Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,13 @@ static Type *classifyConstantWithOpaquePtr(const Constant *C,

static void classifyGlobalCtorPointerType(const GlobalVariable &GV,
PointerTypeMap &Map) {
const auto *CA = cast<ConstantArray>(GV.getInitializer());
const auto *CA = dyn_cast<ConstantArray>(GV.getInitializer());
if (!CA) {
// An empty global_ctors will be a zeroinitializer, so just skip it.
assert(isa<ConstantAggregateZero>(GV.getInitializer()) &&
"global_ctors should be a ConstantArray or ConstantAggregateZero");
return;
}
// Type for global ctor should be array of { i32, void ()*, i8* }.
Type *CtorArrayTy = classifyConstantWithOpaquePtr(CA, Map);

Expand Down
16 changes: 16 additions & 0 deletions llvm/test/CodeGen/DirectX/empty-global-ctors.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; RUN: opt -S -dxil-prepare < %s | FileCheck %s

; Test that dxil-prepare handles llvm.global_ctors with zeroinitializer
; (which is not a ConstantArray) without crashing.
; Fixes https://github.com/llvm/llvm-project/issues/178993

target triple = "dxil-unknown-shadermodel6.7-library"

; An empty global_ctors array uses zeroinitializer, not ConstantArray
@llvm.global_ctors = appending global [0 x { i32, ptr, ptr }] zeroinitializer

; CHECK: define void @main()
define void @main() {
entry:
ret void
}
Loading