Skip to content

[Clang] Assertion when including a header that does not exist #86757

Closed
@Sirraide

Description

@Sirraide

This asserts on main (https://godbolt.org/z/KMxazTaj1) in C++20 mode or later:

#include <concepts>
#include <foobar> // Or some other header that doesn't exist.
#include <ranges>

Interestingly, it doesn’t seem to matter whether libc++ or libstdc++ is used, but removing any of the #includes fixes the crash, and which headers are used does seem to matter.

Stack trace:

<source>:2:10: fatal error: 'foobar' file not found
    2 | #include <foobar>
      |          ^~~~~~~~
clang++: /root/llvm-project/llvm/include/llvm/ADT/SmallVector.h:322: T& llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::back() [with T = clang::Sema::CodeSynthesisContext; <template-parameter-1-2> = void; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::reference = clang::Sema::CodeSynthesisContext&]: Assertion `!empty()' 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++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++2c -stdlib=libc++ <source>
1.	/opt/compiler-explorer/clang-assertions-trunk-20240326/bin/../include/c++/v1/__ranges/movable_box.h:185:26: current parser token '{'
2.	/opt/compiler-explorer/clang-assertions-trunk-20240326/bin/../include/c++/v1/__ranges/movable_box.h:30:1 <Spelling=/opt/compiler-explorer/clang-assertions-trunk-20240326/bin/../include/c++/v1/__config:871:39>: parsing namespace 'std'
3.	/opt/compiler-explorer/clang-assertions-trunk-20240326/bin/../include/c++/v1/__ranges/movable_box.h:30:1 <Spelling=/opt/compiler-explorer/clang-assertions-trunk-20240326/bin/../include/c++/v1/__config:872:39>: parsing namespace 'std::__1'
4.	/opt/compiler-explorer/clang-assertions-trunk-20240326/bin/../include/c++/v1/__ranges/movable_box.h:53:1: parsing namespace 'std::ranges'
 #0 0x00000000039246a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x39246a8)
 #1 0x000000000392238c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x392238c)
 #2 0x0000000003868c28 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f76fd442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f76fd4969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007f76fd442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007f76fd4287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007f76fd42871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007f76fd439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000000006d59d1a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d59d1a)
#10 0x0000000006d59d7d clang::Sema::SubstTemplateArguments(llvm::ArrayRef<clang::TemplateArgumentLoc>, clang::MultiLevelTemplateArgumentList const&, clang::TemplateArgumentListInfo&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d59d7d)
#11 0x00000000064721e3 substituteParameterMappings(clang::Sema&, clang::NormalizedConstraint&, clang::ConceptDecl*, clang::MultiLevelTemplateArgumentList const&, clang::ASTTemplateArgumentListInfo const*) SemaConcept.cpp:0:0
#12 0x0000000006472120 substituteParameterMappings(clang::Sema&, clang::NormalizedConstraint&, clang::ConceptDecl*, clang::MultiLevelTemplateArgumentList const&, clang::ASTTemplateArgumentListInfo const*) SemaConcept.cpp:0:0
#13 0x00000000064803fd clang::NormalizedConstraint::fromConstraintExpr(clang::Sema&, clang::NamedDecl*, clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x64803fd)
#14 0x00000000064802c1 clang::NormalizedConstraint::fromConstraintExpr(clang::Sema&, clang::NamedDecl*, clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x64802c1)
#15 0x0000000006480823 clang::NormalizedConstraint::fromConstraintExprs(clang::Sema&, clang::NamedDecl*, llvm::ArrayRef<clang::Expr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6480823)
#16 0x000000000647fb3f clang::Sema::getNormalizedAssociatedConstraints(clang::NamedDecl*, llvm::ArrayRef<clang::Expr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x647fb3f)
#17 0x000000000648033a clang::NormalizedConstraint::fromConstraintExpr(clang::Sema&, clang::NamedDecl*, clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x648033a)
#18 0x00000000064802c1 clang::NormalizedConstraint::fromConstraintExpr(clang::Sema&, clang::NamedDecl*, clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x64802c1)
#19 0x0000000006480823 clang::NormalizedConstraint::fromConstraintExprs(clang::Sema&, clang::NamedDecl*, llvm::ArrayRef<clang::Expr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6480823)
#20 0x000000000647fb3f clang::Sema::getNormalizedAssociatedConstraints(clang::NamedDecl*, llvm::ArrayRef<clang::Expr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x647fb3f)
#21 0x000000000648033a clang::NormalizedConstraint::fromConstraintExpr(clang::Sema&, clang::NamedDecl*, clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x648033a)
#22 0x0000000006480823 clang::NormalizedConstraint::fromConstraintExprs(clang::Sema&, clang::NamedDecl*, llvm::ArrayRef<clang::Expr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6480823)
#23 0x000000000647fb3f clang::Sema::getNormalizedAssociatedConstraints(clang::NamedDecl*, llvm::ArrayRef<clang::Expr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x647fb3f)
#24 0x0000000006482571 clang::Sema::MaybeEmitAmbiguousAtomicConstraintsDiagnostic(clang::NamedDecl*, llvm::ArrayRef<clang::Expr const*>, clang::NamedDecl*, llvm::ArrayRef<clang::Expr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6482571)
#25 0x0000000006bb31fd void checkTemplatePartialSpecialization<clang::ClassTemplatePartialSpecializationDecl>(clang::Sema&, clang::ClassTemplatePartialSpecializationDecl*) SemaTemplate.cpp:0:0
#26 0x0000000006c84877 clang::Sema::ActOnClassTemplateSpecialization(clang::Scope*, unsigned int, clang::Sema::TagUseKind, clang::SourceLocation, clang::SourceLocation, clang::CXXScopeSpec&, clang::TemplateIdAnnotation&, clang::ParsedAttributesView const&, llvm::MutableArrayRef<clang::TemplateParameterList*>, clang::Sema::SkipBodyInfo*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c84877)
#27 0x000000000622b2e0 clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x622b2e0)
#28 0x00000000062036b5 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62036b5)
#29 0x00000000062c09ea clang::Parser::ParseDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62c09ea)
#30 0x00000000062ce312 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (.part.0) ParseTemplate.cpp:0:0
#31 0x00000000062ce5d7 clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62ce5d7)
#32 0x000000000620a1d0 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x620a1d0)
#33 0x00000000061c651e clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x61c651e)
#34 0x0000000006221e64 clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6221e64)
#35 0x00000000062242fa clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62242fa)
#36 0x000000000620a202 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x620a202)
#37 0x00000000061c651e clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x61c651e)
#38 0x0000000006221e64 clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6221e64)
#39 0x00000000062242fa clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62242fa)
#40 0x000000000620a202 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x620a202)
#41 0x00000000061c651e clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x61c651e)
#42 0x0000000006221e64 clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6221e64)
#43 0x00000000062242fa clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62242fa)
#44 0x000000000620a202 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x620a202)
#45 0x00000000061c651e clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x61c651e)
#46 0x00000000061c739d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x61c739d)
#47 0x00000000061ba07a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x61ba07a)
#48 0x00000000041c0aa8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41c0aa8)
#49 0x0000000004440169 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4440169)
#50 0x00000000043c985e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43c985e)
#51 0x00000000045231ee clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45231ee)
#52 0x0000000000c296ec cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc296ec)
#53 0x0000000000c2297a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#54 0x0000000004203a19 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#55 0x00000000038690d4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x38690d4)
#56 0x000000000420400f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#57 0x00000000041ca3a5 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41ca3a5)
#58 0x00000000041cae0d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41cae0d)
#59 0x00000000041d2b75 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41d2b75)
#60 0x0000000000c26b85 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc26b85)
#61 0x0000000000b1d084 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xb1d084)
#62 0x00007f76fd429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#63 0x00007f76fd429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#64 0x0000000000c2246e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc2246e)

Metadata

Metadata

Assignees

Labels

clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partycrash-on-invalid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions