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

            Bug ID: 80805
           Summary: ICE in sufficiently complex code with -g
                    (dump_aggr_type)
           Product: gcc
           Version: 7.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ed at catmur dot co.uk
  Target Milestone: ---

The following program crashes gcc versions 5.1 to recent trunk (20170517 on
godbolt.org) when compiled with -std=c++11 -g (the -g seems to be essential):

template<class T> struct R { using type = T; };
template<class F> F r(typename R<F>::type f) { return f; }
template<class F> void s(F) {}
template<bool, class F> void t(F f) { s(r<F>(f)); }
template<bool> struct S {};
template<class> struct P { constexpr static bool value = false; };
template<class D>
void g()
{
    constexpr static bool H = P<D>::value;
    using X = S<H>;
    []() -> X
    {
        t<false>([]{});
        return X{};
    }();
}
int main() { g<int>(); }

I haven't been able to reduce the test case any further - almost any change to
the above avoids the crash - although it's possible I'm stuck on a local
minimum.

Valgrind shows:

==22516== Memcheck, a memory error detector
==22516== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==22516== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==22516== Command:
/usr/local/gcc-7.1.0/libexec/gcc/x86_64-pc-linux-gnu/7.1.0/cc1plus -quiet
-D_GNU_SOURCE x.cpp -quiet -dumpbase x.cpp -mtune=generic -march=x86-64
-auxbase x -g -std=c++11 -o /tmp/ccxmO5KA.s
==22516== 
==22516== Invalid read of size 8
==22516==    at 0x627FDF: tsubst_decl(tree_node*, tree_node*, int)
(hash-table.h:875)
==22516==    by 0x6162C8: tsubst_copy(tree_node*, tree_node*, int, tree_node*)
[clone .part.192] (pt.c:14590)
==22516==    by 0x620076: tsubst_copy_and_build(tree_node*, tree_node*, int,
tree_node*, bool, bool) [clone .part.194] (pt.c:14433)
==22516==    by 0x61F7A1: tsubst_copy_and_build(tree_node*, tree_node*, int,
tree_node*, bool, bool) [clone .part.194] (pt.c:16710)
==22516==    by 0x613F97: tsubst_expr(tree_node*, tree_node*, int, tree_node*,
bool) [clone .part.187] (pt.c:16468)
==22516==    by 0x6180C0: tsubst_template_arg(tree_node*, tree_node*, int,
tree_node*) (pt.c:10805)
==22516==    by 0x619D52: tsubst_template_args(tree_node*, tree_node*, int,
tree_node*) (pt.c:11697)
==22516==    by 0x626B7C: tsubst_aggr_type(tree_node*, tree_node*, int,
tree_node*, int) (pt.c:11899)
==22516==    by 0x616F48: tsubst(tree_node*, tree_node*, int, tree_node*)
(pt.c:13405)
==22516==    by 0x6518F2: dump_substitution(cxx_pretty_printer*, tree_node*,
tree_node*, tree_node*, int) [clone .part.53] (error.c:353)
==22516==    by 0x654059: dump_scope(cxx_pretty_printer*, tree_node*, int)
(error.c:153)
==22516==    by 0x653573: dump_aggr_type(cxx_pretty_printer*, tree_node*, int)
(error.c:666)
==22516==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
==22516== 
==22516== 
==22516== Process terminating with default action of signal 11 (SIGSEGV)
==22516==  General Protection Fault
==22516==    at 0x6B88E9: lookup_member(tree_node*, tree_node*, int, bool, int)
(search.c:1291)
==22516==    by 0x708503: lambda_function(tree_node*) (lambda.c:205)
==22516==    by 0x6533C4: dump_aggr_type(cxx_pretty_printer*, tree_node*, int)
(error.c:692)
==22516==    by 0x651FA0: dump_function_decl(cxx_pretty_printer*, tree_node*,
int) (error.c:1508)
==22516==    by 0x654059: dump_scope(cxx_pretty_printer*, tree_node*, int)
(error.c:153)
==22516==    by 0x653573: dump_aggr_type(cxx_pretty_printer*, tree_node*, int)
(error.c:666)
==22516==    by 0x6530D5: dump_template_parms(cxx_pretty_printer*, tree_node*,
int, int) (error.c:1870)
==22516==    by 0x657351: cp_printer(pretty_printer*, text_info*, char const*,
int, bool, bool, bool) (error.c:3033)
==22516==    by 0x11F0942: pp_format(pretty_printer*, text_info*)
(pretty-print.c:679)
==22516==    by 0x11F11B0: pp_format_verbatim(pretty_printer*, text_info*)
(pretty-print.c:738)
==22516==    by 0x11F1284: pp_verbatim(pretty_printer*, char const*, ...)
(pretty-print.c:939)
==22516==    by 0x6509F5: print_instantiation_full_context(diagnostic_context*)
(error.c:3388)
==22516== 

When compiled without -g, the program compiles without warning (at -O3 -Wall
-Wextra) and appears to run fine. Clang, icc and MSVC are happy with it.

Reply via email to