[llvm-bugs] [Bug 31874] New: clang crashes on (likely) valid C++11 code on x86_64-linux-gnu: Assertion `Spec->getTemplateSpecializationKind() == TSK_ExplicitSpecialization' failed

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Feb 5 18:32:51 PST 2017


https://llvm.org/bugs/show_bug.cgi?id=31874

            Bug ID: 31874
           Summary: clang crashes on (likely) valid C++11 code on
                    x86_64-linux-gnu: Assertion
                    `Spec->getTemplateSpecializationKind() ==
                    TSK_ExplicitSpecialization' failed
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: su at cs.ucdavis.edu
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

The code also crashes at least 3.5.x and later. 

Interestingly, if we move 

    enum A < int >::E e;

immediately before 

    static_assert (A < int >().f () == 0, "error");

the code compiles fine. 


$ clang++ -v
clang version 5.0.0 (trunk 294096)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/clang-trunk/bin
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9.4
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/5.3.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7.3
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.3.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.2.0
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
$
$ clang++ -c -std=c++11 small.cpp
clang-5.0:
/tmp/llvm-builder/llvm-source-trunk/tools/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:5039:
clang::NamedDecl* clang::Sema::FindInstantiatedDecl(clang::SourceLocation,
clang::NamedDecl*, const clang::MultiLevelTemplateArgumentList&): Assertion
`Spec->getTemplateSpecializationKind() == TSK_ExplicitSpecialization' failed.
#0 0x000000000207897a llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/usr/local/clang-trunk/bin/clang-5.0+0x207897a)
#1 0x0000000002076aae llvm::sys::RunSignalHandlers()
(/usr/local/clang-trunk/bin/clang-5.0+0x2076aae)
#2 0x0000000002076c10 SignalHandler(int)
(/usr/local/clang-trunk/bin/clang-5.0+0x2076c10)
#3 0x00007f76c5e10330 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
#4 0x00007f76c4bfcc37 gsignal
/build/eglibc-oGUzwX/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
#5 0x00007f76c4c00028 abort
/build/eglibc-oGUzwX/eglibc-2.19/stdlib/abort.c:91:0
#6 0x00007f76c4bf5bf6 __assert_fail_base
/build/eglibc-oGUzwX/eglibc-2.19/assert/assert.c:92:0
#7 0x00007f76c4bf5ca2 (/lib/x86_64-linux-gnu/libc.so.6+0x2fca2)
#8 0x0000000003310960 clang::Sema::FindInstantiatedDecl(clang::SourceLocation,
clang::NamedDecl*, clang::MultiLevelTemplateArgumentList const&)
(/usr/local/clang-trunk/bin/clang-5.0+0x3310960)
#9 0x00000000032cd961 (anonymous
namespace)::TemplateInstantiator::TransformDecl(clang::SourceLocation,
clang::Decl*) (/usr/local/clang-trunk/bin/clang-5.0+0x32cd961)
#10 0x00000000032f2d3d clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformDeclRefExpr(clang::DeclRefExpr*)
(/usr/local/clang-trunk/bin/clang-5.0+0x32f2d3d)
#11 0x00000000032d9c66 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*)
(/usr/local/clang-trunk/bin/clang-5.0+0x32d9c66)
#12 0x00000000032db2f0 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformInitializer(clang::Expr*, bool)
(/usr/local/clang-trunk/bin/clang-5.0+0x32db2f0)
#13 0x00000000032db581 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformReturnStmt(clang::ReturnStmt*)
(/usr/local/clang-trunk/bin/clang-5.0+0x32db581)
#14 0x00000000032f9f15 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*)
(/usr/local/clang-trunk/bin/clang-5.0+0x32f9f15)
#15 0x00000000032fb7a4 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*,
bool) (/usr/local/clang-trunk/bin/clang-5.0+0x32fb7a4)
#16 0x00000000032fb8db clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*)
(/usr/local/clang-trunk/bin/clang-5.0+0x32fb8db)
#17 0x00000000032fa383 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*)
(/usr/local/clang-trunk/bin/clang-5.0+0x32fa383)
#18 0x00000000032ff5d8 clang::Sema::SubstStmt(clang::Stmt*,
clang::MultiLevelTemplateArgumentList const&)
(/usr/local/clang-trunk/bin/clang-5.0+0x32ff5d8)
#19 0x0000000003318c28
clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation,
clang::FunctionDecl*, bool, bool, bool)
(/usr/local/clang-trunk/bin/clang-5.0+0x3318c28)
#20 0x000000000306e3fb
clang::Sema::MarkFunctionReferenced(clang::SourceLocation,
clang::FunctionDecl*, bool) (/usr/local/clang-trunk/bin/clang-5.0+0x306e3fb)
#21 0x000000000306fbed MarkExprReferenced(clang::Sema&, clang::SourceLocation,
clang::Decl*, clang::Expr*, bool)
(/usr/local/clang-trunk/bin/clang-5.0+0x306fbed)
#22 0x000000000306fe29 clang::Sema::MarkMemberReferenced(clang::MemberExpr*)
(/usr/local/clang-trunk/bin/clang-5.0+0x306fe29)
#23 0x00000000030f5010 BuildMemberExpr(clang::Sema&, clang::ASTContext&,
clang::Expr*, bool, clang::SourceLocation, clang::CXXScopeSpec const&,
clang::SourceLocation, clang::ValueDecl*, clang::DeclAccessPair,
clang::DeclarationNameInfo const&, clang::QualType, clang::ExprValueKind,
clang::ExprObjectKind, clang::TemplateArgumentListInfo const*) [clone
.constprop.597] (/usr/local/clang-trunk/bin/clang-5.0+0x30f5010)
#24 0x00000000030fc183 clang::Sema::BuildMemberReferenceExpr(clang::Expr*,
clang::QualType, clang::SourceLocation, bool, clang::CXXScopeSpec const&,
clang::SourceLocation, clang::NamedDecl*, clang::LookupResult&,
clang::TemplateArgumentListInfo const*, clang::Scope const*, bool,
clang::Sema::ActOnMemberAccessExtraArgs*)
(/usr/local/clang-trunk/bin/clang-5.0+0x30fc183)
#25 0x00000000030fc7fc clang::Sema::BuildMemberReferenceExpr(clang::Expr*,
clang::QualType, clang::SourceLocation, bool, clang::CXXScopeSpec&,
clang::SourceLocation, clang::NamedDecl*, clang::DeclarationNameInfo const&,
clang::TemplateArgumentListInfo const*, clang::Scope const*,
clang::Sema::ActOnMemberAccessExtraArgs*)
(/usr/local/clang-trunk/bin/clang-5.0+0x30fc7fc)
#26 0x00000000030fcaed clang::Sema::ActOnMemberAccessExpr(clang::Scope*,
clang::Expr*, clang::SourceLocation, clang::tok::TokenKind,
clang::CXXScopeSpec&, clang::SourceLocation, clang::UnqualifiedId&,
clang::Decl*) (/usr/local/clang-trunk/bin/clang-5.0+0x30fcaed)
#27 0x0000000002cc9c54
clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*,
true>) (/usr/local/clang-trunk/bin/clang-5.0+0x2cc9c54)
#28 0x0000000002cc48c8 clang::Parser::ParseCastExpression(bool, bool, bool&,
clang::Parser::TypeCastState) (/usr/local/clang-trunk/bin/clang-5.0+0x2cc48c8)
#29 0x0000000002cc738d clang::Parser::ParseCastExpression(bool, bool,
clang::Parser::TypeCastState) (/usr/local/clang-trunk/bin/clang-5.0+0x2cc738d)
#30 0x0000000002cc534f clang::Parser::ParseCastExpression(bool, bool, bool&,
clang::Parser::TypeCastState) (/usr/local/clang-trunk/bin/clang-5.0+0x2cc534f)
#31 0x0000000002cc738d clang::Parser::ParseCastExpression(bool, bool,
clang::Parser::TypeCastState) (/usr/local/clang-trunk/bin/clang-5.0+0x2cc738d)
#32 0x0000000002ccb6ce
clang::Parser::ParseConstantExpression(clang::Parser::TypeCastState)
(/usr/local/clang-trunk/bin/clang-5.0+0x2ccb6ce)
#33 0x0000000002cb3aff
clang::Parser::ParseStaticAssertDeclaration(clang::SourceLocation&)
(/usr/local/clang-trunk/bin/clang-5.0+0x2cb3aff)
#34 0x0000000002cabb08 clang::Parser::ParseDeclaration(unsigned int,
clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&)
(/usr/local/clang-trunk/bin/clang-5.0+0x2cabb08)
#35 0x0000000002c88f4a
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*) (/usr/local/clang-trunk/bin/clang-5.0+0x2c88f4a)
#36 0x0000000002c89992
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&)
(/usr/local/clang-trunk/bin/clang-5.0+0x2c89992)
#37 0x0000000002c80e43 clang::ParseAST(clang::Sema&, bool, bool)
(/usr/local/clang-trunk/bin/clang-5.0+0x2c80e43)
#38 0x00000000028a340a clang::CodeGenAction::ExecuteAction()
(/usr/local/clang-trunk/bin/clang-5.0+0x28a340a)
#39 0x000000000256267e clang::FrontendAction::Execute()
(/usr/local/clang-trunk/bin/clang-5.0+0x256267e)
#40 0x000000000253916e
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/usr/local/clang-trunk/bin/clang-5.0+0x253916e)
#41 0x00000000025f7482
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/usr/local/clang-trunk/bin/clang-5.0+0x25f7482)
#42 0x0000000000c2c0c8 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/usr/local/clang-trunk/bin/clang-5.0+0xc2c0c8)
#43 0x0000000000bc9dc5 main (/usr/local/clang-trunk/bin/clang-5.0+0xbc9dc5)
#44 0x00007f76c4be7f45 __libc_start_main
/build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:321:0
#45 0x0000000000c27d69 _start (/usr/local/clang-trunk/bin/clang-5.0+0xc27d69)
Stack dump:
0.      Program arguments: /usr/local/clang-trunk/bin/clang-5.0 -cc1 -triple
x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name
small.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim
-fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables
-fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb
-coverage-notes-file /data2/small.gcno -resource-dir
/usr/local/clang-trunk/bin/../lib/clang/5.0.0 -internal-isystem
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9 -internal-isystem
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/x86_64-linux-gnu/c++/4.9
-internal-isystem
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/x86_64-linux-gnu/c++/4.9
-internal-isystem
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/backward
-internal-isystem /usr/local/include -internal-isystem
/usr/local/clang-trunk/bin/../lib/clang/5.0.0/include -internal-externc-isystem
/usr/include/x86_64-linux-gnu -internal-externc-isystem /include
-internal-externc-isystem /usr/include -std=c++11 -fdeprecated-macro
-fdebug-compilation-dir /data2 -ferror-limit 19 -fmessage-length 164
-fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option
-fcolor-diagnostics -o small.o -x c++ small.cpp
1.      small.cpp:12:30: current parser token '('
2.      small.cpp:4:17: instantiating function definition 'A<int>::f'
clang-5.0: error: unable to execute command: Aborted (core dumped)
clang-5.0: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 5.0.0 (trunk 294096)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/clang-trunk/bin
clang-5.0: 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-5.0: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-5.0: note: diagnostic msg: /tmp/small-35c1ba.cpp
clang-5.0: note: diagnostic msg: /tmp/small-35c1ba.sh
clang-5.0: note: diagnostic msg:

********************
$


-----------------------------------------------------


template < typename T > struct A
{ 
  enum E : int;
  constexpr int f () const;
};

enum A < int >::E e;

template < typename T > enum A < T >::E : int { R };
template < typename T > constexpr int A < T >::f () const { return R; }

static_assert (A < int >().f () == 0, "error");

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170206/769c359f/attachment-0001.html>


More information about the llvm-bugs mailing list