[llvm-bugs] [Bug 28656] New: clang crashes on C++ code with bad template class object declaration: Assertion `Recent->isInjectedClassName() && Recent->getPreviousDecl()' failed

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jul 21 17:05:14 PDT 2016


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

            Bug ID: 28656
           Summary: clang crashes on C++ code with bad template class
                    object declaration: Assertion
                    `Recent->isInjectedClassName() &&
                    Recent->getPreviousDecl()' failed
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          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 current clang trunk crashes when compiling the following C++ test case on
x86_64-linux-gnu in both 32-bit and 64-bit modes. 

It is a regression from 3.8.x, which properly rejects the code.


$ clang++ -v
clang version 4.0.0 (trunk 276243)
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.3
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.3
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.1.1
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 small.cpp
small.cpp:3:19: error: template specialization requires 'template<>'
struct A < int >::A; // should be, e.g.: struct A < int >::A a;
       ~~~~~~~~~  ^
template<> 
small.cpp:3:19: error: specialization of member 'A<int>::A' does not specialize
an instantiated member
small.cpp:1:30: note: attempt to specialize declaration here
template < typename > struct A {};
                             ^
clang-4.0:
/tmp/llvm-builder/llvm-source-trunk/tools/clang/include/clang/AST/DeclTemplate.h:1608:
clang::ClassTemplateSpecializationDecl*
clang::ClassTemplateSpecializationDecl::getMostRecentDecl(): Assertion
`Recent->isInjectedClassName() && Recent->getPreviousDecl()' failed.
#0 0x0000000001d96685 llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/usr/local/clang-trunk/bin/clang-4.0+0x1d96685)
#1 0x0000000001d9473e llvm::sys::RunSignalHandlers()
(/usr/local/clang-trunk/bin/clang-4.0+0x1d9473e)
#2 0x0000000001d948a0 SignalHandler(int)
(/usr/local/clang-trunk/bin/clang-4.0+0x1d948a0)
#3 0x00007fe21d3a1340 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x10340)
#4 0x00007fe21c192cc9 gsignal
/build/eglibc-3GlaMS/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
#5 0x00007fe21c1960d8 abort
/build/eglibc-3GlaMS/eglibc-2.19/stdlib/abort.c:91:0
#6 0x00007fe21c18bb86 __assert_fail_base
/build/eglibc-3GlaMS/eglibc-2.19/assert/assert.c:92:0
#7 0x00007fe21c18bc32 (/lib/x86_64-linux-gnu/libc.so.6+0x2fc32)
#8 0x0000000002e3deae
clang::ClassTemplateSpecializationDecl::getMostRecentDecl()
(/usr/local/clang-trunk/bin/clang-4.0+0x2e3deae)
#9 0x0000000003374c3f
clang::ClassTemplateDecl::findSpecialization(llvm::ArrayRef<clang::TemplateArgument>,
void*&) (/usr/local/clang-trunk/bin/clang-4.0+0x3374c3f)
#10 0x0000000002e3b06d clang::Sema::CheckTemplateIdType(clang::TemplateName,
clang::SourceLocation, clang::TemplateArgumentListInfo&)
(/usr/local/clang-trunk/bin/clang-4.0+0x2e3b06d)
#11 0x0000000002e3c546
clang::Sema::ActOnTagTemplateIdType(clang::Sema::TagUseKind,
clang::TypeSpecifierType, clang::SourceLocation, clang::CXXScopeSpec&,
clang::SourceLocation, clang::OpaquePtr<clang::TemplateName>,
clang::SourceLocation, clang::SourceLocation,
llvm::MutableArrayRef<clang::ParsedTemplateArgument>, clang::SourceLocation)
(/usr/local/clang-trunk/bin/clang-4.0+0x2e3c546)
#12 0x00000000028d15df
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/clang-trunk/bin/clang-4.0+0x28d15df)
#13 0x00000000028b3038
clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&,
clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier,
clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*)
(/usr/local/clang-trunk/bin/clang-4.0+0x28b3038)
#14 0x0000000002897ac4
clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec&, clang::AccessSpecifier)
(/usr/local/clang-trunk/bin/clang-4.0+0x2897ac4)
#15 0x0000000002898221
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*, clang::AccessSpecifier) [clone .part.222]
(/usr/local/clang-trunk/bin/clang-4.0+0x2898221)
#16 0x000000000289825f
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*, clang::AccessSpecifier)
(/usr/local/clang-trunk/bin/clang-4.0+0x289825f)
#17 0x000000000289d0a0
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*) (/usr/local/clang-trunk/bin/clang-4.0+0x289d0a0)
#18 0x000000000289d870
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&)
(/usr/local/clang-trunk/bin/clang-4.0+0x289d870)
#19 0x0000000002894e8b clang::ParseAST(clang::Sema&, bool, bool)
(/usr/local/clang-trunk/bin/clang-4.0+0x2894e8b)
#20 0x000000000252b8fe clang::CodeGenAction::ExecuteAction()
(/usr/local/clang-trunk/bin/clang-4.0+0x252b8fe)
#21 0x0000000002236efe clang::FrontendAction::Execute()
(/usr/local/clang-trunk/bin/clang-4.0+0x2236efe)
#22 0x000000000220c6f6
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/usr/local/clang-trunk/bin/clang-4.0+0x220c6f6)
#23 0x00000000022c4572
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/usr/local/clang-trunk/bin/clang-4.0+0x22c4572)
#24 0x0000000000b1cb88 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/usr/local/clang-trunk/bin/clang-4.0+0xb1cb88)
#25 0x0000000000acb577 main (/usr/local/clang-trunk/bin/clang-4.0+0xacb577)
#26 0x00007fe21c17dec5 __libc_start_main
/build/eglibc-3GlaMS/eglibc-2.19/csu/libc-start.c:321:0
#27 0x0000000000b18bb4 _start (/usr/local/clang-trunk/bin/clang-4.0+0xb18bb4)
Stack dump:
0.      Program arguments: /usr/local/clang-trunk/bin/clang-4.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-file /data2/small.cpp -resource-dir
/usr/local/clang-trunk/bin/../lib/clang/4.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/4.0.0/include -internal-externc-isystem
/usr/include/x86_64-linux-gnu -internal-externc-isystem /include
-internal-externc-isystem /usr/include -fdeprecated-macro
-fdebug-compilation-dir /data2 -ferror-limit 19 -fmessage-length 255
-fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option
-fcolor-diagnostics -o small.o -x c++ small.cpp
1.      small.cpp:4:18: current parser token 'b'
clang-4.0: error: unable to execute command: Aborted (core dumped)
clang-4.0: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 4.0.0 (trunk 276243)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/clang-trunk/bin
clang-4.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-4.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-4.0: note: diagnostic msg: /tmp/small-28b7f3.cpp
clang-4.0: note: diagnostic msg: /tmp/small-28b7f3.sh
clang-4.0: note: diagnostic msg:

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


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


template < typename > struct A {};

struct A < int >::A; // should be, e.g.: struct A < int >::A a;
struct A < int > b;

-- 
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/20160722/c595a580/attachment-0001.html>


More information about the llvm-bugs mailing list