Index: cfe/trunk/lib/CodeGen/CGCUDANV.cpp =================================================================== --- cfe/trunk/lib/CodeGen/CGCUDANV.cpp +++ cfe/trunk/lib/CodeGen/CGCUDANV.cpp @@ -468,11 +468,13 @@ /// \endcode llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() { bool IsHIP = CGM.getLangOpts().HIP; + bool IsCUDA = CGM.getLangOpts().CUDA; // No need to generate ctors/dtors if there is no GPU binary. StringRef CudaGpuBinaryFileName = CGM.getCodeGenOpts().CudaGpuBinaryFileName; if (CudaGpuBinaryFileName.empty() && !IsHIP) return nullptr; - if (IsHIP && EmittedKernels.empty() && DeviceVars.empty()) + if ( (IsHIP || (IsCUDA && !RelocatableDeviceCode) ) + && EmittedKernels.empty() && DeviceVars.empty()) return nullptr; // void __{cuda|hip}_register_globals(void* handle); Index: cfe/trunk/test/CodeGenCUDA/device-stub.cu =================================================================== --- cfe/trunk/test/CodeGenCUDA/device-stub.cu +++ cfe/trunk/test/CodeGenCUDA/device-stub.cu @@ -227,20 +227,14 @@ // There should be no __[[PREFIX]]_register_globals if we have no // device-side globals, but we still need to register GPU binary. // Skip GPU binary string first. -// CUDANOGLOBALS: @{{.*}} = private constant{{.*}} +// CUDANOGLOBALS-NOT: @{{.*}} = private constant{{.*}} // HIPNOGLOBALS-NOT: @{{.*}} = internal constant{{.*}} // NOGLOBALS-NOT: define internal void @__{{.*}}_register_globals -// CUDANOGLOBALS: define internal void @__[[PREFIX:cuda|hip]]_module_ctor -// CUDANOGLOBALS: call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper +// NOGLOBALS-NOT: define internal void @__[[PREFIX:cuda|hip]]_module_ctor +// NOGLOBALS-NOT: call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper // NOGLOBALS-NOT: call void @__[[PREFIX]]_register_globals -// CUDANOGLOBALS: define internal void @__[[PREFIX]]_module_dtor -// CUDANOGLOBALS: call void @__[[PREFIX]]UnregisterFatBinary - -// There should be no fat binary functions when no device-code is found for HIP. -// HIPNOGLOBALS-NOT: define internal void @__[[PREFIX:cuda|hip]]_module_ctor -// HIPNOGLOBALS-NOT: call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper -// HIPNOGLOBALS-NOT: define internal void @__[[PREFIX]]_module_dtor -// HIPNOGLOBALS-NOT: call void @__[[PREFIX]]UnregisterFatBinary +// NOGLOBALS-NOT: define internal void @__[[PREFIX]]_module_dtor +// NOGLOBALS-NOT: call void @__[[PREFIX]]UnregisterFatBinary // There should be no constructors/destructors if we have no GPU binary. // NOGPUBIN-NOT: define internal void @__[[PREFIX]]_register_globals