https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120185

            Bug ID: 120185
           Summary: [16 Regression] ncc-3.11 ICE since
                    r16-479-gabab79397ef97a in
                    type_has_converting_constructor
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: slyfox at gcc dot gnu.org
  Target Milestone: ---

Today's gcc SIGSEGVs when compiling nss-3.11. Bisected down to
r16-479-gabab79397ef97a

commit abab79397ef97acf7c689c43e27d58d8d7d5c599
Author: Jason Merrill <ja...@redhat.com>
Date:   Sat May 3 09:30:01 2025 -0400

    c++: adjust PR99599/CWG2369 workaround

Mildly reduced example:

$ cat pk11_cbc_unittest.cc.cc
template <unsigned long...> struct IndexSequence {
  using type = IndexSequence;
};
template <typename, unsigned long> struct DoubleSequence;
template <unsigned long... I, unsigned long sizeofT>
struct DoubleSequence<IndexSequence<I...>, sizeofT> {
  using type = IndexSequence<1, sizeofT>;
};
template <int N>
struct MakeIndexSequenceImpl
    : DoubleSequence<typename MakeIndexSequenceImpl<N / 2>::type, 2> {};
template <> struct MakeIndexSequenceImpl<0> : IndexSequence<> {};
template <long N>
using MakeIndexSequence = typename MakeIndexSequenceImpl<N>::type;
template <int> struct Ignore {
  Ignore(...);
};
template <typename> struct ElemFromListImpl;
template <unsigned long... I> struct ElemFromListImpl<IndexSequence<I...>> {
  template <typename R> static void Apply(Ignore<I>..., R);
};
template <int N, typename... T> struct ElemFromList {
  using type =
      decltype(ElemFromListImpl<typename MakeIndexSequence<N>::type>::Apply(
          static_cast<T *>(nullptr)...));
};
template <typename...> class FlatTuple;
template <typename, typename> struct FlatTupleBase;
template <unsigned long... Idx, typename... T>
struct FlatTupleBase<FlatTuple<T...>, IndexSequence<Idx...>> {
  template <long I> typename ElemFromList<I, T...>::type Get();
  template <typename F> auto Apply() -> decltype(F(Get<Idx>()...));
};
template <typename... T>
struct FlatTuple
    : FlatTupleBase<FlatTuple<T...>,
                    typename MakeIndexSequence<sizeof...(T)>::type> {};
template <typename... Ts> struct ValueArray {
  FlatTuple<Ts...> v_;
};
void gtest_EncryptDecryptPkcs11CbcPadTest_EvalGenerateName_() {
  ValueArray<long, long, long> __trans_tmp_1;
}

Crashing:

gcc/xg++ -B gcc -c -O0 -std=c++11 -c pk11_cbc_unittest.cc.cc
pk11_cbc_unittest.cc.cc: In instantiation of ‘struct ElemFromList<2, long int,
long int, long int>’:
pk11_cbc_unittest.cc.cc:31:58:   required by substitution of ‘template<long int
I> typename ElemFromList<I, long int, long int, long int>::type
FlatTupleBase<FlatTuple<long int, long int, long int>, IndexSequence<1, 2>
>::Get() [with long int I = 2]’
   31 |   template <long I> typename ElemFromList<I, T...>::type Get();
      |                                                          ^~~
pk11_cbc_unittest.cc.cc:32:60:   required from ‘struct
FlatTupleBase<FlatTuple<long int, long int, long int>, IndexSequence<1, 2> >’
   32 |   template <typename F> auto Apply() -> decltype(F(Get<Idx>()...));
      |                                                    ~~~~~~~~^~
pk11_cbc_unittest.cc.cc:35:8:   required from ‘struct FlatTuple<long int, long
int, long int>’
   35 | struct FlatTuple
      |        ^~~~~~~~~
pk11_cbc_unittest.cc.cc:39:20:   required from ‘struct ValueArray<long int,
long int, long int>’
   39 |   FlatTuple<Ts...> v_;
      |                    ^~
pk11_cbc_unittest.cc.cc:42:32:   required from here
   42 |   ValueArray<long, long, long> __trans_tmp_1;
      |                                ^~~~~~~~~~~~~
pk11_cbc_unittest.cc.cc:24:76: internal compiler error: Segmentation fault
   24 |       decltype(ElemFromListImpl<typename
MakeIndexSequence<N>::type>::Apply(
      |               
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
   25 |           static_cast<T *>(nullptr)...));
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0x294b485 diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
        ???:0
0x2963a35 internal_error(char const*, ...)
        ???:0
0x12f95b7 crash_signal(int)
        ???:0
0x85e85c type_has_converting_constructor(tree_node*)
        ???:0
0xabe076 check_non_deducible_conversions(tree_node*, tree_node* const*,
unsigned int, tree_node*, unification_kind_t, int, conversion**, bool, bool)
        ???:0
0xb23e5e fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node*
const*, unsigned int, tree_node*, unification_kind_t, int, conversion**, bool,
bool)
        ???:0
0x83f9c7 add_template_candidate_real(z_candidate**, tree_node*, tree_node*,
tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed> const*, tree_node*,
tree_node*, tree_node*, int, tree_node*, unification_kind_t, bool, int)
        ???:0
0x841301 add_candidates(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed> const*, tree_node*, tree_node*, bool, tree_node*, tree_node*, int,
z_candidate**, int)
        ???:0
0x82e692 build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, tree_node*, int, tree_node**, int)
        ???:0
0xb59202 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
        ???:0
0xaeba38 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xae582b tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xafb86b tsubst_decl(tree_node*, tree_node*, int, bool)
        ???:0
0xae2aee tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xb2b282 instantiate_class_template(tree_node*)
        ???:0
0xb9b7b7 complete_type(tree_node*)
        ???:0
0xb9ba7f complete_type_or_maybe_complain(tree_node*, tree_node*, int)
        ???:0
0xae53c5 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xb02412 tsubst_function_type(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xae31c1 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0


gcc/xg++ -B gcc -v
Reading specs from gcc/specs
COLLECT_GCC=gcc/xg++
COLLECT_LTO_WRAPPER=gcc/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /home/slyfox/dev/git/gcc/configure --disable-multilib
--disable-bootstrap --disable-lto --disable-libsanitizer
--disable-libstdcxx-pch --enable-languages=c,c++ --disable-libgomp
--disable-libquadmath --disable-libvtv CFLAGS='-O1 -g0' CXXFLAGS='-O1 -g0'
LDFLAGS='-O1 -g0'
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 16.0.0 20250509 (experimental) (GCC)

Reply via email to