llvm / llvm/llvm-project

[clang] malformed __identifier directive causes preprocessor assertion failure with -fms-compatibility

Open
#222,310 2 comments 0 reactions 0 assignees View on GitHub
clang:frontend crash-on-invalid generated by fuzzer
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Reproducer:
https://godbolt.org/z/xEYs9vb51
```cpp
# 1 __identifier(foo
```

Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/lib/Lex/PPDirectives.cpp:97: clang::SourceRange clang::Preprocessor::DiscardUntilEndOfDirective(clang::Token&, llvm::SmallVectorImpl*): Assertion `Tmp.isNot(tok::eof) && "EOF seen while discarding directive tokens"' 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 -fms-compatibility
1. :1:3: current parser token '1'
#0 0x00000000044aca88 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44aca88)
#1 0x00000000044a9ce4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44a9ce4)
#2 0x00000000044aa31c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44aa31c)
#3 0x00000000043e6898 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x00007cd3fa045330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x00007cd3fa09ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#6 0x00007cd3fa04527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x00007cd3fa0288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x00007cd3fa02881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x00007cd3fa03b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x0000000008868d95 clang::Preprocessor::DiscardUntilEndOfDirective(clang::Token&, llvm::SmallVectorImpl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x8868d95)
#11 0x00000000088704c2 clang::Preprocessor::HandleDigitDirective(clang::Token&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x88704c2)
#12 0x000000000887f193 clang::Preprocessor::HandleDirective(clang::Token&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x887f193)
#13 0x000000000881488a clang::Lexer::LexTokenInternal(clang::Token&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x881488a)
#14 0x0000000008816afa clang::Lexer::Lex(clang::Token&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x8816afa)
#15 0x00000000088c382c clang::Preprocessor::Lex(clang::Token&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x88c382c)
#16 0x0000000006e10012 clang::Parser::ConsumeToken() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e10012)
#17 0x0000000006dfbd61 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dfbd61)
#18 0x0000000004fc0788 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fc0788)
#19 0x00000000052e0e28 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52e0e28)
#20 0x000000000526e92d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x526e92d)
#21 0x00000000053b564d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x53b564d)
#22 0x0000000000d8f6fc cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd8f6fc)
#23 0x0000000000d863fa ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#24 0x0000000000d8657d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#25 0x0000000005034329 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#26 0x00000000043e6c94 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43e6c94)
#27 0x0000000005034e95 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#28 0x0000000004ff32c2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ff32c2)
#29 0x0000000004ff7c27 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ff7c27)
#30 0x0000000005002185 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5002185)
#31 0x0000000000d8bbea clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd8bbea)
#32 0x0000000000cc977a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc977a)
#33 0x00007cd3fa02a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#34 0x00007cd3fa02a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#35 0x0000000000d85da5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd85da5)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Program terminated with signal SIGABRT (6)
Compiler returned: 134
```

Contributor guide

Open the contributing guide

Research direction

Start with llvm/tools/clang/lib/Lex/PPDirectives.cpp, especially Preprocessor::HandleDigitDirective and DiscardUntilEndOfDirective, using the reported reproducer with -fms-compatibility. Trace how the malformed __identifier directive reaches EOF, then verify the input produces diagnostics without triggering an assertion or crash.

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
Active
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.