llvm / llvm/llvm-project

Using ?: operator in fold expression -> Assertion `!(D & ExprDependence::UnexpandedPack)' failed.

Open
#162,198 9 comments 0 reactions 0 assignees View on GitHub
clang:frontend confirmed crash
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

[Godbolt link](https://godbolt.org/z/7KMbKGfrG)
```cpp
template
void foo(A ...a) {
(a ?: 42, ...);
}
```

```
clang++: /root/llvm-project/llvm/tools/clang/lib/AST/ComputeDependence.cpp:32: clang::ExprDependence clang::computeDependence(clang::OpaqueValueExpr*): Assertion `!(D & ExprDependence::UnexpandedPack)' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
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. :3:10: current parser token ','
2. :2:18: parsing function body 'foo'
3. :2:18: in compound statement ('{}')
#0 0x00000000041ca628 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41ca628)
#1 0x00000000041c7a54 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41c7a54)
#2 0x000000000410bce8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007c47ee842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007c47ee8969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007c47ee842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007c47ee8287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x00007c47ee82871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x00007c47ee839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x00000000079689fa clang::computeDependence(clang::OpaqueValueExpr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x79689fa)
#10 0x0000000006e23014 clang::Sema::ActOnConditionalOp(clang::SourceLocation, clang::SourceLocation, clang::Expr*, clang::Expr*, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e23014)
#11 0x000000000692b2cf clang::Parser::ParseRHSOfBinaryExpression(clang::ActionResult, clang::prec::Level) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x692b2cf)
#12 0x000000000692e169 clang::Parser::ParseExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x692e169)
#13 0x0000000006931f04 clang::Parser::ParseParenExpression(clang::ParenParseOption&, bool, clang::ParenExprKind, clang::TypoCorrectionTypeBehavior, clang::OpaquePtr&, clang::SourceLocation&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6931f04)
#14 0x0000000006928538 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6928538)
#15 0x00000000069298a7 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x69298a7)
#16 0x0000000006929939 clang::Parser::ParseAssignmentExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6929939)
#17 0x000000000692e169 clang::Parser::ParseExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x692e169)
#18 0x00000000069b2d89 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x69b2d89)
#19 0x00000000069aa112 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x69aa112)
#20 0x00000000069aaf89 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x69aaf89)
#21 0x00000000069b349e clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x69b349e)
#22 0x00000000069b3cba clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x69b3cba)
#23 0x00000000068ba1bb clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x68ba1bb)
#24 0x00000000068f062d 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+++0x68f062d)
#25 0x00000000069bf9b8 clang::Parser::ParseDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x69bf9b8)
#26 0x00000000069ccb99 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (.part.0) ParseTemplate.cpp:0:0
#27 0x00000000069ccfaa clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x69ccfaa)
#28 0x00000000068f8f30 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x68f8f30)
#29 0x00000000068b5627 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x68b5627)
#30 0x00000000068b64f5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x68b64f5)
#31 0x00000000068b69b0 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x68b69b0)
#32 0x0000000006897b23 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6897b23)
#33 0x0000000004b08ee8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b08ee8)
#34 0x0000000004df44e5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4df44e5)
#35 0x0000000004d754be clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4d754be)
#36 0x0000000004eeb75d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4eeb75d)
#37 0x0000000000dbbd40 cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdbbd40)
#38 0x0000000000db28aa ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#39 0x0000000000db2a2d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#40 0x0000000004b72069 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#41 0x000000000410c184 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x410c184)
#42 0x0000000004b7267f clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#43 0x0000000004b339b2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b339b2)
#44 0x0000000004b3495e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b3495e)
#45 0x0000000004b3c095 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b3c095)
#46 0x0000000000db8269 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdb8269)
#47 0x0000000000c69a74 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc69a74)
#48 0x00007c47ee829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#49 0x00007c47ee829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#50 0x0000000000db2345 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdb2345)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the assertion with the C++ template from the Godbolt link using an assertions-enabled Clang build. Start in llvm/tools/clang/lib/AST/ComputeDependence.cpp and follow the Sema::ActOnConditionalOp entry point shown in the stack trace. Done means the reproducer no longer aborts with the UnexpandedPack 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
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.