[BUG] ICE in clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
## Bug Report: ICE in clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const
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 { long a : 33 __attribute__((mode(QI);
} b = {b.a}
```
## Crash Output
```
/root/outputs/experiments-on-metamut/surfuzz,gcc,4/bbigMRtPfwwa_surfuzz_2.c:6:26: warning: unknown attribute 'noclone' ignored; did you mean 'noinline'? [-Wunknown-attributes]
6 | __attribute__((noinline, noclone)) void
| ^\~\~\~\~\~\~
| noinline
/root/outputs/experiments-on-metamut/surfuzz,gcc,4/bbigMRtPfwwa_surfuzz_2.c:9:24: error: use of unknown builtin '__builtin_shuffle' [-Wimplicit-function-declaration]
9 | b.m \= (unsigned int) __builtin_shuffle (a, a);
| ^
clang-22: /root/compilers/llvm-project-release/clang/lib/AST/RecordLayoutBuilder.cpp:1462: void {anonymous}::ItaniumRecordLayoutBuilder::LayoutWideBitField(uint64_t, uint64_t, bool, const clang::FieldDecl*): Assertion \`Context.getLangOpts().CPlusPlus && "Can only have wide bit-fields in C++!"' 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 bbigMRtPfwwa_surfuzz_2.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/bbigMRtPfwwa_surfuzz_2-a8f865.o -x c /root/outputs/experiments-on-metamut/surfuzz,gcc,4/bbigMRtPfwwa_surfuzz_2.c
1\. /root/outputs/experiments-on-metamut/surfuzz,gcc,4/bbigMRtPfwwa_surfuzz_2.c:10:1: current parser token '}'
2\. /root/outputs/experiments-on-metamut/surfuzz,gcc,4/bbigMRtPfwwa_surfuzz_2.c:8:1: parsing function body 'foo'
3\. /root/outputs/experiments-on-metamut/surfuzz,gcc,4/bbigMRtPfwwa_surfuzz_2.c:8:1: in compound statement ('{}')
#0 0x0000558623eda2d2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/root/objects/llvm-project-release.obj/bin/clang-22+0x44f62d2)
#1 0x0000558623ed6caf llvm::sys::RunSignalHandlers() (/root/objects/llvm-project-release.obj/bin/clang-22+0x44f2caf)
#2 0x0000558623ed6dfc SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007fb934b89520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007fb934bdda7c __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76
#5 0x00007fb934bdda7c __pthread_kill_internal ./nptl/./nptl/pthread_kill.c:78:10
#6 0x00007fb934bdda7c pthread_kill ./nptl/./nptl/pthread_kill.c:89:10
#7 0x00007fb934b89476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007fb934b6f7f3 abort ./stdlib/./stdlib/abort.c:81:7
#9 0x00007fb934b6f71b _nl_load_domain ./intl/./intl/loadmsgcat.c:1177:9
#10 0x00007fb934b80e96 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x0000558627debcd8 (anonymous namespace)::ItaniumRecordLayoutBuilder::LayoutField(clang::FieldDecl const*, bool) RecordLayoutBuilder.cpp:0:0
#12 0x0000558627debd59 (anonymous namespace)::ItaniumRecordLayoutBuilder::LayoutFields(clang::RecordDecl const*) RecordLayoutBuilder.cpp:0:0
#13 0x0000558627de4dfd clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/root/objects/llvm-project-release.obj/bin/clang-22+0x8400dfd)
#14 0x0000558627a105fa HandleLValueMember((anonymous namespace)::EvalInfo&, clang::Expr const*, (anonymous namespace)::LValue&, clang::FieldDecl const*, clang::ASTRecordLayout const*) (.constprop.0) ExprConstant.cpp:0:0
#15 0x0000558627a323d1 (anonymous namespace)::LValueExprEvaluator::VisitMemberExpr(clang::MemberExpr const*) ExprConstant.cpp:0:0
#16 0x0000558627a34a99 EvaluateLValue(clang::Expr const*, (anonymous namespace)::LValue&, (anonymous namespace)::EvalInfo&, bool) ExprConstant.cpp:0:0
#17 0x0000558627a596cf Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
#18 0x0000558627a95492 (anonymous namespace)::IntExprEvaluator::VisitBinaryOperator(clang::BinaryOperator const*) ExprConstant.cpp:0:0
#19 0x0000558627a597e0 Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
#20 0x0000558627a5a1b1 EvaluateAsRValue((anonymous namespace)::EvalInfo&, clang::Expr const*, clang::APValue&) ExprConstant.cpp:0:0
#21 0x0000558627a5fd04 clang::Expr::EvaluateForOverflow(clang::ASTContext const&) const (/root/objects/llvm-project-release.obj/bin/clang-22+0x807bd04)
#22 0x0000558626935f66 clang::Sema::CheckForIntOverflow(clang::Expr const*) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6f51f66)
#23 0x00005586269774a4 clang::Sema::CheckCompletedExpr(clang::Expr*, clang::SourceLocation, bool) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6f934a4)
#24 0x0000558626d2020e clang::Sema::ActOnFinishFullExpr(clang::Expr*, clang::SourceLocation, bool, bool, bool) (/root/objects/llvm-project-release.obj/bin/clang-22+0x733c20e)
#25 0x0000558627051f0f clang::Sema::ActOnExprStmt(clang::ActionResult, bool) (/root/objects/llvm-project-release.obj/bin/clang-22+0x766df0f)
#26 0x0000558626801b84 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6e1db84)
#27 0x00005586267fad80 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)
#28 0x00005586267fb703 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6e17703)
#29 0x0000558626802361 clang::Parser::ParseCompoundStatementBody(bool) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6e1e361)
#30 0x0000558626802b3f clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6e1eb3f)
#31 0x0000558626706cab clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6d22cab)
#32 0x000055862674942d 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)
#33 0x00005586267017e1 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6d1d7e1)
#34 0x000055862670200f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6d1e00f)
#35 0x000055862670a896 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6d26896)
#36 0x000055862670b915 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6d27915)
#37 0x00005586266eb88a clang::ParseAST(clang::Sema&, bool, bool) (/root/objects/llvm-project-release.obj/bin/clang-22+0x6d0788a)
#38 0x0000558624b63987 clang::FrontendAction::Execute() (/root/objects/llvm-project-release.obj/bin/clang-22+0x517f987)
#39 0x0000558624aeb0e9 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/root/objects/llvm-project-release.obj/bin/clang-22+0x51070e9)
#40 0x0000558624c6095e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/root/objects/llvm-project-release.obj/bin/clang-22+0x527c95e)
#41 0x000055862096b657 cc1_main(llvm::ArrayRef, char const*, void*) (/root/objects/llvm-project-release.obj/bin/clang-22+0xf87657)
#42 0x0000558620960694 ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#43 0x0000558620965907 clang_main(int, char**, llvm::ToolContext const&) (/root/objects/llvm-project-release.obj/bin/clang-22+0xf81907)
#44 0x00005586208230ea main (/root/objects/llvm-project-release.obj/bin/clang-22+0xe3f0ea)
#45 0x00007fb934b70d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#46 0x00007fb934b70e40 call_init ./csu/../csu/libc-start.c:128:20
#47 0x00007fb934b70e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#48 0x000055862095fcb5 _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/bbigMRtPfwwa_surfuzz_2-15a579.c
clang: note: diagnostic msg: /tmp/bbigMRtPfwwa_surfuzz_2-15a579.sh
clang: note: diagnostic msg:
********************
EXIT_CODE: 1
```
## Preprocessed Source & Run Script
**Preprocessed source** (`/tmp/bbigMRtPfwwa_surfuzz_2-15a579.c`):
```c
# 1 ""
# 1 "/root/outputs/experiments-on-metamut/surfuzz,gcc,4/bbigMRtPfwwa_surfuzz_2.c"
unsigned long long int a = 0x95dd3d896f7422e2ULL;
static struct A
{
long unsigned int m: 33 __attribute__((mode (QI)));
} b = { 0 };
__attribute__((noinline, noclone)) void
foo (void)
{
b.m = (unsigned int) __builtin_shuffle (a, a);
}
int
main ()
{
if (__INT_MAX__ != 0x7fffffffULL)
return 0;
foo ();
if (b.m != 0)
__builtin_abort ();
return 0;
}
```
**Run script** (`/tmp/bbigMRtPfwwa_surfuzz_2-15a579.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,4/bbigMRtPfwwa_surfuzz_2.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" "bbigMRtPfwwa_surfuzz_2.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/bbigMRtPfwwa_surfuzz_2-a8f865.o" "-x" "c" "/root/outputs/experiments-on-metamut/surfuzz,gcc,4/bbigMRtPfwwa_surfuzz_2.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" "bbigMRtPfwwa_surfuzz_2.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" "bbigMRtPfwwa_surfuzz_2-15a579.c"
```
* found via a fuzzer
[bbigMRtPfwwa_surfuzz_2-15a579.c](https://github.com/user-attachments/files/29129372/bbigMRtPfwwa_surfuzz_2-15a579.c)
[bbigMRtPfwwa_surfuzz_2-15a579.sh](https://github.com/user-attachments/files/29129371/bbigMRtPfwwa_surfuzz_2-15a579.sh)
Contributor guide
Research direction
Reproduce the crash with the reduced C source and command shown in the report, then inspect clang/lib/AST/RecordLayoutBuilder.cpp around ItaniumRecordLayoutBuilder::LayoutWideBitField and ASTContext::getASTRecordLayout. Done means the reproducer no longer triggers the assertion or frontend crash, with regression coverage for this input.
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