Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault when evaluating generic lambda with lambda default parameter #42196

Closed
ldionne opened this issue Jul 31, 2019 · 7 comments
Closed

Segfault when evaluating generic lambda with lambda default parameter #42196

ldionne opened this issue Jul 31, 2019 · 7 comments
Labels
bugzilla Issues migrated from bugzilla c++14 clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party

Comments

@ldionne
Copy link
Member

ldionne commented Jul 31, 2019

Bugzilla Link 42851
Version trunk
OS All
CC @zygoloid

Extended Description

The following code causes Clang to assert (when built with assertions enabled, obviously):

$ cat <<EOF | clang++ -xc++ - -std=c++14 -fsyntax-only
int main() {
  auto apply = [](auto, void(*)() = []{}) { };
  apply(1);
}
EOF

Produces this output:

Assertion failed: (isDependentContext() && "cannot iterate dependent diagnostics of non-dependent context"), function ddiags, file <snip>/clang-tot/clang/include/clang/AST/DependentDiagnostic.h, line 177.
Stack dump:
0.  Program arguments: <snip>/clang-tot/install/bin/clang-10 -cc1 -triple x86_64-apple-macosx10.15.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -fsyntax-only -disable-free -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -masm-verbose -munwind-tables -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -ggnu-pubnames -target-linker-version 512.4 -resource-dir <snip>/clang-tot/install/lib/clang/10.0.0 -stdlib=libc++ -internal-isystem <snip>/clang-tot/install/bin/../include/c++/v1 -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/include -internal-isystem <snip>/clang-tot/install/lib/clang/10.0.0/include -internal-externc-isystem /usr/include -std=c++14 -fdeprecated-macro -fdebug-compilation-dir <snip> -ferror-limit 19 -fmessage-length 211 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.15.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -x c++ -
1.  <stdin>:3:10: current parser token ')'
2.  <stdin>:1:12: parsing function body 'main'
3.  <stdin>:1:12: in compound statement ('{}')
0  clang-10                 0x0000000105d8c775 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  clang-10                 0x0000000105d8b905 llvm::sys::RunSignalHandlers() + 85
2  clang-10                 0x0000000105d8cd68 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff6d809b1d _sigtramp + 29
4  libsystem_platform.dylib 0x0000000000000e60 _sigtramp + 18446603338679022432
5  libsystem_c.dylib        0x00007fff6d6df91c abort + 120
6  libsystem_c.dylib        0x00007fff6d6debd6 err + 0
7  clang-10                 0x0000000108eef413 clang::Sema::PerformDependentDiagnostics(clang::DeclContext const*, clang::MultiLevelTemplateArgumentList const&) (.cold.1) + 35
8  clang-10                 0x000000010779dcb6 clang::Sema::PerformDependentDiagnostics(clang::DeclContext const*, clang::MultiLevelTemplateArgumentList const&) + 102
9  clang-10                 0x0000000107778c18 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformLambdaExpr(clang::LambdaExpr*) + 4280
10 clang-10                 0x0000000107763255 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) + 2309
11 clang-10                 0x000000010775c934 clang::Sema::SubstParmVarDecl(clang::ParmVarDecl*, clang::MultiLevelTemplateArgumentList const&, int, llvm::Optional<unsigned int>, bool) + 1236
12 clang-10                 0x000000010775d74d clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformFunctionTypeParams(clang::SourceLocation, llvm::ArrayRef<clang::ParmVarDecl*>, clang::QualType const*, clang::FunctionType::ExtParameterInfo const*, llvm::SmallVectorImpl<clang::QualType>&, llvm::SmallVectorImpl<clang::ParmVarDecl*>*, clang::Sema::ExtParameterInfoBuilder&) + 1533
13 clang-10                 0x000000010775b739 clang::Sema::SubstFunctionDeclType(clang::TypeSourceInfo*, clang::MultiLevelTemplateArgumentList const&, clang::SourceLocation, clang::DeclarationName, clang::CXXRecordDecl*, clang::Qualifiers) + 1977
14 clang-10                 0x0000000107795e9e clang::TemplateDeclInstantiator::SubstFunctionType(clang::FunctionDecl*, llvm::SmallVectorImpl<clang::ParmVarDecl*>&) + 254
15 clang-10                 0x0000000107793642 clang::TemplateDeclInstantiator::VisitCXXMethodDecl(clang::CXXMethodDecl*, clang::TemplateParameterList*, llvm::Optional<clang::ASTTemplateArgumentListInfo const*>) + 674
16 clang-10                 0x000000010779b576 clang::Sema::SubstDecl(clang::Decl*, clang::DeclContext*, clang::MultiLevelTemplateArgumentList const&) + 150
17 clang-10                 0x000000010771c38c clang::Sema::FinishTemplateArgumentDeduction(clang::FunctionTemplateDecl*, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, unsigned int, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::Sema::OriginalCallArg> const*, bool, llvm::function_ref<bool ()>) + 2636
18 clang-10                 0x000000010771db50 clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool, llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>)>) + 2320
19 clang-10                 0x000000010761a669 clang::Sema::AddMethodTemplateCandidate(clang::FunctionTemplateDecl*, clang::DeclAccessPair, clang::CXXRecordDecl*, clang::TemplateArgumentListInfo*, clang::QualType, clang::Expr::Classification, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool, bool) + 489
20 clang-10                 0x000000010761adc7 clang::Sema::AddMethodCandidate(clang::DeclAccessPair, clang::QualType, clang::Expr::Classification, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool) + 215
21 clang-10                 0x000000010763371b clang::Sema::BuildCallToObjectOfClassType(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation) + 1003
22 clang-10                 0x0000000107401ca7 clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool) + 1959
23 clang-10                 0x0000000107419349 clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*) + 41
24 clang-10                 0x000000010709b489 clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) + 3897
25 clang-10                 0x00000001070a0938 clang::Parser::ParseCastExpression(bool, bool, bool&, clang::Parser::TypeCastState, bool) + 18472
26 clang-10                 0x0000000107098c26 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) + 166
27 clang-10                 0x0000000107098b5e clang::Parser::ParseExpression(clang::Parser::TypeCastState) + 14
28 clang-10                 0x00000001070e745b clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) + 75
29 clang-10                 0x00000001070e59af clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) + 943
30 clang-10                 0x00000001070e547c clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) + 188
31 clang-10                 0x00000001070ed54d clang::Parser::ParseCompoundStatementBody(bool) + 1725
32 clang-10                 0x00000001070ee0d4 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) + 180
33 clang-10                 0x0000000107107373 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) + 1971
34 clang-10                 0x000000010706fcb5 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) + 2053
35 clang-10                 0x0000000107106885 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) + 693
36 clang-10                 0x00000001071062c3 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) + 371
37 clang-10                 0x0000000107104d30 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) + 2704
38 clang-10                 0x0000000107102f96 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) + 1126
39 clang-10                 0x0000000107102a2a clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) + 42
40 clang-10                 0x000000010705bf5c clang::ParseAST(clang::Sema&, bool, bool) + 444
41 clang-10                 0x00000001064291f4 clang::FrontendAction::Execute() + 84
42 clang-10                 0x00000001063dc358 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1528
43 clang-10                 0x000000010649a313 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1811
44 clang-10                 0x0000000104239ff7 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 2375
45 clang-10                 0x0000000104237856 main + 10662
46 libdyld.dylib            0x00007fff6d6097a9 start + 1
47 libdyld.dylib            0x000000000000003d start + 18446603338681116821
clang-10: error: unable to execute command: Abort trap: 6
clang-10: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 10.0.0 (<snip> c940adeddb86dfccfcbb2eb3fedd0deb0b3640e1)
Target: x86_64-apple-darwin19.0.0
Thread model: posix
InstalledDir: <snip>/clang-tot/install/bin
clang-10: note: diagnostic msg: PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
clang-10: note: diagnostic msg: Error generating preprocessed source(s) - ignoring input from stdin.
clang-10: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
@ldionne
Copy link
Member Author

ldionne commented Jul 31, 2019

I'm creating this for tracking purposes -- I'm about to submit a review for the fix.

@llvmbot
Copy link
Collaborator

llvmbot commented Aug 12, 2019

#41267 seems very similar. Might be possible to fix both together.

@ldionne
Copy link
Member Author

ldionne commented Aug 12, 2019

I don't understand the root cause for #41267 , but I don't think they are related. #41267 appears to be an issue in the code gen, while this issue is in the frontend.

@ldionne
Copy link
Member Author

ldionne commented Mar 2, 2021

We still segfault on this (the same reproducer I originally filed):

$ cat <<EOF | clang++ -xc++ - -std=c++14 -fsyntax-only
int main() {
auto apply = [](auto, void(*)() = []{}) { };
apply(1);
}
EOF

I'm returning this bug report to Clang Unassigned since I don't have time to work on this with the libc++ workload.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@llvmbot llvmbot added the confirmed Verified by a second party label Jan 26, 2022
@shafik
Copy link
Collaborator

shafik commented Jan 28, 2023

Looks like this no longer crashes on clang trunk: https://godbolt.org/z/cezdE3jd5

@shafik shafik closed this as completed Jan 28, 2023
@shafik shafik added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Jan 28, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 28, 2023

@llvm/issue-subscribers-clang-frontend

@ldionne
Copy link
Member Author

ldionne commented Sep 5, 2023

Indeed, looks like this was fixed in Clang 16: https://godbolt.org/z/EoYxT75c6 (clang 15 segfaults and clang 16 doesn't).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++14 clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party
Projects
None yet
Development

No branches or pull requests

3 participants