This repository was archived by the owner on Feb 21, 2026. It is now read-only.
[CIR] Add basic thunk generation infrastructure#2003
Closed
lanza wants to merge 1 commit intogh/lanza/7/basefrom
Closed
[CIR] Add basic thunk generation infrastructure#2003lanza wants to merge 1 commit intogh/lanza/7/basefrom
lanza wants to merge 1 commit intogh/lanza/7/basefrom
Conversation
lanza
added a commit
that referenced
this pull request
Nov 22, 2025
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
This was referenced Nov 22, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
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:
Fix VTable double-insertion bug in createGlobalOp/createCIRFunction:
Implement thunk generation infrastructure matching CodeGen:
Make StartFunction null-safe for thunks:
Handle thunk attributes in setFunctionAttributes:
Add comprehensive test coverage:
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.