Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Segfault on template instantiation depth overflow #12563

Open Quuxplusone opened 12 years ago

Quuxplusone commented 12 years ago
Bugzilla Link PR12458
Status NEW
Importance P normal
Reported by llvm-bugs@quasiparticle.net
Reported on 2012-04-04 03:05:48 -0700
Last modified on 2015-10-31 05:34:35 -0700
Version 3.6
Hardware PC All
CC bisqwit@iki.fi, dgregor@apple.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments brainfuck.cpp (1382 bytes, text/x-c++src)
Blocks
Blocked by
See also

clang++ dies with a segfault when decomposing template types nested deeper than the maximum template instantiation depth. A test program to trigger this is attached.

Quuxplusone commented 12 years ago

Attached brainfuck.cpp (1382 bytes, text/x-c++src): Example program

Quuxplusone commented 9 years ago
This bug still exists.

Clang crashes when attempting to compile this (preprocessed) code with options:
-std=c++11 -ftemplate-depth=2000

  template<unsigned... _Indexes>
    struct _Index_tuple
    {
      typedef _Index_tuple<_Indexes..., sizeof...(_Indexes)> __next;
    };
  template<unsigned _Num>
    struct _Build_index_tuple
    {
      typedef typename _Build_index_tuple<_Num - 1>::__type::__next __type;
    };
  template<>
    struct _Build_index_tuple<0>
    {
      typedef _Index_tuple<> __type;
    };
  template<typename _Tp, _Tp... _Idx>
    struct integer_sequence
    {
      typedef _Tp value_type;
      static constexpr unsigned size() { return sizeof...(_Idx); }
    };
  template<typename _Tp, _Tp _Num,
           typename _ISeq = typename _Build_index_tuple<_Num>::__type>
    struct _Make_integer_sequence;
  template<typename _Tp, _Tp _Num,  unsigned... _Idx>
    struct _Make_integer_sequence<_Tp, _Num, _Index_tuple<_Idx...>>
    {
      typedef integer_sequence<_Tp, static_cast<_Tp>(_Idx)...> __type;
    };
  template<typename _Tp, _Tp _Num>
    using make_integer_sequence
      = typename _Make_integer_sequence<_Tp, _Num>::__type;
  template<unsigned... _Idx>
    using index_sequence = integer_sequence<unsigned, _Idx...>;
  template<unsigned _Num>
    using make_index_sequence = make_integer_sequence<unsigned, _Num>;

  auto t = make_index_sequence<2000>();

Causes a segmentation fault.
Tested on Clang 3.5 and Clang 3.6 on x86_64 Linux.

The above code is from libstdc++ (which is why it contains underscored names)
with integer_sequence from C++14, but is compilable as C++11. The equivalent
code from libc++ does not trigger the template instantation depth problem.
Quuxplusone commented 9 years ago

However, unlike my testcase (which is essentially a duplicate of PR23815 and PR23685), attachment 8328 shows that the bug that does not require the use of -ftemplate-depth to happen.