Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

clang crashes due to infinite template recursion #23942

Open Quuxplusone opened 9 years ago

Quuxplusone commented 9 years ago
Bugzilla Link PR23943
Status NEW
Importance P normal
Reported by milleniumbug@protonmail.com
Reported on 2015-06-25 07:15:08 -0700
Last modified on 2015-06-29 16:30:51 -0700
Version 3.6
Hardware PC Windows NT
CC llvm-bugs@lists.llvm.org, rnk@google.com, yaron.keren@gmail.com
Fixed by commit(s)
Attachments trace.txt (2441 bytes, text/plain)
Blocks
Blocked by
See also
Created attachment 14517
the crash backtrace

Clang crashes when given a type dependent on infinite-recursive template as a
template parameter.

The code is not valid as it is, but the clang crashing was not the expected
reaction.

You can reproduce the issue by compiling the following code with Clang 3.6.1
(I'm using the build from MSYS2)

template<typename T>
struct Concat
{
    typedef int type;
};

template<typename T, T Count>
struct Iota
{
    typedef typename Concat<
        typename Iota<T, Count-1>::type
    >::type type;
};

Iota<int, 4>::type err;

int main() {}

The run script is as follows:

 "C:\\__MOJE\\prog\\MSYS2_Toolset64\\mingw64\\bin\\clang++.exe" "-cc1" "-triple" "x86_64-w64-windows-gnu" "-emit-obj" "-mrelax-all" "-disable-free" "-disable-llvm-verifier" "-main-file-name" "ice.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mthread-model" "posix" "-mdisable-fp-elim" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-target-cpu" "x86-64" "-target-linker-version" "2.25" "-dwarf-column-info" "-std=c++11" "-fdeprecated-macro" "-ferror-limit" "19" "-fmessage-length" "0" "-mstackrealign" "-fno-use-cxa-atexit" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-x" "c++" "ice-143b03.cpp"

The trace is in the attachment.

The clang++ -v output is:

clang version 3.6.1 (tags/RELEASE_361/final)
Target: x86_64-w64-windows-gnu
Thread model: posix
Quuxplusone commented 9 years ago

Attached trace.txt (2441 bytes, text/plain): the crash backtrace

Quuxplusone commented 9 years ago
It sounds like the msys 2 build of clang isn't overriding the stack depth. I
seem to remember we tweaked the CMake under VS to bump it up a bit.

FWIW, when I self-host clang on Windows I get the usual error:
$ clang -c t.cpp
t.cpp:4:36: fatal error: recursive template instantiation exceeded maximum
depth of 256
  typedef typename Concat<typename Iota<T, Count - 1>::type>::type type;
...