You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit adds the foundational support for generating C++ thunks
needed for multiple inheritance, particularly for virtual function calls
through base class pointers. The implementation closely follows CodeGen.
Key changes:
1. Fix VTable double-insertion bug in createGlobalOp/createCIRFunction:
- Clear insertion point before calling create() to prevent auto-insertion
- Manually insert operations at correct location
- This was a pre-existing bug blocking VTable generation during thunk emission
2. Implement thunk generation infrastructure matching CodeGen:
- Add startThunk() matching CodeGen's StartThunk()
- Add generateThunk() matching CodeGen's generateThunk()
- Add emitCallAndReturnForThunk() stub matching CodeGen's EmitCallAndReturnForThunk()
- Add emitMustTailThunk() stub matching CodeGen's EmitMustTailThunk()
- Implement finishThunk() matching CodeGen's FinishThunk() for cleanup
- Enable thunk handling in addVTableComponent() for VTable emission
- Call generateThunk() from maybeEmitThunk()
3. Make StartFunction null-safe for thunks:
- Add null checks for GlobalDecl in XRay attributes
- Guard function body access for thunks (which have no AST body)
4. Handle thunk attributes in setFunctionAttributes:
- Remove assertion blocking thunks
- Allow thunks to proceed through attribute setting
5. Add comprehensive test coverage:
- clang/test/CIR/CodeGen/vtable-thunk.cpp - CIR output test with specific offset verification
- clang/test/CIR/Lowering/vtable-thunk.cpp - LLVM lowering test with correct offset
- clang/test/CIR/CodeGen/vtable-thunk-compare-codegen.cpp - CodeGen comparison test (XFAIL until thunk bodies implemented)
Note: Thunk bodies are marked with llvm_unreachable("NYI") placeholders.
Full thunk body emission (this adjustment, call forwarding, return adjustment)
will be implemented in follow-up commits.
ghstack-source-id: 933ad05
Pull-Request: #2003
0 commit comments