<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62384>62384</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[GlobalOpt][AMDGPU] Assertion hit while handling global constructor
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:AMDGPU
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jhuber6
</td>
</tr>
</table>
<pre>
This IR hits an assertion when run through `opt`. It came from compiling a global constructor with a virtual member.
```llvm-ir
target triple = "amdgcn-amd-amdhsa"
@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @ctor, ptr null }]
@x = internal addrspace(1) global ptr null
define internal void @ctor() {
entry:
tail call void @init(ptr addrspacecast (ptr addrspace(1) null to ptr))
ret void
}
define internal void @init(ptr %T) {
entry:
%0 = load ptr, ptr addrspace(1) @x, align 8
%cmp = icmp eq ptr %0, null
store ptr %T, ptr addrspace(1) @x, align 8
ret void
}
```
```
$> opt -O1 bug.ll
opt: llvm/lib/IR/Constants.cpp:2215: static llvm::Constant* llvm::ConstantExpr::getBitCast(llvm::Constant*, llvm::Type*, bool): Assertion `CastInst::castIsValid(Instruction::BitCast, C, DstTy) && "Invalid constantexpr bitcast!"' failed.
```
Here's a link to the reproducer https://godbolt.org/z/h7PrfdWhW.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVc2u2zYTfRp6M7iCNDIleeGFfR3n8-JDguC2WRaUSEtMKFIlR_enT19Qkn-a3hQtINMWyTNz5nB4LELQrVVqy_ie8cNKjNQ5v_3WjbXyxap28m371OkApy_QaQogLIgQlCftLLx0yoIfLVDn3dh2wIrUDcSKNIETQSN6BWfvemhcP2ijbQsCWuNqYaBxNpAfG3IeXjR1IOBZexqFgV71tfIJSw8s3S1jkc6PMc_9g_bzLAnfKgLyejAKWH4Ahih62Tb2QfQyfrogGOJ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