-
Notifications
You must be signed in to change notification settings - Fork 182
[CIR] Implement non-virtual thunk generation for multiple inheritance #2006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lanza
wants to merge
7
commits into
gh/lanza/10/base
Choose a base branch
from
gh/lanza/10/head
base: gh/lanza/10/base
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,012
−35
Conversation
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
lanza
added a commit
that referenced
this pull request
Nov 23, 2025
This patch implements complete support for generating non-virtual thunks
in ClangIR for multiple inheritance scenarios. Thunks are small adapter
functions that adjust the 'this' pointer and forward calls to the actual
target function when virtual functions are overridden in derived classes
with multiple base classes.
Implementation details:
1. **CIRGenVTables.cpp**:
- Implemented `generateThunk()` to create thunk function bodies with
proper scope management (SymTableScopeTy + LexicalScope)
- Implemented `emitCallAndReturnForThunk()` to emit the call sequence
- Implemented `setThunkProperties()` to set linkage and properties
- Fixed VTable double-insertion bug in vtable emission
2. **CIRGenCXXABI.h/cpp**:
- Added virtual methods `performThisAdjustment()` and
`performReturnAdjustment()` to base class
- Implemented `EmitReturnFromThunk()` default implementation
3. **CIRGenItaniumCXXABI.cpp**:
- Implemented `performThisAdjustment()` for non-virtual adjustments
using cir.ptr_stride operations
- Implemented `performReturnAdjustment()` for covariant return types
- Virtual adjustments marked as NYI with llvm_unreachable
4. **CIRGenFunction.h/cpp**:
- Added `startThunk()`, `generateThunk()`, `emitCallAndReturnForThunk()`,
`finishThunk()`, and `emitMustTailThunk()` methods
- Implemented `finishThunk()` to properly cleanup after thunk generation
5. **CIRGenModule.cpp**:
- Removed assertion blocking thunks in `setFunctionAttributes()`
- Fixed insertion point management in vtable creation
6. **CIRGenCXX.cpp**:
- Added null checks for GlobalDecl in XRay attributes for thunks
7. **Test Updates**:
- Added `clang/test/CIR/CodeGen/vtable-thunk.cpp` for CIR generation
- Added `clang/test/CIR/Lowering/vtable-thunk.cpp` for LLVM lowering
- Fixed offset expectations (16 bytes for x86_64 layout)
- Reordered FileCheck patterns to match actual CIR output order
This implementation closely follows CodeGen's approach in
CodeGenVTables.cpp and CodeGenItaniumCXXABI.cpp, with adaptations for
CIR's MLIR-based infrastructure (e.g., location requirements, operation
builders, scope management).
Limitations:
- Virtual adjustments (vcall offsets) not yet implemented
- Musttail thunks for variadic functions not yet implemented
- Return adjustments implemented but not extensively tested
Test Plan:
```
bin/llvm-lit -v ../../clang/test/CIR/CodeGen/vtable-thunk.cpp
bin/llvm-lit -v ../../clang/test/CIR/Lowering/vtable-thunk.cpp
```
Both tests pass, verifying:
- CIR generation with correct thunk mangling and operations
- Vtable contains thunk references
- Lowering to LLVM IR produces correct getelementptr operations
ghstack-source-id: eaf1735
Pull-Request: #2006
This was referenced Nov 23, 2025
lanza
added a commit
that referenced
this pull request
Nov 23, 2025
This patch implements complete support for generating non-virtual thunks
in ClangIR for multiple inheritance scenarios. Thunks are small adapter
functions that adjust the 'this' pointer and forward calls to the actual
target function when virtual functions are overridden in derived classes
with multiple base classes.
Implementation details:
1. **CIRGenVTables.cpp**:
- Implemented `generateThunk()` to create thunk function bodies with
proper scope management (SymTableScopeTy + LexicalScope)
- Implemented `emitCallAndReturnForThunk()` to emit the call sequence
- Implemented `setThunkProperties()` to set linkage and properties
- Fixed VTable double-insertion bug in vtable emission
2. **CIRGenCXXABI.h/cpp**:
- Added virtual methods `performThisAdjustment()` and
`performReturnAdjustment()` to base class
- Implemented `EmitReturnFromThunk()` default implementation
3. **CIRGenItaniumCXXABI.cpp**:
- Implemented `performThisAdjustment()` for non-virtual adjustments
using cir.ptr_stride operations
- Implemented `performReturnAdjustment()` for covariant return types
- Virtual adjustments marked as NYI with llvm_unreachable
4. **CIRGenFunction.h/cpp**:
- Added `startThunk()`, `generateThunk()`, `emitCallAndReturnForThunk()`,
`finishThunk()`, and `emitMustTailThunk()` methods
- Implemented `finishThunk()` to properly cleanup after thunk generation
5. **CIRGenModule.cpp**:
- Removed assertion blocking thunks in `setFunctionAttributes()`
- Fixed insertion point management in vtable creation
6. **CIRGenCXX.cpp**:
- Added null checks for GlobalDecl in XRay attributes for thunks
7. **Test Updates**:
- Added `clang/test/CIR/CodeGen/vtable-thunk.cpp` for CIR generation
- Added `clang/test/CIR/Lowering/vtable-thunk.cpp` for LLVM lowering
- Fixed offset expectations (16 bytes for x86_64 layout)
- Reordered FileCheck patterns to match actual CIR output order
This implementation closely follows CodeGen's approach in
CodeGenVTables.cpp and CodeGenItaniumCXXABI.cpp, with adaptations for
CIR's MLIR-based infrastructure (e.g., location requirements, operation
builders, scope management).
Limitations:
- Virtual adjustments (vcall offsets) not yet implemented
- Musttail thunks for variadic functions not yet implemented
- Return adjustments implemented but not extensively tested
Test Plan:
```
bin/llvm-lit -v ../../clang/test/CIR/CodeGen/vtable-thunk.cpp
bin/llvm-lit -v ../../clang/test/CIR/Lowering/vtable-thunk.cpp
```
Both tests pass, verifying:
- CIR generation with correct thunk mangling and operations
- Vtable contains thunk references
- Lowering to LLVM IR produces correct getelementptr operations
ghstack-source-id: 16477e8
Pull-Request: #2006
lanza
added a commit
that referenced
this pull request
Nov 23, 2025
This patch implements complete support for generating non-virtual thunks
in ClangIR for multiple inheritance scenarios. Thunks are small adapter
functions that adjust the 'this' pointer and forward calls to the actual
target function when virtual functions are overridden in derived classes
with multiple base classes.
Implementation details:
1. **CIRGenVTables.cpp**:
- Implemented `generateThunk()` to create thunk function bodies with
proper scope management (SymTableScopeTy + LexicalScope)
- Implemented `emitCallAndReturnForThunk()` to emit the call sequence
- Implemented `setThunkProperties()` to set linkage and properties
- Fixed VTable double-insertion bug in vtable emission
2. **CIRGenCXXABI.h/cpp**:
- Added virtual methods `performThisAdjustment()` and
`performReturnAdjustment()` to base class
- Implemented `EmitReturnFromThunk()` default implementation
3. **CIRGenItaniumCXXABI.cpp**:
- Implemented `performThisAdjustment()` for non-virtual adjustments
using cir.ptr_stride operations
- Implemented `performReturnAdjustment()` for covariant return types
- Virtual adjustments marked as NYI with llvm_unreachable
4. **CIRGenFunction.h/cpp**:
- Added `startThunk()`, `generateThunk()`, `emitCallAndReturnForThunk()`,
`finishThunk()`, and `emitMustTailThunk()` methods
- Implemented `finishThunk()` to properly cleanup after thunk generation
5. **CIRGenModule.cpp**:
- Removed assertion blocking thunks in `setFunctionAttributes()`
- Fixed insertion point management in vtable creation
6. **CIRGenCXX.cpp**:
- Added null checks for GlobalDecl in XRay attributes for thunks
7. **Test Updates**:
- Added `clang/test/CIR/CodeGen/vtable-thunk.cpp` for CIR generation
- Added `clang/test/CIR/Lowering/vtable-thunk.cpp` for LLVM lowering
- Fixed offset expectations (16 bytes for x86_64 layout)
- Reordered FileCheck patterns to match actual CIR output order
This implementation closely follows CodeGen's approach in
CodeGenVTables.cpp and CodeGenItaniumCXXABI.cpp, with adaptations for
CIR's MLIR-based infrastructure (e.g., location requirements, operation
builders, scope management).
Limitations:
- Virtual adjustments (vcall offsets) not yet implemented
- Musttail thunks for variadic functions not yet implemented
- Return adjustments implemented but not extensively tested
Test Plan:
```
bin/llvm-lit -v ../../clang/test/CIR/CodeGen/vtable-thunk.cpp
bin/llvm-lit -v ../../clang/test/CIR/Lowering/vtable-thunk.cpp
```
Both tests pass, verifying:
- CIR generation with correct thunk mangling and operations
- Vtable contains thunk references
- Lowering to LLVM IR produces correct getelementptr operations
ghstack-source-id: 62c915d
Pull-Request: #2006
lanza
added a commit
that referenced
this pull request
Nov 23, 2025
This patch implements complete support for generating non-virtual thunks
in ClangIR for multiple inheritance scenarios. Thunks are small adapter
functions that adjust the 'this' pointer and forward calls to the actual
target function when virtual functions are overridden in derived classes
with multiple base classes.
Implementation details:
1. **CIRGenVTables.cpp**:
- Implemented `generateThunk()` to create thunk function bodies with
proper scope management (SymTableScopeTy + LexicalScope)
- Implemented `emitCallAndReturnForThunk()` to emit the call sequence
- Implemented `setThunkProperties()` to set linkage and properties
- Fixed VTable double-insertion bug in vtable emission
2. **CIRGenCXXABI.h/cpp**:
- Added virtual methods `performThisAdjustment()` and
`performReturnAdjustment()` to base class
- Implemented `EmitReturnFromThunk()` default implementation
3. **CIRGenItaniumCXXABI.cpp**:
- Implemented `performThisAdjustment()` for non-virtual adjustments
using cir.ptr_stride operations
- Implemented `performReturnAdjustment()` for covariant return types
- Virtual adjustments marked as NYI with llvm_unreachable
4. **CIRGenFunction.h/cpp**:
- Added `startThunk()`, `generateThunk()`, `emitCallAndReturnForThunk()`,
`finishThunk()`, and `emitMustTailThunk()` methods
- Implemented `finishThunk()` to properly cleanup after thunk generation
5. **CIRGenModule.cpp**:
- Removed assertion blocking thunks in `setFunctionAttributes()`
- Fixed insertion point management in vtable creation
6. **CIRGenCXX.cpp**:
- Added null checks for GlobalDecl in XRay attributes for thunks
7. **Test Updates**:
- Added `clang/test/CIR/CodeGen/vtable-thunk.cpp` for CIR generation
- Added `clang/test/CIR/Lowering/vtable-thunk.cpp` for LLVM lowering
- Fixed offset expectations (16 bytes for x86_64 layout)
- Reordered FileCheck patterns to match actual CIR output order
This implementation closely follows CodeGen's approach in
CodeGenVTables.cpp and CodeGenItaniumCXXABI.cpp, with adaptations for
CIR's MLIR-based infrastructure (e.g., location requirements, operation
builders, scope management).
Limitations:
- Virtual adjustments (vcall offsets) not yet implemented
- Musttail thunks for variadic functions not yet implemented
- Return adjustments implemented but not extensively tested
Test Plan:
```
bin/llvm-lit -v ../../clang/test/CIR/CodeGen/vtable-thunk.cpp
bin/llvm-lit -v ../../clang/test/CIR/Lowering/vtable-thunk.cpp
```
Both tests pass, verifying:
- CIR generation with correct thunk mangling and operations
- Vtable contains thunk references
- Lowering to LLVM IR produces correct getelementptr operations
ghstack-source-id: d6515e1
Pull-Request: #2006
lanza
added a commit
that referenced
this pull request
Nov 23, 2025
This patch implements complete support for generating non-virtual thunks
in ClangIR for multiple inheritance scenarios. Thunks are small adapter
functions that adjust the 'this' pointer and forward calls to the actual
target function when virtual functions are overridden in derived classes
with multiple base classes.
Implementation details:
1. **CIRGenVTables.cpp**:
- Implemented `generateThunk()` to create thunk function bodies with
proper scope management (SymTableScopeTy + LexicalScope)
- Implemented `emitCallAndReturnForThunk()` to emit the call sequence
- Implemented `setThunkProperties()` to set linkage and properties
- Fixed VTable double-insertion bug in vtable emission
2. **CIRGenCXXABI.h/cpp**:
- Added virtual methods `performThisAdjustment()` and
`performReturnAdjustment()` to base class
- Implemented `EmitReturnFromThunk()` default implementation
3. **CIRGenItaniumCXXABI.cpp**:
- Implemented `performThisAdjustment()` for non-virtual adjustments
using cir.ptr_stride operations
- Implemented `performReturnAdjustment()` for covariant return types
- Virtual adjustments marked as NYI with llvm_unreachable
4. **CIRGenFunction.h/cpp**:
- Added `startThunk()`, `generateThunk()`, `emitCallAndReturnForThunk()`,
`finishThunk()`, and `emitMustTailThunk()` methods
- Implemented `finishThunk()` to properly cleanup after thunk generation
5. **CIRGenModule.cpp**:
- Removed assertion blocking thunks in `setFunctionAttributes()`
- Fixed insertion point management in vtable creation
6. **CIRGenCXX.cpp**:
- Added null checks for GlobalDecl in XRay attributes for thunks
7. **Test Updates**:
- Added `clang/test/CIR/CodeGen/vtable-thunk.cpp` for CIR generation
- Added `clang/test/CIR/Lowering/vtable-thunk.cpp` for LLVM lowering
- Fixed offset expectations (16 bytes for x86_64 layout)
- Reordered FileCheck patterns to match actual CIR output order
This implementation closely follows CodeGen's approach in
CodeGenVTables.cpp and CodeGenItaniumCXXABI.cpp, with adaptations for
CIR's MLIR-based infrastructure (e.g., location requirements, operation
builders, scope management).
Limitations:
- Virtual adjustments (vcall offsets) not yet implemented
- Musttail thunks for variadic functions not yet implemented
- Return adjustments implemented but not extensively tested
Test Plan:
```
bin/llvm-lit -v ../../clang/test/CIR/CodeGen/vtable-thunk.cpp
bin/llvm-lit -v ../../clang/test/CIR/Lowering/vtable-thunk.cpp
```
Both tests pass, verifying:
- CIR generation with correct thunk mangling and operations
- Vtable contains thunk references
- Lowering to LLVM IR produces correct getelementptr operations
ghstack-source-id: ae6fa6a
Pull-Request: #2006
lanza
added a commit
that referenced
this pull request
Nov 24, 2025
This patch implements complete support for generating non-virtual thunks
in ClangIR for multiple inheritance scenarios. Thunks are small adapter
functions that adjust the 'this' pointer and forward calls to the actual
target function when virtual functions are overridden in derived classes
with multiple base classes.
Implementation details:
1. **CIRGenVTables.cpp**:
- Implemented `generateThunk()` to create thunk function bodies with
proper scope management (SymTableScopeTy + LexicalScope)
- Implemented `emitCallAndReturnForThunk()` to emit the call sequence
- Implemented `setThunkProperties()` to set linkage and properties
- Fixed VTable double-insertion bug in vtable emission
2. **CIRGenCXXABI.h/cpp**:
- Added virtual methods `performThisAdjustment()` and
`performReturnAdjustment()` to base class
- Implemented `EmitReturnFromThunk()` default implementation
3. **CIRGenItaniumCXXABI.cpp**:
- Implemented `performThisAdjustment()` for non-virtual adjustments
using cir.ptr_stride operations
- Implemented `performReturnAdjustment()` for covariant return types
- Virtual adjustments marked as NYI with llvm_unreachable
4. **CIRGenFunction.h/cpp**:
- Added `startThunk()`, `generateThunk()`, `emitCallAndReturnForThunk()`,
`finishThunk()`, and `emitMustTailThunk()` methods
- Implemented `finishThunk()` to properly cleanup after thunk generation
5. **CIRGenModule.cpp**:
- Removed assertion blocking thunks in `setFunctionAttributes()`
- Fixed insertion point management in vtable creation
6. **CIRGenCXX.cpp**:
- Added null checks for GlobalDecl in XRay attributes for thunks
7. **Test Updates**:
- Added `clang/test/CIR/CodeGen/vtable-thunk.cpp` for CIR generation
- Added `clang/test/CIR/Lowering/vtable-thunk.cpp` for LLVM lowering
- Fixed offset expectations (16 bytes for x86_64 layout)
- Reordered FileCheck patterns to match actual CIR output order
This implementation closely follows CodeGen's approach in
CodeGenVTables.cpp and CodeGenItaniumCXXABI.cpp, with adaptations for
CIR's MLIR-based infrastructure (e.g., location requirements, operation
builders, scope management).
Limitations:
- Virtual adjustments (vcall offsets) not yet implemented
- Musttail thunks for variadic functions not yet implemented
- Return adjustments implemented but not extensively tested
Test Plan:
```
bin/llvm-lit -v ../../clang/test/CIR/CodeGen/vtable-thunk.cpp
bin/llvm-lit -v ../../clang/test/CIR/Lowering/vtable-thunk.cpp
```
Both tests pass, verifying:
- CIR generation with correct thunk mangling and operations
- Vtable contains thunk references
- Lowering to LLVM IR produces correct getelementptr operations
ghstack-source-id: eb03968
Pull-Request: #2006
This was referenced Nov 24, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 patch implements complete support for generating non-virtual thunks
in ClangIR for multiple inheritance scenarios. Thunks are small adapter
functions that adjust the 'this' pointer and forward calls to the actual
target function when virtual functions are overridden in derived classes
with multiple base classes.
Implementation details:
CIRGenVTables.cpp:
generateThunk()to create thunk function bodies withproper scope management (SymTableScopeTy + LexicalScope)
emitCallAndReturnForThunk()to emit the call sequencesetThunkProperties()to set linkage and propertiesCIRGenCXXABI.h/cpp:
performThisAdjustment()andperformReturnAdjustment()to base classEmitReturnFromThunk()default implementationCIRGenItaniumCXXABI.cpp:
performThisAdjustment()for non-virtual adjustmentsusing cir.ptr_stride operations
performReturnAdjustment()for covariant return typesCIRGenFunction.h/cpp:
startThunk(),generateThunk(),emitCallAndReturnForThunk(),finishThunk(), andemitMustTailThunk()methodsfinishThunk()to properly cleanup after thunk generationCIRGenModule.cpp:
setFunctionAttributes()CIRGenCXX.cpp:
Test Updates:
clang/test/CIR/CodeGen/vtable-thunk.cppfor CIR generationclang/test/CIR/Lowering/vtable-thunk.cppfor LLVM loweringThis implementation closely follows CodeGen's approach in
CodeGenVTables.cpp and CodeGenItaniumCXXABI.cpp, with adaptations for
CIR's MLIR-based infrastructure (e.g., location requirements, operation
builders, scope management).
Limitations:
Test Plan:
Both tests pass, verifying: