aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGVTables.cpp
diff options
context:
space:
mode:
authorAnshil Gandhi <95053726+gandhi56@users.noreply.github.com>2025-02-19 21:47:22 -0700
committerGitHub <noreply@github.com>2025-02-19 23:47:22 -0500
commit95000fdb9e98a88b923fa7aa4bdeffbc618a323c (patch)
tree33d8df9e3f0c002c7e73812edcf95be061a7f549 /clang/lib/CodeGen/CGVTables.cpp
parentdf96b56b9fad29ff0a8654730952d02e7ef6cc50 (diff)
downloadllvm-95000fdb9e98a88b923fa7aa4bdeffbc618a323c.zip
llvm-95000fdb9e98a88b923fa7aa4bdeffbc618a323c.tar.gz
llvm-95000fdb9e98a88b923fa7aa4bdeffbc618a323c.tar.bz2
[CUDA] Increment VTable index for device thunks (#124989)
Currently, the clang frontend incorrectly emits the callee instead of the thunk for the callee in the VTable. This is the case because the thunk index is not incremented when their callees cannot be emitted. This patch fixes the bug.
Diffstat (limited to 'clang/lib/CodeGen/CGVTables.cpp')
-rw-r--r--clang/lib/CodeGen/CGVTables.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp
index 7faf682..c910893 100644
--- a/clang/lib/CodeGen/CGVTables.cpp
+++ b/clang/lib/CodeGen/CGVTables.cpp
@@ -771,6 +771,10 @@ void CodeGenVTables::addVTableComponent(ConstantArrayBuilder &builder,
case VTableComponent::CK_DeletingDtorPointer: {
GlobalDecl GD = component.getGlobalDecl();
+ const bool IsThunk =
+ nextVTableThunkIndex < layout.vtable_thunks().size() &&
+ layout.vtable_thunks()[nextVTableThunkIndex].first == componentIndex;
+
if (CGM.getLangOpts().CUDA) {
// Emit NULL for methods we can't codegen on this
// side. Otherwise we'd end up with vtable with unresolved
@@ -782,9 +786,12 @@ void CodeGenVTables::addVTableComponent(ConstantArrayBuilder &builder,
CGM.getLangOpts().CUDAIsDevice
? MD->hasAttr<CUDADeviceAttr>()
: (MD->hasAttr<CUDAHostAttr>() || !MD->hasAttr<CUDADeviceAttr>());
- if (!CanEmitMethod)
+ if (!CanEmitMethod) {
+ if (IsThunk)
+ nextVTableThunkIndex++;
return builder.add(
llvm::ConstantExpr::getNullValue(CGM.GlobalsInt8PtrTy));
+ }
// Method is acceptable, continue processing as usual.
}
@@ -830,9 +837,7 @@ void CodeGenVTables::addVTableComponent(ConstantArrayBuilder &builder,
fnPtr = DeletedVirtualFn;
// Thunks.
- } else if (nextVTableThunkIndex < layout.vtable_thunks().size() &&
- layout.vtable_thunks()[nextVTableThunkIndex].first ==
- componentIndex) {
+ } else if (IsThunk) {
auto &thunkInfo = layout.vtable_thunks()[nextVTableThunkIndex].second;
nextVTableThunkIndex++;