[BUG] ICE in EvaluateComplex(clang::Expr const*, (anonymous namespace)::ComplexValue&, (anonymous namespace)::EvalInfo&)
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
## Bug Report: ICE in EvaluateComplex(clang::Expr const*, (anonymous namespace)::ComplexValue&, (anonymous namespace)::EvalInfo&)
Clang crashes when compiling the following C code.
**Compiler**: clang-22 (LLVM 22.1.5, commit 5ea218a153f4d2f815b8244eab3e4b4ba5e00e6c)
**Compilation flags**: -O0
**Platform**: x86_64-linux-gnu
**Component**: frontend
This is a **frontend** crash (reproduces with `-emit-llvm -Xclang -disable-llvm-passes`).
## Reduced Test Case
> Minimized from the original fuzzer-generated input using `creduce`.
```sh
clang -O0 test.c -o /dev/null
```
```c
struct {
__complex__ a
} b;
c() {
++b.a
```
## Crash Output
```
/root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c:4:1: error: cannot combine with previous 'double' declaration specifier
4 | void b_struct(complex *z) __attribute__((always_inline));
| ^
/root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c:4:15: error: unknown type name 'complex'; did you mean '_Complex'?
4 | void b_struct(complex *z) __attribute__((always_inline));
| ^\~\~\~\~\~\~
| _Complex
/root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c:4:15: warning: plain '_Complex' requires a type specifier; assuming '_Complex double'
4 | void b_struct(complex *z) __attribute__((always_inline));
| ^
| double
/root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c:10:15: error: must use 'struct' tag to refer to type 'complex'
10 | void b_struct(complex *z)
| ^
| struct
/root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c:10:6: error: conflicting types for 'b_struct'
10 | void b_struct(complex *z)
| ^
/root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c:4:6: note: previous declaration is here
4 | void b_struct(complex *z) __attribute__((always_inline));
| ^
/root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c:15:8: error: invalid operands to binary expression ('_Complex long double' and 'int')
15 | z->w > 0;
| \~\~\~\~ ^ \~
/root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c:16:8: error: invalid operands to binary expression ('_Complex long double' and 'int')
16 | z->w >= 0;
| \~\~\~\~ ^ \~
/root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c:17:8: error: invalid operands to binary expression ('_Complex long double' and 'int')
17 | z->w < 0;
| \~\~\~\~ ^ \~
/root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c:18:8: error: invalid operands to binary expression ('_Complex long double' and 'int')
18 | z->w <= 0;
| \~\~\~\~ ^ \~
/root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c:19:8: warning: equality comparison result unused [-Wunused-comparison]
19 | z->w \== 0;
| \~\~\~\~\~^\~\~\~
/root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c:19:8: note: use '=' to turn this equality comparison into an assignment
19 | z->w \== 0;
| ^\~
| \=
/root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c:20:7: warning: inequality comparison result unused [-Wunused-comparison]
20 | z->w!= 0;
| \~\~\~\~^\~\~\~
/root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c:20:7: note: use '|=' to turn this inequality comparison into an or-assignment
20 | z->w!= 0;
| ^\~
| |=
clang-22: /root/compilers/llvm-project-release/clang/lib/AST/ExprConstant.cpp:8971: bool {anonymous}::ExprEvaluatorBase::VisitMemberExpr(const clang::MemberExpr*) [with Derived \= {anonymous}::ComplexExprEvaluator]: Assertion \`!E->isArrow() && "missing call to bound member function?"' 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: /root/objects/llvm-project-release.obj/bin/clang-22 -cc1 -triple x86_64-unknown-linux-gnu -O0 -emit-obj -dumpdir /dev/null- -disable-free -clear-ast-before-backend -main-file-name aibdWAmnbLBP_surfuzz_28.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=/root/data -fcoverage-compilation-dir=/root/data -resource-dir /root/objects/llvm-project-release.obj/lib/clang/22 -internal-isystem /root/objects/llvm-project-release.obj/lib/clang/22/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../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 -faddrsig -fdwarf2-cfi-asm -o /tmp/aibdWAmnbLBP_surfuzz_28-701e1c.o -x c /root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c
1\. /root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c:23:3: current parser token 'z'
2\. /root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c:11:1: parsing function body 'b_struct'
3\. /root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c:11:1: in compound statement ('{}')
#0 0x000056490d5412d2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/root/objects/llvm-project-release.obj/bin/clang-22+0x44f62d2)
#1 0x000056490d53dcaf llvm::sys::RunSignalHandlers() (/root/objects/llvm-project-release.obj/bin/clang-22+0x44f2caf)
#2 0x000056490d53ddfc SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007f15b8f17520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007f15b8f6ba7c __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76
#5 0x00007f15b8f6ba7c __pthread_kill_internal ./nptl/./nptl/pthread_kill.c:78:10
#6 0x00007f15b8f6ba7c pthread_kill ./nptl/./nptl/pthread_kill.c:89:10
#7 0x00007f15b8f17476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007f15b8efd7f3 abort ./stdlib/./stdlib/abort.c:81:7
#9 0x00007f15b8efd71b _nl_load_domain ./intl/./intl/loadmsgcat.c:1177:9
#10 0x00007f15b8f0ee96 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x00005649110d0a3c (anonymous namespace)::ExprEvaluatorBase<(anonymous namespace)::ComplexExprEvaluator>::VisitMemberExpr(clang::MemberExpr const*) ExprConstant.cpp:0:0
#12 0x0000564911125488 (anonymous namespace)::ComplexExprEvaluator::VisitUnaryOperator(clang::UnaryOperator const*) ExprConstant.cpp:0:0
#13 0x00005649110b8358 EvaluateComplex(clang::Expr const*, (anonymous namespace)::ComplexValue&, (anonymous namespace)::EvalInfo&) ExprConstant.cpp:0:0
#14 0x00005649110c099c Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
#15 0x00005649110c11b1 EvaluateAsRValue((anonymous namespace)::EvalInfo&, clang::Expr const*, clang::APValue&) ExprConstant.cpp:0:0
#16 0x00005649110c6d04 clang::Expr::EvaluateForOverflow(clang::ASTContext const&) const (/root/objects/llvm-project-release.obj/bin/clang-22+0x807bd04)
#17 0x000056490ff9cf66 clang::Sema::CheckForIntOverflow(clang::Expr const*) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6f51f66)
#18 0x000056490ffde4a4 clang::Sema::CheckCompletedExpr(clang::Expr*, clang::SourceLocation, bool) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6f934a4)
#19 0x000056491038720e clang::Sema::ActOnFinishFullExpr(clang::Expr*, clang::SourceLocation, bool, bool, bool) (/root/objects/llvm-project-release.obj/bin/clang-22+0x733c20e)
#20 0x00005649106b8f0f clang::Sema::ActOnExprStmt(clang::ActionResult, bool) (/root/objects/llvm-project-release.obj/bin/clang-22+0x766df0f)
#21 0x000056490fe68b84 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6e1db84)
#22 0x000056490fe61d80 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6e16d80)
#23 0x000056490fe62703 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6e17703)
#24 0x000056490fe69361 clang::Parser::ParseCompoundStatementBody(bool) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6e1e361)
#25 0x000056490fe69b3f clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6e1eb3f)
#26 0x000056490fd6dcab clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6d22cab)
#27 0x000056490fdb042d clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6d6542d)
#28 0x000056490fd687e1 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6d1d7e1)
#29 0x000056490fd6900f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6d1e00f)
#30 0x000056490fd71896 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6d26896)
#31 0x000056490fd72915 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6d27915)
#32 0x000056490fd5288a clang::ParseAST(clang::Sema&, bool, bool) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6d0788a)
#33 0x000056490e1ca987 clang::FrontendAction::Execute() (/root/objects/llvm-project-release.obj/bin/clang-22+0x517f987)
#34 0x000056490e1520e9 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/root/objects/llvm-project-release.obj/bin/clang-22+0x51070e9)
#35 0x000056490e2c795e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/root/objects/llvm-project-release.obj/bin/clang-22+0x527c95e)
#36 0x0000564909fd2657 cc1_main(llvm::ArrayRef, char const*, void*) (/root/objects/llvm-project-release.obj/bin/clang-22+0xf87657)
#37 0x0000564909fc7694 ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#38 0x0000564909fcc907 clang_main(int, char**, llvm::ToolContext const&) (/root/objects/llvm-project-release.obj/bin/clang-22+0xf81907)
#39 0x0000564909e8a0ea main (/root/objects/llvm-project-release.obj/bin/clang-22+0xe3f0ea)
#40 0x00007f15b8efed90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#41 0x00007f15b8efee40 call_init ./csu/../csu/libc-start.c:128:20
#42 0x00007f15b8efee40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#43 0x0000564909fc6cb5 _start (/root/objects/llvm-project-release.obj/bin/clang-22+0xf7bcb5)
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 22.1.5 (https://github.com/llvm/llvm-project.git 5ea218a153f4d2f815b8244eab3e4b4ba5e00e6c)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /root/objects/llvm-project-release.obj/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/aibdWAmnbLBP_surfuzz_28-f9113b.c
clang: note: diagnostic msg: /tmp/aibdWAmnbLBP_surfuzz_28-f9113b.sh
clang: note: diagnostic msg:
********************
EXIT_CODE: 1
```
## Preprocessed Source & Run Script
**Preprocessed source** (`/tmp/aibdWAmnbLBP_surfuzz_28-f9113b.c`):
```c
# 1 ""
# 1 "/root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c"
_Complex double
// CHECK-NEXT: ^}
void b_struct(complex *z) __attribute__((always_inline));
struct complex {
__complex__ long double w;
};
void b_struct(complex *z)
{
z->w += 0;
z->w *= 0;
z->w /= 0;
z->w > 0;
z->w >= 0;
z->w < 0;
z->w <= 0;
z->w == 0;
z->w!= 0;
z->w = 0;
++(z->w);
z->w--;
--(z->w);
}
void c_float(float z) __attribute__((always_inline));
void c_float(float z)
{
z += 0;
z *= 0;
z /= 0;
z > 0;
z >= 0;
z < 0;
z <= 0;
z == 0;
z!= 0;
z = 0;
++z;
z--;
--z;
return
{
z += 0;
z *= 0;
z /= 0;
z > 0;
z >= 0;
z < 0;
z <= 0;
z == 0;
z!= 0;
z = 0;
++z;
z--;
--z;
return z;
}
```
**Run script** (`/tmp/aibdWAmnbLBP_surfuzz_28-f9113b.sh`):
```sh
# Crash reproducer for clang version 22.1.5 (https://github.com/llvm/llvm-project.git 5ea218a153f4d2f815b8244eab3e4b4ba5e00e6c)
# Driver args: "-O0" "/root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c" "-o" "/dev/null"
# Original command: "/root/objects/llvm-project-release.obj/bin/clang-22" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-O0" "-emit-obj" "-dumpdir" "/dev/null-" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "aibdWAmnbLBP_surfuzz_28.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=/root/data" "-fcoverage-compilation-dir=/root/data" "-resource-dir" "/root/objects/llvm-project-release.obj/lib/clang/22" "-internal-isystem" "/root/objects/llvm-project-release.obj/lib/clang/22/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/12/../../../../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" "-faddrsig" "-fdwarf2-cfi-asm" "-o" "/tmp/aibdWAmnbLBP_surfuzz_28-701e1c.o" "-x" "c" "/root/outputs/experiments-on-metamut/surfuzz,gcc,1/aibdWAmnbLBP_surfuzz_28.c"
"/root/objects/llvm-project-release.obj/bin/clang-22" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-O0" "-emit-obj" "-dumpdir" "/dev/null-" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "aibdWAmnbLBP_surfuzz_28.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=/root/data" "-fcoverage-compilation-dir=/root/data" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-faddrsig" "-fdwarf2-cfi-asm" "-x" "c" "aibdWAmnbLBP_surfuzz_28-f9113b.c"
```
* found via a fuzzer
[aibdWAmnbLBP_surfuzz_28-f9113b.c](https://github.com/user-attachments/files/29128848/aibdWAmnbLBP_surfuzz_28-f9113b.c)
[aibdWAmnbLBP_surfuzz_28-f9113b.sh](https://github.com/user-attachments/files/29128847/aibdWAmnbLBP_surfuzz_28-f9113b.sh)
Contributor guide
Research direction
Reproduce the crash with the reduced C source and clang -O0 test.c -o /dev/null, then inspect clang/lib/AST/ExprConstant.cpp around VisitMemberExpr and EvaluateComplex. Trace why the complex-expression evaluator reaches the assertion for the member expression; done means the reproducer no longer aborts and regression coverage preserves the fixed behavior.
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
- 48/100