llvm-project/llvm/test/CodeGen/DirectX/empty-global-ctors.ll
puneeth_aditya_56 aef7e5768e
[DirectX] Fix assertion in PointerTypeAnalysis with empty global_ctors (#179034)
When `llvm.global_ctors` has no elements (e.g., when all resources are
unused in a shader library), its initializer is a `zeroinitializer`
(`ConstantAggregateZero`) rather than a `ConstantArray`. The previous
code used `cast<ConstantArray>` which asserts on incompatible types:

> "cast<Ty>() argument of incompatible type!"

This patch uses `dyn_cast` and returns early if the initializer is not a
`ConstantArray`, handling the edge case gracefully.

Fixes #178993.

Co-authored-by: Kaitlin Peng <kaitlinpeng@microsoft.com>
2026-03-17 12:06:07 -07:00

17 lines
507 B
LLVM

; 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
}