llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.8k stars 10.98k forks source link

[AMDGPU] Alias to alias crashes 'AMDGPUResourceUsageAnalysis' with an invalid cast #96812

Open jhuber6 opened 1 week ago

jhuber6 commented 1 week ago

The following LLVM-IR using nested aliases crashes the AMDGPU backend during resource assignment. This is caused by an invalid cast between incompatible types. See the godbolt link https://godbolt.org/z/Mrv7a1PrP or below.

target triple = "amdgcn-amd-amdhsa"

@foo_a = alias void (ptr), ptr @foo
@bar_a = alias void (ptr), ptr @foo_a

define void @foo() {
entry:
  ret void
}

define void @bad() {
entry:
  call void @bar_a(ptr null)
  ret void
}

Simply invoking the backend will reproduce the issue.

$ llc bug.bc
llc: /root/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::Function; From = llvm::Constant]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel <source>
1.  Running pass 'Function register usage analysis' on module '<source>'.
 #0 0x0000000003a18df8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3a18df8)
 #1 0x0000000003a1655c SignalHandler(int) Signals.cpp:0:0
 #2 0x000077b059042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x000077b0590969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x000077b059042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x000077b0590287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x000077b05902871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x000077b059039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x0000000000d3c5ad llvm::AMDGPUResourceUsageAnalysis::analyzeResourceUsage(llvm::MachineFunction const&, llvm::TargetMachine const&, unsigned int, unsigned int) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0xd3c5ad)
 #9 0x0000000000d3d673 llvm::AMDGPUResourceUsageAnalysis::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0xd3d673)
#10 0x0000000002fce7f5 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2fce7f5)
#11 0x0000000000835c2c compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#12 0x000000000072b37e main (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x72b37e)
#13 0x000077b059029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#14 0x000077b059029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#15 0x000000000082c74e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x82c74e)
llvmbot commented 1 week ago

@llvm/issue-subscribers-backend-amdgpu

Author: Joseph Huber (jhuber6)

The following LLVM-IR using nested aliases crashes the AMDGPU backend during resource assignment. This is caused by an invalid cast between incompatible types. See the godbolt link https://godbolt.org/z/Mrv7a1PrP or below. ```llvm target triple = "amdgcn-amd-amdhsa" @foo_a = alias void (ptr), ptr @foo @bar_a = alias void (ptr), ptr @foo_a define void @foo() { entry: ret void } define void @bad() { entry: call void @bar_a(ptr null) ret void } ``` Simply invoking the backend will reproduce the issue. ```console $ llc bug.bc llc: /root/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::Function; From = llvm::Constant]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel <source> 1. Running pass 'Function register usage analysis' on module '<source>'. #0 0x0000000003a18df8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3a18df8) #1 0x0000000003a1655c SignalHandler(int) Signals.cpp:0:0 #2 0x000077b059042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #3 0x000077b0590969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc) #4 0x000077b059042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476) #5 0x000077b0590287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3) #6 0x000077b05902871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b) #7 0x000077b059039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96) #8 0x0000000000d3c5ad llvm::AMDGPUResourceUsageAnalysis::analyzeResourceUsage(llvm::MachineFunction const&, llvm::TargetMachine const&, unsigned int, unsigned int) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0xd3c5ad) #9 0x0000000000d3d673 llvm::AMDGPUResourceUsageAnalysis::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0xd3d673) #10 0x0000000002fce7f5 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2fce7f5) #11 0x0000000000835c2c compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0 #12 0x000000000072b37e main (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x72b37e) #13 0x000077b059029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #14 0x000077b059029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #15 0x000000000082c74e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x82c74e) ```