[PATCH] D113800: [amdgpu] Don't crash on empty global ctor/dtor
Jon Chesterfield via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 12 13:12:59 PST 2021
JonChesterfield created this revision.
JonChesterfield added reviewers: rksharma, t-tye, b-sumner, yaxunl, arsenm.
Herald added subscribers: foad, kerbowa, hiraditya, tpr, dstuttard, nhaehnle, jvesely, kzhuravl.
JonChesterfield requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.
Global ctor/dtor can be an empty array, which is a Constant not a
ConstantArray. The cast<ConstantArray> therefore asserts / crashes.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D113800
Files:
llvm/lib/Target/AMDGPU/AMDGPUCtorDtorLowering.cpp
llvm/test/CodeGen/AMDGPU/lower-empty-ctor-dtor.ll
Index: llvm/test/CodeGen/AMDGPU/lower-empty-ctor-dtor.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/lower-empty-ctor-dtor.ll
@@ -0,0 +1,9 @@
+; RUN: opt -S -mtriple=amdgcn-- -amdgpu-lower-ctor-dtor < %s | FileCheck %s
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx700 -filetype=obj -o - < %s | llvm-readelf -s - 2>&1 | FileCheck %s
+
+ at llvm.global_ctors = appending global [0 x { i32, void ()*, i8* }] zeroinitializer
+ at llvm.global_dtors = appending global [0 x { i32, void ()*, i8* }] zeroinitializer
+
+; No amdgpu_kernels emitted for empty global_ctors
+; CHECK-NOT: amdgcn.device.init
+; CHECK-NOT: amdgcn.device.fini
Index: llvm/lib/Target/AMDGPU/AMDGPUCtorDtorLowering.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/AMDGPUCtorDtorLowering.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUCtorDtorLowering.cpp
@@ -52,8 +52,8 @@
bool createInitOrFiniKernel(Module &M, GlobalVariable *GV, bool IsCtor) {
if (!GV)
return false;
- ConstantArray *GA = cast<ConstantArray>(GV->getInitializer());
- if (GA->getNumOperands() == 0)
+ ConstantArray *GA = dyn_cast<ConstantArray>(GV->getInitializer());
+ if (!GA || GA->getNumOperands() == 0)
return false;
Function *InitOrFiniKernel = createInitOrFiniKernelFunction(M, IsCtor);
IRBuilder<> IRB(InitOrFiniKernel->getEntryBlock().getTerminator());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113800.386933.patch
Type: text/x-patch
Size: 1446 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211112/35447210/attachment.bin>
More information about the llvm-commits
mailing list