llvm / llvm/llvm-project

[clang] Assertion `isTypeIdInParens() && "Not a type-id!"' failed.

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

Description

Reproducer:
https://godbolt.org/z/eP1z41zzE
```cpp
template struct S {};

namespace foo {};

int bar = (void(foo::S));
```

Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/lib/Parse/ParseExprCXX.cpp:3598: clang::ExprResult clang::Parser::ParseCXXAmbiguousParenExpression(clang::ParenParseOption&, clang::ParsedType&, clang::BalancedDelimiterTracker&, clang::ColonProtectionRAIIObject&): Assertion `isTypeIdInParens() && "Not a type-id!"' 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
1. :5:12: current parser token 'void'
#0 0x0000000004494678 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4494678)
#1 0x00000000044918d4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44918d4)
#2 0x0000000004491f0c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4491f0c)
#3 0x00000000043ced38 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x00007468a8845330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x00007468a889ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#6 0x00007468a884527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x00007468a88288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x00007468a882881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x00007468a883b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x0000000006e8e344 clang::Parser::ParseCXXAmbiguousParenExpression(clang::ParenParseOption&, clang::OpaquePtr&, clang::BalancedDelimiterTracker&, clang::ColonProtectionRAIIObject&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e8e344)
#11 0x0000000006e7b6ca clang::Parser::ParseParenExpression(clang::ParenParseOption&, bool, clang::ParenExprKind, clang::TypoCorrectionTypeBehavior, clang::OpaquePtr&, clang::SourceLocation&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e7b6ca)
#12 0x0000000006e70fad clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e70fad)
#13 0x0000000006e725d7 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e725d7)
#14 0x0000000006e72669 clang::Parser::ParseAssignmentExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e72669)
#15 0x0000000006e9bb80 clang::Parser::ParseInitializer(clang::Decl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e9bb80)
#16 0x0000000006e29f9e clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e29f9e)
#17 0x0000000006e49fa9 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e49fa9)
#18 0x0000000006df50fb clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6df50fb)
#19 0x0000000006df58ef clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6df58ef)
#20 0x0000000006e02358 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e02358)
#21 0x0000000006e03295 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e03295)
#22 0x0000000006ddf66a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ddf66a)
#23 0x0000000004fa6dc8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fa6dc8)
#24 0x00000000052c6e48 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52c6e48)
#25 0x000000000525494d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x525494d)
#26 0x000000000539b60d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x539b60d)
#27 0x0000000000d8d50c cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd8d50c)
#28 0x0000000000d8420a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#29 0x0000000000d8438d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#30 0x000000000501a359 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#31 0x00000000043cf134 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43cf134)
#32 0x000000000501aec5 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#33 0x0000000004fd9472 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fd9472)
#34 0x0000000004fdddd7 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fdddd7)
#35 0x0000000004fe8265 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fe8265)
#36 0x0000000000d899fa clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd899fa)
#37 0x0000000000cc765a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc765a)
#38 0x00007468a882a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#39 0x00007468a882a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#40 0x0000000000d83bb5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd83bb5)
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 the reproducer and the assertion in llvm/tools/clang/lib/Parse/ParseExprCXX.cpp, particularly Parser::ParseCXXAmbiguousParenExpression. Run the supplied C++ snippet under clang++ to confirm the crash, then trace how the parenthesized expression is classified. Done means the reproducer no longer aborts and equivalent parsing remains covered by a regression test.

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.