diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCtorDtorLowering.cpp b/llvm/lib/Target/AMDGPU/AMDGPUCtorDtorLowering.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPUCtorDtorLowering.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUCtorDtorLowering.cpp @@ -50,7 +50,7 @@ } bool createInitOrFiniKernel(Module &M, GlobalVariable *GV, bool IsCtor) { - if (!GV) + if (!GV || !GV->hasInitializer()) return false; ConstantArray *GA = dyn_cast(GV->getInitializer()); if (!GA || GA->getNumOperands() == 0) diff --git a/llvm/test/CodeGen/AMDGPU/lower-ctor-dtor-declaration.ll b/llvm/test/CodeGen/AMDGPU/lower-ctor-dtor-declaration.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/AMDGPU/lower-ctor-dtor-declaration.ll @@ -0,0 +1,8 @@ +; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx700 < %s | FileCheck %s + +@llvm.global_ctors = external global [2 x { i32, void ()*, i8* }] +@llvm.global_dtors = external global [2 x { i32, void ()*, i8* }] + +; No amdgpu_kernels emitted for global_ctors declaration +; CHECK-NOT: amdgcn.device.init +; CHECK-NOT: amdgcn.device.fini