llvm / llvm/llvm-project

[clang] Assertion `LSI != E && "Should be in a lambda scope info"' failed with -fms-compatibility

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

Description

Reproducer:
https://godbolt.org/z/jWo37GKWx
```cpp
auto l = [](auto a) { return 42; };
using L = decltype(l);

auto L::operator()() const { return {"<="}; }
```

Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/lib/Sema/SemaExpr.cpp:2128: getPredefinedExprDecl(clang::Sema&, clang::DeclContext*)::: Assertion `LSI != E && "Should be in a lambda scope info"' 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. :4:42: current parser token '}'
2. :4:28: parsing function body '(lambda)::operator()'
3. :4:28: in compound statement ('{}')
#0 0x0000000004494808 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4494808)
#1 0x0000000004491a64 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4491a64)
#2 0x000000000449209c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x449209c)
#3 0x00000000043cedd8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x000075d037e45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x000075d037e9ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#6 0x000075d037e4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x000075d037e288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x000075d037e2881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x000075d037e3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x000000000732a78f getPredefinedExprDecl(clang::Sema&, clang::DeclContext*) SemaExpr.cpp:0:0
#11 0x0000000007358b1c clang::Sema::ExpandFunctionLocalPredefinedMacros(llvm::ArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7358b1c)
#12 0x0000000007359861 clang::Sema::ActOnStringLiteral(llvm::ArrayRef, clang::Scope*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7359861)
#13 0x0000000006e6ec19 clang::Parser::ParseStringLiteralExpression(bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e6ec19)
#14 0x0000000006e74137 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e74137)
#15 0x0000000006e75e07 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e75e07)
#16 0x0000000006e75e99 clang::Parser::ParseAssignmentExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e75e99)
#17 0x0000000006e9ee64 clang::Parser::ParseBraceInitializer() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e9ee64)
#18 0x0000000006e9f490 clang::Parser::ParseInitializer(clang::Decl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e9f490)
#19 0x0000000006ef9752 clang::Parser::ParseReturnStatement() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ef9752)
#20 0x0000000006efe33d clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6efe33d)
#21 0x0000000006eff506 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6eff506)
#22 0x0000000006f07a7e clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f07a7e)
#23 0x0000000006f0829a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f0829a)
#24 0x0000000006e0485e clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e0485e)
#25 0x0000000006e4e236 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+++0x6e4e236)
#26 0x0000000006df892b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6df892b)
#27 0x0000000006df911f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6df911f)
#28 0x0000000006e05b88 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e05b88)
#29 0x0000000006e06ac5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e06ac5)
#30 0x0000000006de2e9a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6de2e9a)
#31 0x0000000004fa9bc8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fa9bc8)
#32 0x00000000052c9b68 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52c9b68)
#33 0x000000000525767d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x525767d)
#34 0x000000000539e32d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x539e32d)
#35 0x0000000000d8d90c cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd8d90c)
#36 0x0000000000d8460a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#37 0x0000000000d8478d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#38 0x000000000501d149 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#39 0x00000000043cf1d4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43cf1d4)
#40 0x000000000501dcb5 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#41 0x0000000004fdc272 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fdc272)
#42 0x0000000004fe0bd7 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fe0bd7)
#43 0x0000000004feb065 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4feb065)
#44 0x0000000000d89dfa clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd89dfa)
#45 0x0000000000cc7a5a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc7a5a)
#46 0x000075d037e2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#47 0x000075d037e2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#48 0x0000000000d83fb5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd83fb5)
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 by compiling the provided reproducer with clang++ and -fms-compatibility, then inspect llvm/tools/clang/lib/Sema/SemaExpr.cpp around getPredefinedExprDecl and the ExpandFunctionLocalPredefinedMacros call shown in the backtrace. Done means the reproducer no longer aborts with the lambda-scope assertion and the relevant regression coverage passes.

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
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.