llvm / llvm-project

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

[RISC-V] Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed. #105894

Closed patrick-rivos closed 2 weeks ago

patrick-rivos commented 2 weeks ago

Testcase:

long a, b;
void c() {
  for (int d = (unsigned short)(b >> a) - 7471;;)
    ;
}

Godbolt: https://godbolt.org/z/5Tqaba1ha

LLVM IR:

; ModuleID = 'reduced.bc'
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
target triple = "riscv64-unknown-linux-gnu"

define void @c(i64 %0) #0 {
entry:
  %shr = ashr i64 %0, %0
  %conv = trunc i64 %shr to i16
  %conv1 = zext i16 %conv to i32
  %sub = sub i32 %conv1, 7471
  store i32 %sub, ptr null, align 4
  ret void
}

attributes #0 = { "target-features"="+64bit,+b,+relax,+xsifivecdiscarddlone,+zba,+zbb,+zbs,-a,-c,-d,-e,-experimental-smctr,-experimental-smmpm,-experimental-smnpm,-experimental-ssctr,-experimental-ssnpm,-experimental-sspm,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-f,-h,-m,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-v,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zbc,-zbkb,-zbkc,-zbkx,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zicsr,-zifencei,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-ztso,-zvbb,-zvbc,-zve32f,-zve32x,-zve64d,-zve64f,-zve64x,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl128b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl32b,-zvl4096b,-zvl512b,-zvl64b,-zvl65536b,-zvl8192b" }

Godbolt: https://godbolt.org/z/3znT6d38P

Command/backtrace:

 /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc reduced.ll
llc: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From&) [with To = llvm::ConstantSDNode; From = llvm::SDValue]: 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: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc reduced.ll
1.      Running pass 'Function Pass Manager' on module 'reduced.ll'.
2.      Running pass 'RISC-V DAG->DAG Pattern Instruction Selection' on function '@c'
 #0 0x0000650354e9d720 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1e77720)
 #1 0x0000650354e9ab3f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1e74b3f)
 #2 0x0000650354e9ac95 SignalHandler(int) Signals.cpp:0:0
 #3 0x0000782a68442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000782a684969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x0000782a684969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x0000782a684969fc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x0000782a68442476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x0000782a684287f3 abort ./stdlib/abort.c:81:7
 #9 0x0000782a6842871b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x0000782a68439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x00006503537b5cc8 llvm::SDNode::getConstantOperandVal(unsigned int) const (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x78fcc8)
#12 0x00006503537bc32c llvm::RISCVDAGToDAGISel::selectSHXADDOp(llvm::SDValue, unsigned int, llvm::SDValue&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x79632c)
#13 0x0000650354c2438f llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1bfe38f)
#14 0x00006503537c808f llvm::RISCVDAGToDAGISel::Select(llvm::SDNode*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x7a208f)
#15 0x0000650354c1cc14 llvm::SelectionDAGISel::DoInstructionSelection() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1bf6c14)
#16 0x0000650354c2c8b0 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1c068b0)
#17 0x0000650354c300b2 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1c0a0b2)
#18 0x0000650354c31867 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1c0b867)
#19 0x0000650354c21cb9 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1bfbcb9)
#20 0x0000650353d9a627 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#21 0x00006503543c2aec llvm::FPPassManager::runOnFunction(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x139caec)
#22 0x00006503543c2f19 llvm::FPPassManager::runOnModule(llvm::Module&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x139cf19)
#23 0x00006503543c1e26 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x139be26)
#24 0x000065035369bf36 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#25 0x00006503535e0c96 main (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x5bac96)
#26 0x0000782a68429d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#27 0x0000782a68429e40 call_init ./csu/../csu/libc-start.c:128:20
#28 0x0000782a68429e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#29 0x0000650353692d65 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x66cd65)
zsh: IOT instruction (core dumped)  /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc

Found via fuzzer.

llvmbot commented 2 weeks ago

@llvm/issue-subscribers-backend-risc-v

Author: Patrick O'Neill (patrick-rivos)

Testcase: ```c long a, b; void c() { for (int d = (unsigned short)(b >> a) - 7471;;) ; } ``` Godbolt: https://godbolt.org/z/5Tqaba1ha LLVM IR: ```llvm ir ; ModuleID = 'reduced.bc' target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128" target triple = "riscv64-unknown-linux-gnu" define void @c(i64 %0) #0 { entry: %shr = ashr i64 %0, %0 %conv = trunc i64 %shr to i16 %conv1 = zext i16 %conv to i32 %sub = sub i32 %conv1, 7471 store i32 %sub, ptr null, align 4 ret void } attributes #0 = { "target-features"="+64bit,+b,+relax,+xsifivecdiscarddlone,+zba,+zbb,+zbs,-a,-c,-d,-e,-experimental-smctr,-experimental-smmpm,-experimental-smnpm,-experimental-ssctr,-experimental-ssnpm,-experimental-sspm,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-f,-h,-m,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-v,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zbc,-zbkb,-zbkc,-zbkx,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zicsr,-zifencei,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-ztso,-zvbb,-zvbc,-zve32f,-zve32x,-zve64d,-zve64f,-zve64x,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl128b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl32b,-zvl4096b,-zvl512b,-zvl64b,-zvl65536b,-zvl8192b" } ``` Godbolt: https://godbolt.org/z/3znT6d38P Command/backtrace: ``` /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc reduced.ll llc: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From&) [with To = llvm::ConstantSDNode; From = llvm::SDValue]: 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: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc reduced.ll 1. Running pass 'Function Pass Manager' on module 'reduced.ll'. 2. Running pass 'RISC-V DAG->DAG Pattern Instruction Selection' on function '@c' #0 0x0000650354e9d720 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1e77720) #1 0x0000650354e9ab3f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1e74b3f) #2 0x0000650354e9ac95 SignalHandler(int) Signals.cpp:0:0 #3 0x0000782a68442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #4 0x0000782a684969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76 #5 0x0000782a684969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10 #6 0x0000782a684969fc pthread_kill ./nptl/pthread_kill.c:89:10 #7 0x0000782a68442476 gsignal ./signal/../sysdeps/posix/raise.c:27:6 #8 0x0000782a684287f3 abort ./stdlib/abort.c:81:7 #9 0x0000782a6842871b _nl_load_domain ./intl/loadmsgcat.c:1177:9 #10 0x0000782a68439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96) #11 0x00006503537b5cc8 llvm::SDNode::getConstantOperandVal(unsigned int) const (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x78fcc8) #12 0x00006503537bc32c llvm::RISCVDAGToDAGISel::selectSHXADDOp(llvm::SDValue, unsigned int, llvm::SDValue&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x79632c) #13 0x0000650354c2438f llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1bfe38f) #14 0x00006503537c808f llvm::RISCVDAGToDAGISel::Select(llvm::SDNode*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x7a208f) #15 0x0000650354c1cc14 llvm::SelectionDAGISel::DoInstructionSelection() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1bf6c14) #16 0x0000650354c2c8b0 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1c068b0) #17 0x0000650354c300b2 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1c0a0b2) #18 0x0000650354c31867 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1c0b867) #19 0x0000650354c21cb9 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x1bfbcb9) #20 0x0000650353d9a627 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0 #21 0x00006503543c2aec llvm::FPPassManager::runOnFunction(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x139caec) #22 0x00006503543c2f19 llvm::FPPassManager::runOnModule(llvm::Module&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x139cf19) #23 0x00006503543c1e26 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x139be26) #24 0x000065035369bf36 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0 #25 0x00006503535e0c96 main (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x5bac96) #26 0x0000782a68429d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16 #27 0x0000782a68429e40 call_init ./csu/../csu/libc-start.c:128:20 #28 0x0000782a68429e40 __libc_start_main ./csu/../csu/libc-start.c:379:5 #29 0x0000650353692d65 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc+0x66cd65) zsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/llc ``` Found via fuzzer.
topperc commented 2 weeks ago

This looks a lot like a crash that was reverted here 858afe90aad9ca45165d64baec9249dd680c85d5

patrick-rivos commented 2 weeks ago

Likely the same - I'm was testing with 84aa02d3fa1f1f614c4f3c144ec118b2f05ae6b0 I'll re open if it reproduces with the latest llvm.