Bug 85148 - [6/7/8 Regression] ICE with NSDMI and this pointer
Summary: [6/7/8 Regression] ICE with NSDMI and this pointer
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0
: P2 normal
Target Milestone: 7.4
Assignee: Jason Merrill
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2018-03-31 21:50 UTC by Volker Reichelt
Modified: 2018-04-04 16:47 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-04-03 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2018-03-31 21:50:54 UTC
The following valid code snippet triggers an ICE since GCC 5.1.0
(it was wrongly rejected in GCC 4.9.4):

=====================================
template<typename T> struct A
{
  T x[1]{(__PTRDIFF_TYPE__)this};
};

void foo()
{
  A<A<__PTRDIFF_TYPE__>> a{};
}
=====================================

bug.cc: In function 'void foo()':
bug.cc:8:28: internal compiler error: in replace_placeholders_r, at cp/tree.c:3148
   A<A<__PTRDIFF_TYPE__>> a{};
                            ^
0x667871 replace_placeholders_r
	../../gcc/gcc/cp/tree.c:3148
0x116564b walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*))
	../../gcc/gcc/tree.c:11387
0x9d03b0 replace_placeholders_r
	../../gcc/gcc/cp/tree.c:3188
0x116564b walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*))
	../../gcc/gcc/tree.c:11387
0x9d03b0 replace_placeholders_r
	../../gcc/gcc/cp/tree.c:3188
0x116564b walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*))
	../../gcc/gcc/tree.c:11387
0x9d03b0 replace_placeholders_r
	../../gcc/gcc/cp/tree.c:3188
0x116564b walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*))
	../../gcc/gcc/tree.c:11387
0x9d03b0 replace_placeholders_r
	../../gcc/gcc/cp/tree.c:3188
0x116564b walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*))
	../../gcc/gcc/tree.c:11387
0x9d51d1 replace_placeholders(tree_node*, tree_node*, bool*)
	../../gcc/gcc/cp/tree.c:3226
0x9f4bb3 store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, int)
	../../gcc/gcc/cp/typeck2.c:851
0x887daa check_initializer
	../../gcc/gcc/cp/decl.c:6469
0x89ffdc cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int)
	../../gcc/gcc/cp/decl.c:7127
0x93c97b cp_parser_init_declarator
	../../gcc/gcc/cp/parser.c:19741
0x943e28 cp_parser_simple_declaration
	../../gcc/gcc/cp/parser.c:13059
0x944c38 cp_parser_block_declaration
	../../gcc/gcc/cp/parser.c:12884
0x945669 cp_parser_declaration_statement
	../../gcc/gcc/cp/parser.c:12478
0x923a73 cp_parser_statement
	../../gcc/gcc/cp/parser.c:10927
0x9249e0 cp_parser_statement_seq_opt
	../../gcc/gcc/cp/parser.c:11276
Please submit a full bug report, [etc.]
Comment 1 Jakub Jelinek 2018-04-03 07:07:49 UTC
I get ICE already with r185596 when -std=c++1y option has been introduced:
pr85148.C:1:29: internal compiler error: tree check: expected tree that contains ‘common’ structure, have ‘constructor’ in perform_member_init, at cp/init.c:661
Then starting with r210653 it is rejected:
pr85148.C: In function ‘void foo()’:
pr85148.C:8:28: error: could not convert ‘(long int)this’ from ‘long int’ to ‘A<long int>’
   A<A<__PTRDIFF_TYPE__>> a{};
                            ^
pr85148.C: In constructor ‘constexpr A<A<long int> >::A()’:
pr85148.C:1:29: error: could not convert ‘(long int)this’ from ‘long int’ to ‘A<long int>’
 template<typename T> struct A
                             ^
pr85148.C: In function ‘void foo()’:
pr85148.C:8:28: note: synthesized method ‘constexpr A<A<long int> >::A()’ first required here 
   A<A<__PTRDIFF_TYPE__>> a{};
                            ^
Then starting with r216750 it ICEs in tsubst_copy:
pr85148.C: In function ‘void foo()’:
pr85148.C:8:28: internal compiler error: in tsubst_copy, at cp/pt.c:12755
   A<A<__PTRDIFF_TYPE__>> a{};
                            ^
0x71171b tsubst_copy
	../../gcc/cp/pt.c:12755
0x720a9b tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	../../gcc/cp/pt.c:15464
and finally starting with r234442 in replace_placeholders.

It hasn't been fixed by the r258593 changes, seems the PLACEHOLDER_EXPR refers to the outer A when it should be refering to the inner A?  Or I'm totally confused on what exactly it should do.
Comment 2 Jason Merrill 2018-04-04 16:43:05 UTC
Author: jason
Date: Wed Apr  4 16:42:33 2018
New Revision: 259088

URL: https://gcc.gnu.org/viewcvs?rev=259088&root=gcc&view=rev
Log:
	PR c++/85148 - ICE with 'this' in array NSDMI.

	* tree.c (replace_placeholders_r): Use handled_component_p.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr11.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/tree.c
Comment 3 Jason Merrill 2018-04-04 16:46:26 UTC
Author: jason
Date: Wed Apr  4 16:45:53 2018
New Revision: 259093

URL: https://gcc.gnu.org/viewcvs?rev=259093&root=gcc&view=rev
Log:
	PR c++/85148 - ICE with 'this' in array NSDMI.

	* tree.c (replace_placeholders_r): Use handled_component_p.

Added:
    branches/gcc-7-branch/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr11.C
Modified:
    branches/gcc-7-branch/gcc/cp/ChangeLog
    branches/gcc-7-branch/gcc/cp/tree.c
Comment 4 Jason Merrill 2018-04-04 16:47:28 UTC
Fixed for 7.4; doesn't seem like a priority for GCC 6.