llvm / llvm/llvm-project

[clang] Assertion `IsSLocAffecting[FID.ID]' failed and Assertion `BlockScope.empty() && CurAbbrevs.empty() && "Block imbalance"` failed

Open
#214,925 3 comments 0 reactions 0 assignees View on GitHub
clang:modules crash generated by fuzzer
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The following code:

```cpp
#pragma clang module build A
module A {}
#pragma clang module contents
#pragma clang module begin A
#pragma clang module build B
module B {}
#pragma clang module endbuild
#pragma clang module import B
#pragma clang module end
#pragma clang module endbuild
#pragma clang module build B
module B {}
#pragma clang module contents
#pragma clang module begin B
#pragma clang module import A
#pragma clang module end
```

Resulted in this output:
```
clang++: /home/fuzz/WorkSpace/fusion-fuzz/projects/clang/llvm-project/clang/lib/Serialization/ASTWriter.cpp:7183: void clang::ASTWriter::associateDeclWithFile(const clang::Decl*, clang::LocalDeclID): Assertion `IsSLocAffecting[FID.ID]' failed.
clang++: /home/fuzz/WorkSpace/fusion-fuzz/projects/clang/llvm-project/llvm/include/llvm/Bitstream/BitstreamWriter.h:168: llvm::BitstreamWriter::~BitstreamWriter(): Assertion `BlockScope.empty() && CurAbbrevs.empty() && "Block imbalance"' 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/fuzz/WorkSpace/fusion-fuzz/projects/clang/llvm-clang-install/bin/clang++ -std=c++20 -O0 -fsyntax-only /tmp/test.cpp
1. /tmp/test.cpp:57:2: current parser token 'pragma'
2. Building module 'B' as '/tmp/B-036220.pcm'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 clang++ 0x000055ba0181e0f9 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 121
1 clang++ 0x000055ba0181adcc llvm::sys::RunSignalHandlers() + 76
2 clang++ 0x000055ba0181b678 llvm::sys::CleanupOnSignal(unsigned long) + 216
3 clang++ 0x000055ba0175df88
4 libc.so.6 0x00007fdf7c182520
5 libc.so.6 0x00007fdf7c1d69fc pthread_kill + 300
6 libc.so.6 0x00007fdf7c182476 raise + 22
7 libc.so.6 0x00007fdf7c1687f3 abort + 211
8 libc.so.6 0x00007fdf7c16871b
9 libc.so.6 0x00007fdf7c179e96
10 clang++ 0x000055ba027a55c2 clang::PCHGenerator::~PCHGenerator() + 1554
11 clang++ 0x000055ba027a55fd clang::PCHGenerator::~PCHGenerator() + 13
12 clang++ 0x000055ba0255d6a3 clang::MultiplexConsumer::~MultiplexConsumer() + 99
13 clang++ 0x000055ba0255d6fd clang::MultiplexConsumer::~MultiplexConsumer() + 13
14 clang++ 0x000055ba02489b79 clang::CompilerInstance::compileModule(clang::SourceLocation, llvm::StringRef, llvm::StringRef, clang::CompilerInstance&) + 1305
15 clang++ 0x000055ba0249e867 clang::CompilerInstance::createModuleFromSource(clang::SourceLocation, llvm::StringRef, llvm::StringRef) + 1575
16 clang++ 0x000055ba05ad3485 clang::Preprocessor::HandlePragmaDirective(clang::PragmaIntroducer) + 101
17 clang++ 0x000055ba05aa8c2a clang::Preprocessor::HandleDirective(clang::Token&) + 1898
18 clang++ 0x000055ba05a3ae60 clang::Lexer::LexTokenInternal(clang::Token&) + 1312
19 clang++ 0x000055ba05a3d04e clang::Lexer::Lex(clang::Token&) + 174
20 clang++ 0x000055ba05aec2cc clang::Preprocessor::Lex(clang::Token&) + 60
21 clang++ 0x000055ba03faf370
22 clang++ 0x000055ba03f9b6b0 clang::ParseAST(clang::Sema&, bool, bool) + 496
23 clang++ 0x000055ba02514071 clang::FrontendAction::Execute() + 65
24 clang++ 0x000055ba0249dc65 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1589
25 clang++ 0x000055ba025efea3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 467
26 clang++ 0x000055ba001f2c96 cc1_main(llvm::ArrayRef, char const*, void*) + 7046
27 clang++ 0x000055ba001e8a2a
28 clang++ 0x000055ba001e8bbf
29 clang++ 0x000055ba0222535d
30 clang++ 0x000055ba0175e3a0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) + 160
31 clang++ 0x000055ba022261b3
32 clang++ 0x000055ba021db987 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const + 167
33 clang++ 0x000055ba021e01e0 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const + 304
34 clang++ 0x000055ba021ede44 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) + 404
35 clang++ 0x000055ba001ee2d3 clang_main(int, char**, llvm::ToolContext const&) + 7267
36 clang++ 0x000055ba001407a1 main + 113
37 libc.so.6 0x00007fdf7c169d90
38 libc.so.6 0x00007fdf7c169e40 __libc_start_main + 128
39 clang++ 0x000055ba001e8055 _start + 37
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 24.0.0git (https://github.com/llvm/llvm-project.git aefba88f46a6e55645c848f58f6ba56944d5ae62)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/fuzz/WorkSpace/fusion-fuzz/projects/clang/llvm-clang-install/bin
Build config: +assertions
clang++: error: unable to execute command: Aborted (core dumped)
clang++: note: diagnostic msg: Error generating preprocessed source(s).
Aborted (core dumped)
```

To reproduce:
```
/home/fuzz/WorkSpace/fusion-fuzz/projects/clang/llvm-clang-install/bin/clang++ -std=c++20 -fsyntax-only ./test.cpp
```

Compiler version:
```
clang version 24.0.0git (https://github.com/llvm/llvm-project.git aefba88f46a6e55645c848f58f6ba56944d5ae62)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/fuzz/WorkSpace/fusion-fuzz/projects/clang/llvm-clang-install/bin
Build config: +assertions
```

*This bug was found by [fusion-fuzz](https://github.com/fusion-fuzz/fusion-fuzz)*

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the crash with the provided test.cpp and clang++ command, then inspect clang/lib/Serialization/ASTWriter.cpp around the IsSLocAffecting assertion and llvm/include/llvm/Bitstream/BitstreamWriter.h around the block-imbalance assertion. Done means the supplied nested module-build testcase no longer aborts with either assertion.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.