Internal Assertion llvm/lib/IR/Instructions.cpp:776 failed on __builtin_prefetch(0, 0 * sizeof(int))
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
```c
int a() {
__builtin_prefetch(0, 0 * sizeof(int));
}
```
(found via a fuzzer)
https://godbolt.org/z/jP3d9dnWb
Triggers on https://github.com/llvm/llvm-project/commit/ee5e682f4db85afca52ac6519a4b9bf0bfab4cf9
```sh
$ clang bug.c
bug.c:3:1: warning: non-void function does not return a value [-Wreturn-type]
3 | }
| ^
clang-23: /home/user/software/llvm-install/slot-a/src/llvm/lib/IR/Instructions.cpp:776: void llvm::CallInst::init(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef, llvm::ArrayRef >, const llvm::Twine&): Assertion `(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && "Calling a function with a bad signature!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /home/user/software/llvm-install/slot-a/bin/clang-23 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name bug.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=/tmp/creduce -fcoverage-compilation-dir=/tmp/creduce -resource-dir /home/user/software/llvm-install/slot-a/lib/clang/23 -internal-isystem /home/user/software/llvm-install/slot-a/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../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 -fmessage-length=124 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -faddrsig -fdwarf2-cfi-asm -o /tmp/bug-20a9d9.o -x c bug.c
1. parser at end of file
2. bug.c:1:5: LLVM IR generation of declaration 'a'
3. bug.c:1:5: Generating code for declaration 'a'
#0 0x00005e31eca5c292 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/user/software/llvm-install/slot-a/bin/clang-23+0x2350292)
#1 0x00005e31eca58ebc llvm::sys::RunSignalHandlers() (/home/user/software/llvm-install/slot-a/bin/clang-23+0x234cebc)
#2 0x00005e31eca5901c SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00005e31eca590dc SignalHandlerTerminate(int, siginfo_t*, void*) Signals.cpp:0:0
#4 0x00007efa13645330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x00007efa1369eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#6 0x00007efa1369eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#7 0x00007efa1369eb2c pthread_kill ./nptl/pthread_kill.c:89:10
#8 0x00007efa1364527e raise ./signal/../sysdeps/posix/raise.c:27:6
#9 0x00007efa136288ff abort ./stdlib/abort.c:81:7
#10 0x00007efa1362881b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#11 0x00007efa1363b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#12 0x00005e31ec3ffc16 llvm::CallInst::init(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef, llvm::ArrayRef>, llvm::Twine const&) (/home/user/software/llvm-install/slot-a/bin/clang-23+0x1cf3c16)
#13 0x00005e31ed2589ca llvm::IRBuilderBase::CreateCall(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef, llvm::Twine const&, llvm::MDNode*) (.constprop.0) CGBuiltin.cpp:0:0
#14 0x00005e31ed2766fc clang::CodeGen::CodeGenFunction::EmitBuiltinExpr(clang::GlobalDecl, unsigned int, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) (/home/user/software/llvm-install/slot-a/bin/clang-23+0x2b6a6fc)
#15 0x00005e31ecda39a0 clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::CallBase**) (/home/user/software/llvm-install/slot-a/bin/clang-23+0x26979a0)
#16 0x00005e31ece15f01 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) CGExprScalar.cpp:0:0
#17 0x00005e31ece0e762 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/home/user/software/llvm-install/slot-a/bin/clang-23+0x2702762)
#18 0x00005e31ecd68551 clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/home/user/software/llvm-install/slot-a/bin/clang-23+0x265c551)
#19 0x00005e31ecd68888 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (.part.0) CGExpr.cpp:0:0
#20 0x00005e31ecf435ab clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef) (/home/user/software/llvm-install/slot-a/bin/clang-23+0x28375ab)
#21 0x00005e31ecf4a33b clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/home/user/software/llvm-install/slot-a/bin/clang-23+0x283e33b)
#22 0x00005e31ecfb0cc3 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/home/user/software/llvm-install/slot-a/bin/clang-23+0x28a4cc3)
#23 0x00005e31ecfc899c clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/home/user/software/llvm-install/slot-a/bin/clang-23+0x28bc99c)
#24 0x00005e31ed02e78a clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/user/software/llvm-install/slot-a/bin/clang-23+0x292278a)
#25 0x00005e31ed029775 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/user/software/llvm-install/slot-a/bin/clang-23+0x291d775)
#26 0x00005e31ed02a3f3 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/home/user/software/llvm-install/slot-a/bin/clang-23+0x291e3f3)
#27 0x00005e31ed033e87 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#28 0x00005e31ed3c1611 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#29 0x00005e31ed3b1591 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/home/user/software/llvm-install/slot-a/bin/clang-23+0x2ca5591)
#30 0x00005e31ef172fc4 clang::ParseAST(clang::Sema&, bool, bool) (/home/user/software/llvm-install/slot-a/bin/clang-23+0x4a66fc4)
#31 0x00005e31ed73e1d1 clang::FrontendAction::Execute() (/home/user/software/llvm-install/slot-a/bin/clang-23+0x30321d1)
#32 0x00005e31ed6bf278 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/user/software/llvm-install/slot-a/bin/clang-23+0x2fb3278)
#33 0x00005e31ed838e2e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/user/software/llvm-install/slot-a/bin/clang-23+0x312ce2e)
#34 0x00005e31eb4319fa cc1_main(llvm::ArrayRef, char const*, void*) (/home/user/software/llvm-install/slot-a/bin/clang-23+0xd259fa)
#35 0x00005e31eb427a07 ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#36 0x00005e31eb42c745 clang_main(int, char**, llvm::ToolContext const&) (/home/user/software/llvm-install/slot-a/bin/clang-23+0xd20745)
#37 0x00005e31eb3233a0 main (/home/user/software/llvm-install/slot-a/bin/clang-23+0xc173a0)
#38 0x00007efa1362a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#39 0x00007efa1362a28b call_init ./csu/../csu/libc-start.c:128:20
#40 0x00007efa1362a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#41 0x00005e31eb426f75 _start (/home/user/software/llvm-install/slot-a/bin/clang-23+0xd1af75)
clang: error: unable to execute command: Aborted (core dumped)
clang: error: clang frontend command failed with exit code -2 (use -v to see invocation)
clang version 23.0.0git (https://github.com/llvm/llvm-project.git c3e9d05ce8044612ecae2eb27dd5ca52b612a8ac)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/user/software/llvm-install/slot-a/bin
Build config: +assertions
clang: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING CRASH REPRODUCER FILES TO THE BUG REPORT:
clang: note: diagnostic msg: /tmp/bug-ba2cb4.c
clang: note: diagnostic msg: /tmp/bug-ba2cb4.sh
clang: note: diagnostic msg:
********************
Aborted (core dumped)
```
```sh
$ cat /tmp/bug-ba2cb4.c
# 1 ""
# 1 "bug.c"
int a() {
__builtin_prefetch(0, 0 * sizeof(int));
}
```
```sh
# Crash reproducer for clang version 23.0.0git (https://github.com/llvm/llvm-project.git c3e9d05ce8044612ecae2eb27dd5ca52b612a8ac)
# Driver args: "bug.c"
# Original command: "/home/user/software/llvm-install/slot-a/bin/clang-23" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-dumpdir" "a-" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "bug.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=/tmp/creduce" "-fcoverage-compilation-dir=/tmp/creduce" "-resource-dir" "/home/user/software/llvm-install/slot-a/lib/clang/23" "-internal-isystem" "/home/user/software/llvm-install/slot-a/lib/clang/23/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/14/../../../../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" "-fmessage-length=124" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-fcolor-diagnostics" "-faddrsig" "-fdwarf2-cfi-asm" "-o" "/tmp/bug-20a9d9.o" "-x" "c" "bug.c"
"/home/user/software/llvm-install/slot-a/bin/clang-23" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-dumpdir" "a-" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "bug.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=/tmp/creduce" "-fcoverage-compilation-dir=/tmp/creduce" "-ferror-limit" "19" "-fmessage-length=124" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-fcolor-diagnostics" "-faddrsig" "-fdwarf2-cfi-asm" "-x" "c" "bug-ba2cb4.c"
```
Contributor guide
Research direction
Reproduce the crash with the minimal bug.c example and inspect clang's EmitBuiltinExpr path in CGBuiltin.cpp, along with the assertion at llvm/lib/IR/Instructions.cpp:776. Trace the generated call arguments and add regression coverage showing that this __builtin_prefetch case no longer aborts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100