[clang] Assertion `(Params || CurTok.is(tok::eod)) && "expected success or to be at the end of the directive"' failed.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Reproducer:
https://godbolt.org/z/sf8ojYoo4
```c
#embed limit(defined(bar)),
```
Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/lib/Lex/PPDirectives.cpp:4127: void clang::Preprocessor::HandleEmbedDirective(clang::SourceLocation, clang::Token&): Assertion `(Params || CurTok.is(tok::eod)) && "expected success or to be at the end of the directive"' 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: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -x c -std=c23
1. :1:2: current parser token 'embed'
#0 0x0000000004421578 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4421578)
#1 0x000000000441e424 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x441e424)
#2 0x000000000441ea5c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x441ea5c)
#3 0x000000000435da38 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x0000727da6a45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x0000727da6a9eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#6 0x0000727da6a4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x0000727da6a288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x0000727da6a2881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x0000727da6a3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x0000000008779c73 clang::Preprocessor::HandleEmbedDirective(clang::SourceLocation, clang::Token&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x8779c73)
#11 0x0000000008786694 clang::Preprocessor::HandleDirective(clang::Token&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x8786694)
#12 0x000000000871c8aa clang::Lexer::LexTokenInternal(clang::Token&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x871c8aa)
#13 0x000000000871eb0a clang::Lexer::Lex(clang::Token&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x871eb0a)
#14 0x00000000087ca4bc clang::Preprocessor::Lex(clang::Token&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x87ca4bc)
#15 0x0000000006d41492 clang::Parser::ConsumeToken() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d41492)
#16 0x0000000006d2d8f1 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d2d8f1)
#17 0x0000000004f2c288 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f2c288)
#18 0x0000000005259508 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5259508)
#19 0x00000000051e60cd clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51e60cd)
#20 0x000000000532dc4d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x532dc4d)
#21 0x0000000000daf4dc cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdaf4dc)
#22 0x0000000000da60ea ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#23 0x0000000000da626d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#24 0x0000000004fa3749 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#25 0x000000000435de74 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x435de74)
#26 0x0000000004fa42b5 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#27 0x0000000004f5ca92 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f5ca92)
#28 0x0000000004f612c7 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f612c7)
#29 0x0000000004f6b825 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f6b825)
#30 0x0000000000dab9ca clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdab9ca)
#31 0x0000000000cc5c5a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc5c5a)
#32 0x0000727da6a2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#33 0x0000727da6a2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#34 0x0000000000da5a95 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda5a95)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
```
Contributor guide
Research direction
Start in llvm/tools/clang/lib/Lex/PPDirectives.cpp at Preprocessor::HandleEmbedDirective, identified in the backtrace, and reproduce the failure with the linked Compiler Explorer example. Trace parsing of the #embed limit argument and verify that the reproducer no longer triggers the assertion or aborts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100