AMDGPU: Don't crash on global_ctor/dtor declaration
authorRuiling Song <ruiling.song@amd.com>
Wed, 22 Jun 2022 02:50:46 +0000 (10:50 +0800)
committerRuiling Song <ruiling.song@amd.com>
Thu, 23 Jun 2022 13:04:54 +0000 (21:04 +0800)
Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D128320

llvm/lib/Target/AMDGPU/AMDGPUCtorDtorLowering.cpp
llvm/test/CodeGen/AMDGPU/lower-ctor-dtor-declaration.ll [new file with mode: 0644]

index 04bf623..8fcf669 100644 (file)
@@ -50,7 +50,7 @@ public:
   }
 
   bool createInitOrFiniKernel(Module &M, GlobalVariable *GV, bool IsCtor) {
-    if (!GV)
+    if (!GV || !GV->hasInitializer())
       return false;
     ConstantArray *GA = dyn_cast<ConstantArray>(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 (file)
index 0000000..d293984
--- /dev/null
@@ -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