llvm / llvm-project

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

crash on invalid c++ code on x86_64-linux-gnu (segmentation fault, c++ template) #29807

Open chengniansun opened 8 years ago

chengniansun commented 8 years ago
Bugzilla Link 30459
Version trunk
OS Windows NT
CC @DougGregor

Extended Description

$ clang-trunk -v
clang version 4.0.0 (trunk 281908) (llvm/trunk 281907)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/5
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/5.3.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8.5
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9.3
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0
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.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
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
$ clang-trunk small.C
small.C:2:31: fatal error: recursive template instantiation exceeded maximum depth of 1024
template <class> struct A { C<A<A>::x> c; };                                       
                              ^                                                    
#&#8203;0 0x0000000001c9e155 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/local/clang-trunk/bin/clang-4.0+0x1c9e155)
#&#8203;1 0x0000000001c9c0fe llvm::sys::RunSignalHandlers() (/usr/local/clang-trunk/bin/clang-4.0+0x1c9c0fe)
#&#8203;2 0x0000000001c9c262 SignalHandler(int) (/usr/local/clang-trunk/bin/clang-4.0+0x1c9c262)
#&#8203;3 0x00007f955e429340 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x10340)
#&#8203;4 0x00000000032c6004 clang::TemplateArgument::print(clang::PrintingPolicy const&, llvm::raw_ostream&) const (/usr/local/clang-trunk/bin/clang-4.0+0x32c6004)
#&#8203;5 0x00000000032df63f clang::TemplateSpecializationType::PrintTemplateArgumentList(llvm::raw_ostream&, llvm::ArrayRef<clang::TemplateArgument>, clang::PrintingPolicy const&, bool) (/usr/local/clang-trunk/bin/clang-4.0+0x32df63f)
#&#8203;6 0x00000000032e05a0 (anonymous namespace)::TypePrinter::printTag(clang::TagDecl*, llvm::raw_ostream&) (/usr/local/clang-trunk/bin/clang-4.0+0x32e05a0)
#&#8203;7 0x00000000032e3011 (anonymous namespace)::TypePrinter::printBefore(clang::Type const*, clang::Qualifiers, llvm::raw_ostream&) (/usr/local/clang-trunk/bin/clang-4.0+0x32e3011)
#&#8203;8 0x00000000032e1da7 (anonymous namespace)::TypePrinter::print(clang::Type const*, clang::Qualifiers, llvm::raw_ostream&, llvm::StringRef) (/usr/local/clang-trunk/bin/clang-4.0+0x32e1da7)
#&#8203;9 0x00000000032e1ec1 clang::QualType::print(clang::Type const*, clang::Qualifiers, llvm::raw_ostream&, clang::PrintingPolicy const&, llvm::Twine const&, unsigned int) (/usr/local/clang-trunk/bin/clang-4.0+0x32e1ec1)
#&#8203;10 0x00000000032c6009 clang::TemplateArgument::print(clang::PrintingPolicy const&, llvm::raw_ostream&) const (/usr/local/clang-trunk/bin/clang-4.0+0x32c6009)
#&#8203;11 0x00000000032df63f clang::TemplateSpecializationType::PrintTemplateArgumentList(llvm::raw_ostream&, llvm::ArrayRef<clang::TemplateArgument>, clang::PrintingPolicy const&, bool) (/usr/local/clang-trunk/bin/clang-4.0+0x32df63f)
#&#8203;12 0x00000000032e05a0 (anonymous namespace)::TypePrinter::printTag(clang::TagDecl*, llvm::raw_ostream&) (/usr/local/clang-trunk/bin/clang-4.0+0x32e05a0)
#&#8203;13 0x00000000032e3011 (anonymous namespace)::TypePrinter::printBefore(clang::Type const*, clang::Qualifiers, llvm::raw_ostream&) (/usr/local/clang-trunk/bin/clang-4.0+0x32e3011)
#&#8203;14 0x00000000032e1da7 (anonymous namespace)::TypePrinter::print(clang::Type const*, clang::Qualifiers, llvm::raw_ostream&, llvm::StringRef) (/usr/local/clang-trunk/bin/clang-4.0+0x32e1da7)
#&#8203;15 0x00000000032e1ec1 clang::QualType::print(clang::Type const*, clang::Qualifiers, llvm::raw_ostream&, clang::PrintingPolicy const&, llvm::Twine const&, unsigned int) (/usr/local/clang-trunk/bin/clang-4.0+0x32e1ec1)
#&#8203;16 0x00000000032c6009 clang::TemplateArgument::print(clang::PrintingPolicy const&, llvm::raw_ostream&) const (/usr/local/clang-trunk/bin/clang-4.0+0x32c6009)
#&#8203;17 0x00000000032df63f clang::TemplateSpecializationType::PrintTemplateArgumentList(llvm::raw_ostream&, llvm::ArrayRef<clang::TemplateArgument>, clang::PrintingPolicy const&, bool) (/usr/local/clang-trunk/bin/clang-4.0+0x32df63f)
#&#8203;18 0x00000000032e05a0 (anonymous namespace)::TypePrinter::printTag(clang::TagDecl*, llvm::raw_ostream&) (/usr/local/clang-trunk/bin/clang-4.0+0x32e05a0)
........................................
189.    small.C:2:25: instantiating class definition 'A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<int> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >'
190.    small.C:2:25: instantiating class definition 'A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<int> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >'
191.    small.C:2:25: instantiating class definition 'A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<int> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >'
192.    small.C:2:25: instantiating class definition 'A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<int> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >'
193.    small.C:2:25: instantiating class definition 'A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<int> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >'
194.    small.C:2:25: instantiating class definition 'A<clang-4.0: error: unable to execute command: Segmentation fault (core dumped)
clang-4.0: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 4.0.0 (trunk 281908) (llvm/trunk 281907)                          
Target: x86_64-unknown-linux-gnu                                                
Thread model: posix                                                             
InstalledDir: /usr/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-ae7b98.cpp                          
clang-4.0: note: diagnostic msg: /tmp/small-ae7b98.sh                           
clang-4.0: note: diagnostic msg:                                                

********************                
$ cat small.C
template <int> struct C;
template <class> struct A { C<A<A>::x> c; };
A<int> a;
wheatman commented 1 year ago

This crash still occurs on post 16 trunk(ba7cc56782dbf4a26c0a043dd33c7949366e2b0d) https://godbolt.org/z/nerc7aK1x

The code is

// compile with -O1 -std=c++11
template <int> struct C;
template <class> struct A { C<A<A>::x> c; };
A<int> a;

the output is

<source>:2:31: fatal error: recursive template instantiation exceeded maximum depth of 1024
    2 | template <class> struct A { C<A<A>::x> c; };
      |                               ^
Program terminated with signal: SIGSEGV
Compiler returned: 139
llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-frontend

tonyelewis commented 8 months ago

I've also hit this one, with:

template <typename a = int> struct b : b<b<b<b<a>>>> {};
b<> c;

(Which emerged from a creduce of (what I suspect to be) a different bug)

Testing on Godbolt confirms what @wheatman said: Clang 16.0.0 rejected the code without crashing (and GCC does to). But 17.0.1 and trunk crash.

Endilll commented 8 months ago

Regression in 17 confirmed: https://godbolt.org/z/Kc3Eobb6P