llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.11k stars 12.01k forks source link

crash during parsing of entangled alias template and variable template #25995

Closed tomilov closed 1 year ago

tomilov commented 8 years ago
Bugzilla Link 25621
Version trunk
OS Linux
Attachments soruce generated at crash

Extended Description

Crash caused by missing typename keyword before and {} or () or ::value after mentioning of a alias template in a definition of a variable template.

tomilov commented 8 years ago

Debug output:

​0 0x0000000000eb0788 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/local/bin/clang-3.8+0xeb0788)

​1 0x0000000000eaeb76 llvm::sys::RunSignalHandlers() (/usr/local/bin/clang-3.8+0xeaeb76)

​2 0x0000000000eb0fd9 SignalHandler(int) (/usr/local/bin/clang-3.8+0xeb0fd9)

​3 0x00002b7bb1a57340 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x10340)

​4 0x0000000001e5c4a3 clang::Sema::SubstituteExplicitTemplateArguments(clang::FunctionTemplateDecl, clang::TemplateArgumentListInfo&, llvm::SmallVectorImpl&, llvm::SmallVectorImpl&, clang::QualType, clang::sema::TemplateDeductionInfo&) (/usr/local/bin/clang-3.8+0x1e5c4a3)

​5 0x0000000001e63738 clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl, clang::TemplateArgumentListInfo, clang::QualType, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool) (/usr/local/bin/clang-3.8+0x1e63738)

​6 0x0000000001e64e7b clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl, clang::TemplateArgumentListInfo, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool) (/usr/local/bin/clang-3.8+0x1e64e7b)

​7 0x0000000001db1439 clang::Sema::ResolveSingleFunctionTemplateSpecialization(clang::OverloadExpr, bool, clang::DeclAccessPair) (/usr/local/bin/clang-3.8+0x1db1439)

​8 0x0000000001daf668 clang::Sema::ResolveAddressOfOverloadedFunction(clang::Expr, clang::QualType, bool, clang::DeclAccessPair&, bool) (/usr/local/bin/clang-3.8+0x1daf668)

​9 0x0000000001dc7a9c IsStandardConversion(clang::Sema&, clang::Expr*, clang::QualType, bool, clang::StandardConversionSequence&, bool, bool) (/usr/local/bin/clang-3.8+0x1dc7a9c)

​10 0x0000000001d94900 TryImplicitConversion(clang::Sema&, clang::Expr*, clang::QualType, bool, bool, bool, bool, bool, bool) (/usr/local/bin/clang-3.8+0x1d94900)

​11 0x0000000001d94890 clang::Sema::TryImplicitConversion(clang::Expr*, clang::QualType, bool, bool, bool, bool, bool) (/usr/local/bin/clang-3.8+0x1d94890)

​12 0x0000000001cfb3d8 clang::InitializationSequence::InitializeFrom(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, bool) (/usr/local/bin/clang-3.8+0x1cfb3d8)

​13 0x0000000001cfa8dc clang::InitializationSequence::InitializationSequence(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, bool) (/usr/local/bin/clang-3.8+0x1cfa8dc)

​14 0x0000000001b2d769 clang::Sema::AddInitializerToDecl(clang::Decl, clang::Expr, bool, bool) (/usr/local/bin/clang-3.8+0x1b2d769)

​15 0x0000000001ec048b clang::Sema::InstantiateVariableInitializer(clang::VarDecl, clang::VarDecl, clang::MultiLevelTemplateArgumentList const&) (/usr/local/bin/clang-3.8+0x1ec048b)

​16 0x0000000001ec12bc clang::Sema::InstantiateVariableDefinition(clang::SourceLocation, clang::VarDecl*, bool, bool) (/usr/local/bin/clang-3.8+0x1ec12bc)

​17 0x0000000001c57996 DoMarkVarDeclReferenced(clang::Sema&, clang::SourceLocation, clang::VarDecl, clang::Expr) (/usr/local/bin/clang-3.8+0x1c57996)

​18 0x0000000001c1c6bc clang::Sema::BuildDeclRefExpr(clang::ValueDecl, clang::QualType, clang::ExprValueKind, clang::DeclarationNameInfo const&, clang::CXXScopeSpec const, clang::NamedDecl, clang::TemplateArgumentListInfo const) (/usr/local/bin/clang-3.8+0x1c1c6bc)

​19 0x0000000001c2141b clang::Sema::BuildDeclarationNameExpr(clang::CXXScopeSpec const&, clang::DeclarationNameInfo const&, clang::NamedDecl, clang::NamedDecl, clang::TemplateArgumentListInfo const*, bool) (/usr/local/bin/clang-3.8+0x1c2141b)

​20 0x0000000001e18152 clang::Sema::BuildTemplateIdExpr(clang::CXXScopeSpec const&, clang::SourceLocation, clang::LookupResult&, bool, clang::TemplateArgumentListInfo const*) (/usr/local/bin/clang-3.8+0x1e18152)

​21 0x0000000001c1725d clang::Sema::ActOnIdExpression(clang::Scope, clang::CXXScopeSpec&, clang::SourceLocation, clang::UnqualifiedId&, bool, bool, std::__1::unique_ptr<clang::CorrectionCandidateCallback, std::__1::default_delete >, bool, clang::Token) (/usr/local/bin/clang-3.8+0x1c1725d)

​22 0x00000000018c5096 clang::Parser::tryParseCXXIdExpression(clang::CXXScopeSpec&, bool, clang::Token&) (/usr/local/bin/clang-3.8+0x18c5096)

​23 0x00000000018c610f clang::Parser::ParseCXXIdExpression(bool) (/usr/local/bin/clang-3.8+0x18c610f)

​24 0x00000000018b6664 clang::Parser::ParseCastExpression(bool, bool, bool&, clang::Parser::TypeCastState) (/usr/local/bin/clang-3.8+0x18b6664)

​25 0x00000000018b9dc6 clang::Parser::ParseCastExpression(bool, bool, bool&, clang::Parser::TypeCastState) (/usr/local/bin/clang-3.8+0x18b9dc6)

​26 0x00000000018b2897 clang::Parser::ParseRHSOfBinaryExpression(clang::ActionResult<clang::Expr*, true>, clang::prec::Level) (/usr/local/bin/clang-3.8+0x18b2897)

​27 0x00000000018b278b clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/usr/local/bin/clang-3.8+0x18b278b)

​28 0x00000000018bbb50 clang::Parser::ParseParenExpression(clang::Parser::ParenParseOption&, bool, bool, clang::OpaquePtr&, clang::SourceLocation&) (/usr/local/bin/clang-3.8+0x18bbb50)

​29 0x00000000018b59c5 clang::Parser::ParseCastExpression(bool, bool, bool&, clang::Parser::TypeCastState) (/usr/local/bin/clang-3.8+0x18b59c5)

​30 0x00000000018b271c clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/usr/local/bin/clang-3.8+0x18b271c)

​31 0x00000000018b2669 clang::Parser::ParseExpression(clang::Parser::TypeCastState) (/usr/local/bin/clang-3.8+0x18b2669)

​32 0x00000000018f5146 clang::Parser::ParseReturnStatement() (/usr/local/bin/clang-3.8+0x18f5146)

​33 0x00000000018f08a1 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt, 32u>&, bool, clang::SourceLocation, clang::Parser::ParsedAttributesWithRange&) (/usr/local/bin/clang-3.8+0x18f08a1)

​34 0x00000000018efb11 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt, 32u>&, bool, clang::SourceLocation) (/usr/local/bin/clang-3.8+0x18efb11)

​35 0x00000000018f6ee4 clang::Parser::ParseCompoundStatementBody(bool) (/usr/local/bin/clang-3.8+0x18f6ee4)

​36 0x00000000018f791e clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/usr/local/bin/clang-3.8+0x18f791e)

​37 0x000000000187f0ec clang::Parser::ParseLexedMethodDef(clang::Parser::LexedMethod&) (/usr/local/bin/clang-3.8+0x187f0ec)

​38 0x000000000187e1cd clang::Parser::ParseLexedMethodDefs(clang::Parser::ParsingClass&) (/usr/local/bin/clang-3.8+0x187e1cd)

​39 0x00000000018a848d clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::Parser::ParsedAttributesWithRange&, unsigned int, clang::Decl*) (/usr/local/bin/clang-3.8+0x18a848d)

​40 0x00000000018a61b1 clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::Parser::ParsedAttributesWithRange&) (/usr/local/bin/clang-3.8+0x18a61b1)

​41 0x000000000188977b clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*) (/usr/local/bin/clang-3.8+0x188977b)

​42 0x0000000001876400 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/usr/local/bin/clang-3.8+0x1876400)

​43 0x0000000001876133 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/usr/local/bin/clang-3.8+0x1876133)

​44 0x000000000187548d clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/usr/local/bin/clang-3.8+0x187548d)

​45 0x000000000189fcd0 clang::Parser::ParseInnerNamespace(std::1::vector<clang::SourceLocation, std::1::allocator >&, std::1::vector<clang::IdentifierInfo*, std::1::allocator<clang::IdentifierInfo*> >&, std::1::vector<clang::SourceLocation, std::1::allocator >&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) (/usr/local/bin/clang-3.8+0x189fcd0)

​46 0x000000000189f4dc clang::Parser::ParseNamespace(unsigned int, clang::SourceLocation&, clang::SourceLocation) (/usr/local/bin/clang-3.8+0x189f4dc)

​47 0x0000000001888b89 clang::Parser::ParseDeclaration(unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) (/usr/local/bin/clang-3.8+0x1888b89)

​48 0x0000000001874f2f clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/usr/local/bin/clang-3.8+0x1874f2f)

​49 0x000000000189fcd0 clang::Parser::ParseInnerNamespace(std::1::vector<clang::SourceLocation, std::1::allocator >&, std::1::vector<clang::IdentifierInfo*, std::1::allocator<clang::IdentifierInfo*> >&, std::1::vector<clang::SourceLocation, std::1::allocator >&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) (/usr/local/bin/clang-3.8+0x189fcd0)

​50 0x000000000189f4dc clang::Parser::ParseNamespace(unsigned int, clang::SourceLocation&, clang::SourceLocation) (/usr/local/bin/clang-3.8+0x189f4dc)

​51 0x0000000001888b89 clang::Parser::ParseDeclaration(unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) (/usr/local/bin/clang-3.8+0x1888b89)

​52 0x0000000001874f2f clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/usr/local/bin/clang-3.8+0x1874f2f)

​53 0x0000000001874735 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&) (/usr/local/bin/clang-3.8+0x1874735)

​54 0x0000000001870aba clang::ParseAST(clang::Sema&, bool, bool) (/usr/local/bin/clang-3.8+0x1870aba)

​55 0x0000000001292d18 clang::FrontendAction::Execute() (/usr/local/bin/clang-3.8+0x1292d18)

​56 0x0000000001261c88 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/local/bin/clang-3.8+0x1261c88)

​57 0x000000000130c854 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/local/bin/clang-3.8+0x130c854)

​58 0x00000000006d5bf9 cc1_main(llvm::ArrayRef<char const>, char const, void*) (/usr/local/bin/clang-3.8+0x6d5bf9)

​59 0x00000000006d23ea main (/usr/local/bin/clang-3.8+0x6d23ea)

​60 0x00002b7bb23bcec5 __libc_start_main /build/buildd/eglibc-2.19/csu/libc-start.c:321:0

​61 0x00000000006d18da _start (/usr/local/bin/clang-3.8+0x6d18da)

Stack dump:

  1. Program arguments: /usr/local/bin/clang-3.8 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name parser.cpp -mrelocation-model pic -pic-level 2 -pie-level 2 -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 -coverage-file /tmp/parser.o -resource-dir /usr/local/bin/../lib/clang/3.8.0 -D _DEBUG=1 -D DEBUG=1 -D _GLIBCXX_DEBUG=1 -D BOOST_RESULT_OF_USE_DECLTYPE=1 -D BOOST_SYSTEM_NO_DEPRECATED=1 -D BOOST_SPIRIT_X3_NO_RTTI=1 -D PAGESIZE=4096 -I . -I ../../../include -I /usr/local/Qt-5.4.1/mkspecs/linux-clang-libc++ -cxx-isystem /home/user/versatile/include -cxx-isystem /home/user/insituc/include -internal-isystem /usr/local/bin/../include/c++/v1 -internal-isystem /usr/local/include -internal-isystem /usr/local/bin/../lib/clang/3.8.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -W -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wunused-variable -pedantic -std=gnu++1z -fdeprecated-macro -fdebug-compilation-dir /home/user/insituc/src/tst/parser -ferror-limit 19 -ftemplate-backtrace-limit 0 -fmessage-length 0 -fdiagnostics-show-template-tree -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/parser.o -x c++ ../../insituc/parser/parser.cpp
  2. ../../../include/insituc/ast/ast.hpp:179:56: current parser token ')'
  3. ../../../include/insituc/ast/ast.hpp:16:1: parsing namespace 'insituc'
  4. ../../../include/insituc/ast/ast.hpp:18:1: parsing namespace 'ast'
  5. ../../../include/insituc/ast/ast.hpp:145:1: parsing struct/union/class body 'operand'
  6. ../../../include/insituc/ast/ast.hpp:178:5: parsing function body 'empty'
  7. ../../../include/insituc/ast/ast.hpp:178:5: in compound statement ('{}') clang-3.8: error: unable to execute command: Segmentation fault (core dumped) clang-3.8: error: clang frontend command failed due to signal (use -v to see invocation) clang version 3.8.0 (trunk 253951) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /usr/local/bin clang-3.8: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script. clang-3.8: note: diagnostic msg:

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang-3.8: note: diagnostic msg: /tmp/parser-fbcca9.cpp make[1]: Leaving directory `/home/user/insituc/src/tst/parser' clang-3.8: note: diagnostic msg: /tmp/parser-fbcca9.sh clang-3.8: note: diagnostic msg:


Endilll commented 1 year ago

Appears to be fixed in Clang 9: https://godbolt.org/z/Y6n8od8b3 Reduced by C-Reduce:

struct Trans_NS_versatile_variant {
  template < typename >
  using index =  int>
}
struct variant {
  using variant_type = Trans_NS_versatile_variant ;
  using size_type = variant_type:template < typename variant_type, typename >
  constexpr size_type index = variant_type::variant_type::index<>;
namespace ast {
  struct empty  
  struct statement : variant 
  int empty{index< statement, ast:empty >