Skip to content

Clang crashes on variable template instantiated with a member of a template class #65153

@oliora

Description

@oliora

clang version 16.0.0 (https://github.com/llvm/llvm-project.git 08d094a)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-16.0.0/bin

Log and the crash backtrace:

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-16.0.0/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-12.2.0 -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 <source>
1.	<source>:55:67: current parser token ';'
2.	<source>:40:1: parsing struct/union/class body 'Builder'
 #0 0x000055ed179d48df llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x3ba18df)
 #1 0x000055ed179d290c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x3b9f90c)
 #2 0x000055ed17925518 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007fc08950c420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x000055ed1a94d2e9 clang::Sema::SubstituteExplicitTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo&, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, llvm::SmallVectorImpl<clang::QualType>&, clang::QualType*, clang::sema::TemplateDeductionInfo&) (.constprop.0) SemaTemplateDeduction.cpp:0:0
 #5 0x000055ed1a94dd75 void llvm::function_ref<void ()>::callback_fn<clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, clang::QualType, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool)::'lambda'()>(long) SemaTemplateDeduction.cpp:0:0
 #6 0x000055ed1a041eb5 clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x620eeb5)
 #7 0x000055ed1a98a059 clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, clang::QualType, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x6b57059)
 #8 0x000055ed1a98a6cb clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x6b576cb)
 #9 0x000055ed1a7a79aa clang::Sema::ResolveSingleFunctionTemplateSpecialization(clang::OverloadExpr*, bool, clang::DeclAccessPair*) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x69749aa)
#10 0x000055ed1a98b52f ResolveOverloadForDeduction(clang::Sema&, clang::TemplateParameterList*, clang::Expr*, clang::QualType, bool) SemaTemplateDeduction.cpp:0:0
#11 0x000055ed1a98bcde DeduceTemplateArgumentsFromCallArgument(clang::Sema&, clang::TemplateParameterList*, unsigned int, clang::QualType, clang::Expr*, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, llvm::SmallVectorImpl<clang::Sema::OriginalCallArg>&, bool, unsigned int, unsigned int) SemaTemplateDeduction.cpp:0:0
#12 0x000055ed1a98ccad clang::Sema::DeduceAutoType(clang::TypeLoc, clang::Expr*, clang::QualType&, clang::sema::TemplateDeductionInfo&, bool, bool) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x6b59cad)
#13 0x000055ed1a215087 clang::Sema::deduceVarTypeFromInitializer(clang::VarDecl*, clang::DeclarationName, clang::QualType, clang::TypeSourceInfo*, clang::SourceRange, bool, clang::Expr*) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x63e2087)
#14 0x000055ed1a22a93f clang::Sema::DeduceVariableDeclarationType(clang::VarDecl*, bool, clang::Expr*) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x63f793f)
#15 0x000055ed1a253eed clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x6420eed)
#16 0x000055ed19f47bc9 clang::Parser::ParseCXXClassMemberDeclaration(clang::AccessSpecifier, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject*) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x6114bc9)
#17 0x000055ed19f48db4 clang::Parser::ParseCXXClassMemberDeclarationWithPragmas(clang::AccessSpecifier&, clang::ParsedAttributes&, clang::TypeSpecifierType, clang::Decl*) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x6115db4)
#18 0x000055ed19f49453 clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributes&, unsigned int, clang::Decl*) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x6116453)
#19 0x000055ed19f4b7fe 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-16.0.0/bin/clang+++0x61187fe)
#20 0x000055ed19f1c01e clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x60e901e)
#21 0x000055ed19ff42b7 clang::Parser::ParseSingleDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x61c12b7)
#22 0x000055ed19ffcc5d clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x61c9c5d)
#23 0x000055ed19ffcf43 clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x61c9f43)
#24 0x000055ed19f28d0f clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x60f5d0f)
#25 0x000055ed19ef88a5 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x60c58a5)
#26 0x000055ed19efa72d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x60c772d)
#27 0x000055ed19ee9a8a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x60b6a8a)
#28 0x000055ed18cc4865 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x4e91865)
#29 0x000055ed185a0671 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x476d671)
#30 0x000055ed18524993 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x46f1993)
#31 0x000055ed18684b3b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x4851b3b)
#32 0x000055ed151ad41c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x137a41c)
#33 0x000055ed151a8bdc ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#34 0x000055ed18385ce9 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
#35 0x000055ed17925977 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x3af2977)
#36 0x000055ed18385f1c 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
#37 0x000055ed1834e3fc clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x451b3fc)
#38 0x000055ed1834eded clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x451bded)
#39 0x000055ed1835923c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x452623c)
#40 0x000055ed151ab523 clang_main(int, char**) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x1378523)
#41 0x00007fc088fba083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#42 0x000055ed151a4d1e _start (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x1371d1e)
clang-16: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139

Minimal code:

#include <string_view>
#include <array>

template <const std::string_view&... Strs>
struct Join {
    static constexpr auto impl() noexcept {
        // Logic does not matter
        std::array<char, (Strs.size() + ... + 0)> arr{};
        return arr;
    }
    static constexpr auto arr = impl();
    static constexpr std::string_view value{ arr.data(), arr.size() - 1 };
};

template <const std::string_view&... Strs>
constexpr std::string_view JoinStringViews = details::Join<Strs...>::value;

static constexpr std::string_view LengthValue = "12345678";

enum class Version { v1, v2 };

template <Version V>
class Builder {
public:
    static constexpr std::string_view Equal = "=";
    
    // Crash is happening for this line
    // No crash without passing a template member `Equal`
    static constexpr auto Val = JoinStringViews<Equal, LengthValue>;

    // Note that the following line compiles just fine
    // static constexpr auto Val = Join<Equal, LengthValue>::value;
};

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions