Bug 87513 - [8 Regression] ICE in write_expression, at cp/mangle.c:3050
Summary: [8 Regression] ICE in write_expression, at cp/mangle.c:3050
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.2.0
: P2 normal
Target Milestone: 8.4
Assignee: Jason Merrill
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2018-10-04 10:04 UTC by Alexander Sergeyev
Modified: 2020-02-24 19:41 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 7.2.0
Known to fail: 8.2.0, 9.0
Last reconfirmed: 2018-10-04 00:00:00


Attachments
preprocessed code sample (581.10 KB, application/x-bzip2)
2018-10-04 10:04 UTC, Alexander Sergeyev
Details
preprocessed code sample (gcc-7.3.0) (578.56 KB, application/x-bzip2)
2018-10-04 12:28 UTC, Alexander Sergeyev
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Sergeyev 2018-10-04 10:04:12 UTC
Created attachment 44780 [details]
preprocessed code sample

=== compiler and system information ===

$ g++-8.2.0 -v
Using built-in specs.
COLLECT_GCC=g++-8.2.0
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/8.2.0 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/8.2.0 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/8.2.0/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/8.2.0/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/include/g++-v8 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/8.2.0/python --enable-languages=c,c++,go,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --disable-nls --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 8.2.0-r3 p1.4' --disable-esp --enable-libstdcxx-time --disable-libstdcxx-pch --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --disable-multilib --with-multilib-list=m64 --disable-altivec --disable-fixed-point --enable-targets=all --enable-libgomp --disable-libmudflap --disable-libssp --disable-libmpx --disable-systemtap --enable-vtable-verify --enable-libvtv --enable-lto --without-isl --enable-libsanitizer --enable-default-pie --enable-default-ssp
Thread model: posix
gcc version 8.2.0 (Gentoo 8.2.0-r3 p1.4)


=== the complete command line that triggers the bug, the compiler output ===

$ g++-8.2.0 -std=c++14 -o /dev/null -c ice_sample_8.2.0.ii 
In file included from main.cc:2:
crow/app.h: In instantiation of 'typename std::result_of<decltype (& crow::Router::new_rule_tagged<Tag>)(crow::Router, std::__cxx11::basic_string<char>&&)>::type crow::Crow<Middlewares>::route(std::__cxx11::string&&) [with long unsigned int Tag = 0; Middlewares = {}]':
main.cc:8:1:   required from here
crow/app.h:63:14: internal compiler error: in write_expression, at cp/mangle.c:3050
         auto route(std::string&& rule)
              ^~~~~
0x59167a write_expression
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/cp/mangle.c:3050
0x65a9af write_expression
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/cp/mangle.c:3373
0x65876e write_type
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/cp/mangle.c:2352
0x659d1d write_bare_function_type
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/cp/mangle.c:2731
0x65d39b write_function_type
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/cp/mangle.c:2706
0x658244 write_type
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/cp/mangle.c:2214
0x65d58b write_template_args
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/cp/mangle.c:2841
0x65d8da write_prefix
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/cp/mangle.c:1146
0x6574ba write_nested_name
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/cp/mangle.c:1076
0x658680 write_type
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/cp/mangle.c:2232
0x659d1d write_bare_function_type
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/cp/mangle.c:2731
0x65dcf4 mangle_decl_string
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/cp/mangle.c:3795
0x65df28 get_mangled_id
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/cp/mangle.c:3817
0x65df28 mangle_decl(tree_node*)
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/cp/mangle.c:3855
0xdaaf99 decl_assembler_name(tree_node*)
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/tree.c:687
0x7e0fc5 symbol_table::insert_to_assembler_name_hash(symtab_node*, bool)
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/symtab.c:174
0x7e1924 symbol_table::symtab_initialize_asm_name_hash()
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/symtab.c:266
0x7e19b4 symbol_table::symtab_initialize_asm_name_hash()
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/symtab.c:976
0x7e19b4 symtab_node::get_for_asmname(tree_node const*)
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/symtab.c:964
0x7f1660 handle_alias_pairs
	/var/tmp/portage/sys-devel/gcc-8.2.0-r3/work/gcc-8.2.0/gcc/cgraphunit.c:1398


=== an (older) working version of the compiler ===
$ g++-7.3.0 -v
Using built-in specs.
COLLECT_GCC=g++-7.3.0
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-7.3.0-r3/work/gcc-7.3.0/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/7.3.0 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/7.3.0 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/7.3.0/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/7.3.0/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include/g++-v7 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/7.3.0/python --enable-languages=c,c++,go,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --disable-nls --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 7.3.0-r3 p1.4' --disable-esp --enable-libstdcxx-time --disable-libstdcxx-pch --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --disable-multilib --with-multilib-list=m64 --disable-altivec --disable-fixed-point --enable-targets=all --disable-libgcj --enable-libgomp --disable-libmudflap --disable-libssp --disable-libcilkrts --enable-libmpx --enable-vtable-verify --enable-libvtv --enable-lto --without-isl --enable-libsanitizer --enable-default-pie --enable-default-ssp
Thread model: posix
gcc version 7.3.0 (Gentoo 7.3.0-r3 p1.4)
Comment 1 Martin Liška 2018-10-04 12:20:09 UTC
Confirmed, I'm reducing that..
Comment 2 Martin Liška 2018-10-04 12:23:50 UTC
Started with r251438.
Can you please attach pre-processed source file created with GCC 7.3.x ?
Comment 3 Alexander Sergeyev 2018-10-04 12:28:33 UTC
Created attachment 44783 [details]
preprocessed code sample (gcc-7.3.0)
Comment 4 Martin Liška 2018-10-04 12:31:55 UTC
Thanks!
Comment 5 Alexander Sergeyev 2018-10-04 12:43:56 UTC
(In reply to Martin Liška from comment #4)
> Thanks!

No problems. Let me know if I could do anything else.
Comment 6 Martin Liška 2018-10-04 12:45:27 UTC
(In reply to Alexander Sergeyev from comment #5)
> (In reply to Martin Liška from comment #4)
> > Thanks!
> 
> No problems. Let me know if I could do anything else.

Now all you need to do is to be patient and wait for a fix ;)
Comment 7 Martin Liška 2018-10-04 13:40:35 UTC
Reduced test-case:

$ cat ice.ii
template < int a > struct b { static constexpr int c = a; };
template < typename > struct d;
template < typename > struct e;
template < typename f, typename g > struct e< f g::* > : b< d< f >::c > {};
template < typename h, typename... i > struct d< h(i...) > : b< true > {};
template < typename > class j;
struct k {
  typedef int l;
};
template < bool, bool, typename... > struct m;
template < typename ab, typename n, typename... o >
struct m< false, true, ab, n, o... > : k {};
template < typename ac, typename... i >
struct ad : m< b< false >::c, e< ac >::c, i... > {};
template < typename ac, typename... i >
struct j< ac(i...) > : ad< ac, i... > {};
class p {
public:
  p(char *);
};
class q {
public:
  template < long > void r();
};
class s {
public:
  template < long t >
  auto ae(p) -> typename j< decltype (&q::r< t >)(q, p) >::l;
};
using z = s;
void f() {
  z ag;
  ag.ae< 0 >("");
}
Comment 8 Jakub Jelinek 2018-11-21 15:37:31 UTC
Slightly adjusted testcase:
template <int N> struct A { static constexpr int c = N; };
template <typename> struct B;
template <typename> struct C;
template <typename T, typename U> struct C<T U::*> : A<B<T>::c> {};
template <typename T, typename... U> struct B<T (U...)> : A<true> {};
template <typename> class D;
struct E { typedef int l; };
template <bool, bool, typename...> struct F;
template <typename T, typename U, typename... V> struct F<false, true, T, U, V...> : E {};
template <typename T, typename... U> struct G : F<A<false>::c, C<T>::c, U...> {};
template <typename T, typename... U> struct D<T (U...)> : G<T, U...> {};
struct H { H (const char *); };
struct I { template <long> void foo (); };
struct J { template <long t> auto bar (H) -> typename D<decltype (&I::foo<t>) (I, H)>::l; };
void
foo ()
{
  J j;
  j.bar<0> ("");
}
Comment 9 ensadc 2018-12-26 07:25:26 UTC
struct A { template <long> void foo (); };
template <long t> auto bar () -> decltype (&A::foo<t>);
void foo ()
{
  bar<0> ();
}
Comment 10 Jason Merrill 2019-02-20 18:59:50 UTC
Author: jason
Date: Wed Feb 20 18:59:18 2019
New Revision: 269048

URL: https://gcc.gnu.org/viewcvs?rev=269048&root=gcc&view=rev
Log:
	PR c++/87513 - 'sorry' mangling PMF template-id.

Here build_offset_ref calls build_qualified_name to make a SCOPE_REF because
the dependent template arguments make type_dependent_expression_p (member)
true.  We could probably work hard to prevent this, but it doesn't seem
necessary, and it's easy to fix write_expression to handle the result.

	* mangle.c (write_expression): Handle SCOPE_REF to BASELINK.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/decltype-tid1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/mangle.c
Comment 11 Jason Merrill 2019-02-20 20:19:37 UTC
Fixed on trunk so far.
Comment 12 Jakub Jelinek 2019-02-22 15:20:01 UTC
GCC 8.3 has been released.
Comment 13 Jason Merrill 2019-03-08 18:21:33 UTC
Author: jason
Date: Fri Mar  8 18:21:02 2019
New Revision: 269502

URL: https://gcc.gnu.org/viewcvs?rev=269502&root=gcc&view=rev
Log:
	PR c++/87513 - 'sorry' mangling PMF template-id.

Here build_offset_ref calls build_qualified_name to make a SCOPE_REF because
the dependent template arguments make type_dependent_expression_p (member)
true.  We could probably work hard to prevent this, but it doesn't seem
necessary, and it's easy to fix write_expression to handle the result.

	* mangle.c (write_expression): Handle SCOPE_REF to BASELINK.

Added:
    branches/gcc-8-branch/gcc/testsuite/g++.dg/cpp0x/decltype-tid1.C
Modified:
    branches/gcc-8-branch/gcc/cp/ChangeLog
    branches/gcc-8-branch/gcc/cp/mangle.c
Comment 14 Jason Merrill 2020-02-24 19:41:59 UTC
Fixed for 8.4.