llvm / llvm-project

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

Clang-19 crashed: Assertion `i < NumArgs && "getArg() out of range!"' failed. #98635

Open iamanonymouscs opened 1 month ago

iamanonymouscs commented 1 month ago

Clang-19 with attribute regcall enabled.

Compiler explorer(assertion trunck): https://godbolt.org/z/T7xbbWjfG

$cat mutant.c
struct a {};
__attribute__((regcall)) b(struct a) {}

$clang-19 mutant.c
mutant.c:2:26: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
    2 | __attribute__((regcall)) b(struct a) {}
      | ~~~~~~~~~~~~~~~~~~~~~~~~ ^
      | int
mutant.c:2:36: warning: omitting the parameter name in a function definition is a C23 extension [-Wc23-extensions]
    2 | __attribute__((regcall)) b(struct a) {}
      |                                    ^
clang-19: /home/compiler/llvm/llvm/include/llvm/IR/Function.h:850: Argument *llvm::Function::getArg(unsigned int) const: Assertion `i < NumArgs && "getArg() out of range!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /home/software/llvm-trunk-eed7c5e/bin/clang-19 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name mutant.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/code/reduce -fcoverage-compilation-dir=/home/code/reduce -resource-dir /home/software/llvm-trunk-eed7c5e/lib/clang/19 -internal-isystem /home/software/llvm-trunk-eed7c5e/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/mutant-d0f4b9.o -x c mutant.c
1.      <eof> parser at end of file
2.      mutant.c:2:26: LLVM IR generation of declaration 'b'
3.      mutant.c:2:26: Generating code for declaration 'b'
 #0 0x00007f9effd33617 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libLLVM.so.19.0git+0xffc617)
 #1 0x00007f9effd2fb92 llvm::sys::RunSignalHandlers() (/home/software/llvm-trunk-eed7c5e/bin/../lib/libLLVM.so.19.0git+0xff8b92)
 #2 0x00007f9effd33d91 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f9efe817520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f9efe86b9fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007f9efe817476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007f9efe7fd7f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007f9efe7fd71b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007f9efe80ee96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x00007f9f1c081b8f clang::CodeGen::CodeGenFunction::EmitFunctionProlog(clang::CodeGen::CGFunctionInfo const&, llvm::Function*, clang::CodeGen::FunctionArgList const&) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x392cb8f)
#10 0x00007f9f1c5a3762 clang::CodeGen::CodeGenFunction::StartFunction(clang::GlobalDecl, clang::QualType, llvm::Function*, clang::CodeGen::CGFunctionInfo const&, clang::CodeGen::FunctionArgList const&, clang::SourceLocation, clang::SourceLocation) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x3e4e762)
#11 0x00007f9f1c5a6caa clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x3e51caa)
#12 0x00007f9f1c5efcb4 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x3e9acb4)
#13 0x00007f9f1c5e2067 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x3e8d067)
#14 0x00007f9f1c5e9275 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x3e94275)
#15 0x00007f9f1c5e04ed clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x3e8b4ed)
#16 0x00007f9f1c75e164 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#17 0x00007f9f1c57e57c clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x3e2957c)
#18 0x00007f9f195b02ab clang::ParseAST(clang::Sema&, bool, bool) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0xe5b2ab)
#19 0x00007f9f1de98ed5 clang::FrontendAction::Execute() (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x5743ed5)
#20 0x00007f9f1dd51cbb clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x55fccbb)
#21 0x00007f9f1df99fd1 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x5844fd1)
#22 0x00005566ff03b1bf cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/software/llvm-trunk-eed7c5e/bin/clang-19+0x1d1bf)
#23 0x00005566ff030a94 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#24 0x00005566ff02f2b5 clang_main(int, char**, llvm::ToolContext const&) (/home/software/llvm-trunk-eed7c5e/bin/clang-19+0x112b5)
#25 0x00005566ff057e25 main (/home/software/llvm-trunk-eed7c5e/bin/clang-19+0x39e25)
#26 0x00007f9efe7fed90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#27 0x00007f9efe7fee40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#28 0x00005566ff02c6d5 _start (/home/software/llvm-trunk-eed7c5e/bin/clang-19+0xe6d5)
clang: error: unable to execute command: Aborted (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 19.0.0git (https://github.com/llvm/llvm-project.git eed7c5e29c1dc5f78bd01608430e2b4e0c439bb1)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/software/llvm-trunk-eed7c5e/bin
Build config: +assertions
clang: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/mutant-64b4f4.c
clang: note: diagnostic msg: /tmp/mutant-64b4f4.sh
clang: note: diagnostic msg: 

********************
llvmbot commented 1 month ago

@llvm/issue-subscribers-clang-codegen

Author: Anonymous (iamanonymouscs)

Clang-19 with attribute `regcall` enabled. Compiler explorer(assertion trunck): https://godbolt.org/z/T7xbbWjfG ``` $cat mutant.c struct a {}; __attribute__((regcall)) b(struct a) {} $clang-19 mutant.c clang-19: /home/compiler/llvm/llvm/include/llvm/IR/Function.h:850: Argument *llvm::Function::getArg(unsigned int) const: Assertion `i < NumArgs && "getArg() out of range!"' failed. root@65dac7c84719:/home/code/reduce# tmux atttach-session -t reduce unknown command: atttach-session root@65dac7c84719:/home/code/reduce# tmux attach-session -t reduce [detached (from session reduce-2)] root@65dac7c84719:/home/code/reduce# /home/software/llvm-trunk-eed7c5e/bin/clang mutant.c mutant.c:2:26: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int] 2 | __attribute__((regcall)) b(struct a) {} | ~~~~~~~~~~~~~~~~~~~~~~~~ ^ | int mutant.c:2:36: warning: omitting the parameter name in a function definition is a C23 extension [-Wc23-extensions] 2 | __attribute__((regcall)) b(struct a) {} | ^ clang-19: /home/compiler/llvm/llvm/include/llvm/IR/Function.h:850: Argument *llvm::Function::getArg(unsigned int) const: Assertion `i < NumArgs && "getArg() out of range!"' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script. Stack dump: 0. Program arguments: /home/software/llvm-trunk-eed7c5e/bin/clang-19 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name mutant.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/code/reduce -fcoverage-compilation-dir=/home/code/reduce -resource-dir /home/software/llvm-trunk-eed7c5e/lib/clang/19 -internal-isystem /home/software/llvm-trunk-eed7c5e/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/mutant-d0f4b9.o -x c mutant.c 1. <eof> parser at end of file 2. mutant.c:2:26: LLVM IR generation of declaration 'b' 3. mutant.c:2:26: Generating code for declaration 'b' #0 0x00007f9effd33617 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libLLVM.so.19.0git+0xffc617) #1 0x00007f9effd2fb92 llvm::sys::RunSignalHandlers() (/home/software/llvm-trunk-eed7c5e/bin/../lib/libLLVM.so.19.0git+0xff8b92) #2 0x00007f9effd33d91 SignalHandler(int) Signals.cpp:0:0 #3 0x00007f9efe817520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #4 0x00007f9efe86b9fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc) #5 0x00007f9efe817476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476) #6 0x00007f9efe7fd7f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3) #7 0x00007f9efe7fd71b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b) #8 0x00007f9efe80ee96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96) #9 0x00007f9f1c081b8f clang::CodeGen::CodeGenFunction::EmitFunctionProlog(clang::CodeGen::CGFunctionInfo const&, llvm::Function*, clang::CodeGen::FunctionArgList const&) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x392cb8f) #10 0x00007f9f1c5a3762 clang::CodeGen::CodeGenFunction::StartFunction(clang::GlobalDecl, clang::QualType, llvm::Function*, clang::CodeGen::CGFunctionInfo const&, clang::CodeGen::FunctionArgList const&, clang::SourceLocation, clang::SourceLocation) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x3e4e762) #11 0x00007f9f1c5a6caa clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x3e51caa) #12 0x00007f9f1c5efcb4 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x3e9acb4) #13 0x00007f9f1c5e2067 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x3e8d067) #14 0x00007f9f1c5e9275 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x3e94275) #15 0x00007f9f1c5e04ed clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x3e8b4ed) #16 0x00007f9f1c75e164 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0 #17 0x00007f9f1c57e57c clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x3e2957c) #18 0x00007f9f195b02ab clang::ParseAST(clang::Sema&, bool, bool) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0xe5b2ab) #19 0x00007f9f1de98ed5 clang::FrontendAction::Execute() (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x5743ed5) #20 0x00007f9f1dd51cbb clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x55fccbb) #21 0x00007f9f1df99fd1 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/software/llvm-trunk-eed7c5e/bin/../lib/libclang-cpp.so.19.0git+0x5844fd1) #22 0x00005566ff03b1bf cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/software/llvm-trunk-eed7c5e/bin/clang-19+0x1d1bf) #23 0x00005566ff030a94 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0 #24 0x00005566ff02f2b5 clang_main(int, char**, llvm::ToolContext const&) (/home/software/llvm-trunk-eed7c5e/bin/clang-19+0x112b5) #25 0x00005566ff057e25 main (/home/software/llvm-trunk-eed7c5e/bin/clang-19+0x39e25) #26 0x00007f9efe7fed90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #27 0x00007f9efe7fee40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #28 0x00005566ff02c6d5 _start (/home/software/llvm-trunk-eed7c5e/bin/clang-19+0xe6d5) clang: error: unable to execute command: Aborted (core dumped) clang: error: clang frontend command failed due to signal (use -v to see invocation) clang version 19.0.0git (https://github.com/llvm/llvm-project.git eed7c5e29c1dc5f78bd01608430e2b4e0c439bb1) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /home/software/llvm-trunk-eed7c5e/bin Build config: +assertions clang: note: diagnostic msg: ******************** PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang: note: diagnostic msg: /tmp/mutant-64b4f4.c clang: note: diagnostic msg: /tmp/mutant-64b4f4.sh clang: note: diagnostic msg: ******************** ```