llvm / llvm/llvm-project

[Clang] Crash on EmitIfStmt with option -std=gnu99: Assertion `!isValueDependent() && "Expression evaluator can't be called on a dependent expression."' failed.

Open
#215,454 3 comments 0 reactions 0 assignees View on GitHub
clang:codegen confirmed crash-on-invalid generated by fuzzer regression:20
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Reproducer: https://godbolt.org/z/1EzeMbMa1

Clang crashes on invalid code with an assertion failure in `ExprConstant.cpp` during LLVM IR generation for an if statement with the compiler option `-std=gnu99`. This code was generated by a fuzzer and has been reduced.

Clang version: Clang 24, assertions trunk

```sh
clang version 24.0.0git (https://github.com/llvm/llvm-project.git e337de11042692af6873a4ba13aa60aeba52900e)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin
Build config: +assertions
Found candidate GCC installation: /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/17.0.0
Selected GCC installation: /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/17.0.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
```

`example.c` Code:

```c
#define c(a, b) \
{;__typeof__(b);}
void d(int e) {if((c(, e););
}
```

Command:

```sh
clang -std=gnu99 example.c
```

Backtrace:

```sh
clang-24: /root/llvm-project/llvm/tools/clang/lib/AST/ExprConstant.cpp:21888: bool clang::Expr::EvaluateAsInt(clang::Expr::EvalResult&, const clang::ASTContext&, clang::Expr::SideEffectsKind, bool) const: Assertion `!isValueDependent() && "Expression evaluator can't be called on a dependent expression."' 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: /cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir /app/output.s- -disable-free -clear-ast-before-backend -main-file-name example.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -fno-verbose-asm -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debug-info-kind=constructor -dwarf-version=5 -debugger-tuning=gdb -fdebug-compilation-dir=/app -fcoverage-compilation-dir=/app -resource-dir /cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/lib/clang/24 -internal-isystem /cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/lib/clang/24/include -internal-isystem /cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/../include/x86_64-unknown-linux-gnu -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/17.0.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=gnu99 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -faddrsig -fdwarf2-cfi-asm -o /tmp/example-28c135.o -x c
1. parser at end of file
2. :3:6: LLVM IR generation of declaration 'd'
3. :3:6: Generating code for declaration 'd'
#0 0x0000000004444738 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0x4444738)
#1 0x00000000044415e4 llvm::sys::RunSignalHandlers() (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0x44415e4)
#2 0x000000000444175e SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x0000000004441808 SignalHandlerTerminate(int, siginfo_t*, void*) Signals.cpp:0:0
#4 0x0000702f50e45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x0000702f50e9ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#6 0x0000702f50e4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x0000702f50e288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x0000702f50e2881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x0000702f50e3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x000000000813ffb5 clang::Expr::EvaluateAsInt(clang::Expr::EvalResult&, clang::ASTContext const&, clang::Expr::SideEffectsKind, bool) const (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0x813ffb5)
#11 0x0000000004b2eb3a clang::CodeGen::CodeGenFunction::ConstantFoldsToSimpleInteger(clang::Expr const*, bool&, bool) (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0x4b2eb3a)
#12 0x0000000004ac4de4 clang::CodeGen::CodeGenFunction::EmitIfStmt(clang::IfStmt const&) (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0x4ac4de4)
#13 0x0000000004ac5afb clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0x4ac5afb)
#14 0x0000000004b2e496 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0x4b2e496)
#15 0x0000000004b43eb4 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0x4b43eb4)
#16 0x0000000004bb432a clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0x4bb432a)
#17 0x0000000004bad704 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0x4bad704)
#18 0x0000000004badef3 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0x4badef3)
#19 0x0000000004bbb581 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#20 0x0000000004f3b459 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#21 0x0000000004f2c504 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0x4f2c504)
#22 0x0000000006d4eb74 clang::ParseAST(clang::Sema&, bool, bool) (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0x6d4eb74)
#23 0x0000000004f392c8 clang::CodeGenAction::ExecuteAction() (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0x4f392c8)
#24 0x0000000005265658 clang::FrontendAction::Execute() (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0x5265658)
#25 0x00000000051f286d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0x51f286d)
#26 0x000000000533af2d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0x533af2d)
#27 0x0000000000dae10c cc1_main(llvm::ArrayRef, char const*, void*) (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0xdae10c)
#28 0x0000000000da4d2a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#29 0x0000000000da922b clang_main(int, char**, llvm::ToolContext const&) (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0xda922b)
#30 0x0000000000cc628a main (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0xcc628a)
#31 0x0000702f50e2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#32 0x0000702f50e2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#33 0x0000000000da46d5 _start (/cefs/ae/aecea0a9f578c21d1f019eeb_clang-assertions-trunk-20260810/bin/clang-24+0xda46d5)
clang: error: unable to execute command: Aborted (core dumped)
clang: error: clang frontend command failed with exit code -2 (use -v to see invocation)

```

Contributor guide

Open the contributing guide

Research direction

Reproduce the assertion with the provided example.c and `clang -std=gnu99`. Start in `clang/lib/AST/ExprConstant.cpp` and the `CodeGenFunction::EmitIfStmt` path named in the backtrace; done means this reduced invalid program no longer aborts during LLVM IR generation.

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
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.