@@ -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