Open llvmbot opened 7 years ago
I can reproduce with svn head
To prove its not my system, I set up a github repository with the test case: https://github.com/toastedcrumpets/clang-bug-34134
I then use Travis CI to build the test case on a range of fresh clang installs: https://travis-ci.org/toastedcrumpets/clang-bug-34134/builds/263262653
clang 3.6, 3.7, 3.8, 3.9, all fail with the correct template recursion error. clang 4.0 displays the segfault. clang 5.0 fails to install so no result there (issue with travis)
Yeah the code has "issues" and is not valid C++, but the segfault is still invalid behaviour.
I've tested on Ubuntu 16.04 and 17.04, using packages of clang++-4.0 from http://apt.llvm.org/ and both installs segfault. I have a segfault with clang++-5.0 as well (see below).
There's nothing "unusual" about my system configuration and I constantly compile plenty of code using clang without issues so its not systemic.
Stack dump:
For me, it doesn't segfault, but simply complains about the recursive template exceeding the maximum instantiation depth:
$ clang-4.0.0 -std=c++11 -c test-63a412.cpp test.cpp:8:50: fatal error: recursive template instantiation exceeded maximum depth of 1024 auto operator=(const T& a) -> decltype(this = A(a)) { return this = A(a); } ^ test.cpp:8:48: note: while substituting deduced template arguments into function template 'operator=' [with T = A] auto operator=(const T& a) -> decltype(this = A(a)) { return this = A(a); } ^ test.cpp:8:48: note: while substituting deduced template arguments into function template 'operator=' [with T = A] test.cpp:8:48: note: while substituting deduced template arguments into function template 'operator=' [with T = A] test.cpp:8:48: note: while substituting deduced template arguments into function template 'operator=' [with T = A] test.cpp:8:48: note: while substituting deduced template arguments into function template 'operator=' [with T = A] test.cpp:8:48: note: (skipping 1015 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all) test.cpp:8:48: note: while substituting deduced template arguments into function template 'operator=' [with T = A] test.cpp:8:48: note: while substituting deduced template arguments into function template 'operator=' [with T = A] test.cpp:8:48: note: while substituting deduced template arguments into function template 'operator=' [with T = A] test.cpp:8:48: note: while substituting deduced template arguments into function template 'operator=' [with T = A] test.cpp:8:71: note: while substituting deduced template arguments into function template 'operator=' [with T = A] auto operator=(const T& a) -> decltype(this = A(a)) { return this = A(a); } ^ 1 error generated.
This does not crash but results in stack exhaustion when substituting deduced template arguments, godbolt: https://godbolt.org/z/vaW83868W
@llvm/issue-subscribers-clang-frontend
Extended Description
The code below causes a segfault on clang++-4.0 on Ubuntu.
Crash trace
0 0x00007fecb96339a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/lib/x86_64-linux-gnu/libLLVM-4.0.so.1+0x70e9a8)
1 0x00007fecb9631b2e llvm::sys::RunSignalHandlers() (/usr/lib/x86_64-linux-gnu/libLLVM-4.0.so.1+0x70cb2e)
2 0x00007fecb9631c7c (/usr/lib/x86_64-linux-gnu/libLLVM-4.0.so.1+0x70cc7c)
3 0x00007fecbbe7d390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
4 0x0000000000f279e3 (/usr/lib/llvm-4.0/bin/clang+0xf279e3)
5 0x0000000000f2b800 (/usr/lib/llvm-4.0/bin/clang+0xf2b800)
6 0x0000000000f2cdb2 (/usr/lib/llvm-4.0/bin/clang+0xf2cdb2)
7 0x0000000000f2d126 clang::Sema::BuildCXXFunctionalCastExpr(clang::TypeSourceInfo, clang::SourceLocation, clang::Expr, clang::SourceLocation) (/usr/lib/llvm-4.0/bin/clang+0xf2d126)
8 0x00000000010f86d4 clang::Sema::BuildCXXTypeConstructExpr(clang::TypeSourceInfo, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr>, clang::SourceLocation) (/usr/lib/llvm-4.0/bin/clang+0x10f86d4)
9 0x00000000012e6304 (/usr/lib/llvm-4.0/bin/clang+0x12e6304)
10 0x00000000012e3ad8 (/usr/lib/llvm-4.0/bin/clang+0x12e3ad8)
11 0x00000000012f3b37 (/usr/lib/llvm-4.0/bin/clang+0x12f3b37)
12 0x00000000012e3a4c (/usr/lib/llvm-4.0/bin/clang+0x12e3a4c)
13 0x00000000012f52a9 (/usr/lib/llvm-4.0/bin/clang+0x12f52a9)
14 0x00000000012e38d9 (/usr/lib/llvm-4.0/bin/clang+0x12e38d9)
15 0x00000000012f3443 (/usr/lib/llvm-4.0/bin/clang+0x12f3443)
16 0x00000000012e3aa6 (/usr/lib/llvm-4.0/bin/clang+0x12e3aa6)
17 0x00000000012dbd91 (/usr/lib/llvm-4.0/bin/clang+0x12dbd91)
18 0x00000000012e1324 clang::Sema::SubstFunctionDeclType(clang::TypeSourceInfo, clang::MultiLevelTemplateArgumentList const&, clang::SourceLocation, clang::DeclarationName, clang::CXXRecordDecl, unsigned int) (/usr/lib/llvm-4.0/bin/clang+0x12e1324)
19 0x0000000001300998 clang::TemplateDeclInstantiator::VisitDecl(clang::Decl*) (/usr/lib/llvm-4.0/bin/clang+0x1300998)
Stack dump: