Skip to content

Commit 260efca

Browse files
committed
[CUDA] Emit NULL in VTable in the last resort
Before adding a pointer to a deleting destructor in the VTable, check if it is either a pure virtual function, deleted virtual member function or a function which desires an addition of thunk functions. Change-Id: I791acb42011d253a2a6b06e5f33090abdaa90872
1 parent d1d3e22 commit 260efca

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

clang/lib/CodeGen/CGVTables.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -772,23 +772,6 @@ void CodeGenVTables::addVTableComponent(ConstantArrayBuilder &builder,
772772
case VTableComponent::CK_DeletingDtorPointer: {
773773
GlobalDecl GD = component.getGlobalDecl();
774774

775-
if (CGM.getLangOpts().CUDA) {
776-
// Emit NULL for methods we can't codegen on this
777-
// side. Otherwise we'd end up with vtable with unresolved
778-
// references.
779-
const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
780-
// OK on device side: functions w/ __device__ attribute
781-
// OK on host side: anything except __device__-only functions.
782-
bool CanEmitMethod =
783-
CGM.getLangOpts().CUDAIsDevice
784-
? MD->hasAttr<CUDADeviceAttr>()
785-
: (MD->hasAttr<CUDAHostAttr>() || !MD->hasAttr<CUDADeviceAttr>());
786-
if (!CanEmitMethod)
787-
return builder.add(
788-
llvm::ConstantExpr::getNullValue(CGM.GlobalsInt8PtrTy));
789-
// Method is acceptable, continue processing as usual.
790-
}
791-
792775
auto getSpecialVirtualFn = [&](StringRef name) -> llvm::Constant * {
793776
// FIXME(PR43094): When merging comdat groups, lld can select a local
794777
// symbol as the signature symbol even though it cannot be accessed
@@ -845,6 +828,24 @@ void CodeGenVTables::addVTableComponent(ConstantArrayBuilder &builder,
845828

846829
// Otherwise we can use the method definition directly.
847830
} else {
831+
832+
if (CGM.getLangOpts().CUDA) {
833+
// Emit NULL for methods we can't codegen on this
834+
// side. Otherwise we'd end up with vtable with unresolved
835+
// references.
836+
const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
837+
// OK on device side: functions w/ __device__ attribute
838+
// OK on host side: anything except __device__-only functions.
839+
bool CanEmitMethod =
840+
CGM.getLangOpts().CUDAIsDevice
841+
? MD->hasAttr<CUDADeviceAttr>()
842+
: (MD->hasAttr<CUDAHostAttr>() || !MD->hasAttr<CUDADeviceAttr>());
843+
if (!CanEmitMethod)
844+
return builder.add(
845+
llvm::ConstantExpr::getNullValue(CGM.GlobalsInt8PtrTy));
846+
// Method is acceptable, continue processing as usual.
847+
}
848+
848849
llvm::Type *fnTy = CGM.getTypes().GetFunctionTypeForVTable(GD);
849850
fnPtr = CGM.GetAddrOfFunction(GD, fnTy, /*ForVTable=*/true);
850851
if (CGM.getCodeGenOpts().PointerAuth.CXXVirtualFunctionPointers)

0 commit comments

Comments
 (0)