Bug 79796 - [5 Regression] ICE with NSDMI and this pointer
Summary: [5 Regression] ICE with NSDMI and this pointer
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P2 normal
Target Milestone: 5.5
Assignee: Marek Polacek
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2017-03-01 22:13 UTC by Volker Reichelt
Modified: 2017-03-07 17:44 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.8.0, 4.9.0
Known to fail: 5.1.0, 6.1.0, 7.0.1
Last reconfirmed: 2017-03-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2017-03-01 22:13:36 UTC
The following valid code snippet (compiled with -std=c++1y) triggers
an ICE since GCC 5.1.0:

=====================
struct A
{
  A* p = this;
};

void foo()
{
  A a;
  a = A({});
}
=====================

bug.cc: In function 'void foo()':
bug.cc:9:5: internal compiler error: in gimplify_expr, at gimplify.c:11950
   a = A({});
   ~~^~~~~~~
0xaeacfc gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gcc/gimplify.c:11950
0xae80e0 gimplify_addr_expr
        ../../gcc/gcc/gimplify.c:5859
0xae80e0 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gcc/gimplify.c:11238
0xaf17c0 gimplify_init_ctor_preeval
        ../../gcc/gcc/gimplify.c:4241
0xaf1778 gimplify_init_ctor_preeval
        ../../gcc/gcc/gimplify.c:4227
0xaf225c gimplify_init_constructor
        ../../gcc/gcc/gimplify.c:4796
0xaf3096 gimplify_modify_expr_rhs
        ../../gcc/gcc/gimplify.c:5082
0xaf9dd0 gimplify_modify_expr
        ../../gcc/gcc/gimplify.c:5417
0xae897c gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gcc/gimplify.c:11191
0xaeb8d8 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gcc/gimplify.c:6478
0xae7a7a gimplify_cleanup_point_expr
        ../../gcc/gcc/gimplify.c:6230
0xae7a7a gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gcc/gimplify.c:11567
0xaeb8d8 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gcc/gimplify.c:6478
0xae71cb gimplify_statement_list
        ../../gcc/gcc/gimplify.c:1716
0xae71cb gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gcc/gimplify.c:11619
0xaeb8d8 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gcc/gimplify.c:6478
0xaec9a8 gimplify_bind_expr
        ../../gcc/gcc/gimplify.c:1290
0xae7b7a gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gcc/gimplify.c:11391
0xaeb8d8 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gcc/gimplify.c:6478
0xaed911 gimplify_body(tree_node*, bool)
        ../../gcc/gcc/gimplify.c:12388
Please submit a full bug report, [etc.]
Comment 1 Marek Polacek 2017-03-01 22:30:27 UTC
Confirmed.
Comment 2 Marek Polacek 2017-03-01 22:32:47 UTC
Started with r216750.
Comment 3 Marek Polacek 2017-03-03 11:16:18 UTC
gimplify_expr can't stomach <PLACEHOLDER_EXPR struct A> created in get_nsdmi.  Wait, there's a dup or at least a very similar PR.
Comment 4 Marek Polacek 2017-03-03 11:28:46 UTC
That was PR77659 which has been fixed on the trunk.
Comment 5 Marek Polacek 2017-03-03 14:18:41 UTC
Surprisingly my naïve attempt to fix this works:

--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -8047,6 +8047,8 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
    {
      arg = cp_build_indirect_ref (arg, RO_NULL, complain);
      val = build2 (MODIFY_EXPR, TREE_TYPE (to), to, arg);
+     if (cxx_dialect >= cxx14)
+       replace_placeholders (arg, to);
    }
       else
    {


and the C++ testsuite passes.
Comment 6 Marek Polacek 2017-03-06 17:39:14 UTC
Author: mpolacek
Date: Mon Mar  6 17:38:42 2017
New Revision: 245927

URL: https://gcc.gnu.org/viewcvs?rev=245927&root=gcc&view=rev
Log:
	PR c++/79796 - ICE with NSDMI and this pointer
	* call.c (build_over_call): Handle NSDMI with a 'this' by calling
	replace_placeholders.

	* g++.dg/cpp0x/nsdmi13.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/nsdmi13.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/testsuite/ChangeLog
Comment 7 Marek Polacek 2017-03-06 17:39:39 UTC
Fixed on the trunk so far.
Comment 8 Marek Polacek 2017-03-07 17:43:01 UTC
Author: mpolacek
Date: Tue Mar  7 17:42:30 2017
New Revision: 245957

URL: https://gcc.gnu.org/viewcvs?rev=245957&root=gcc&view=rev
Log:
	PR c++/79796 - ICE with NSDMI and this pointer
	* call.c (build_over_call): Handle NSDMI with a 'this' by calling
	replace_placeholders.

	* g++.dg/cpp0x/nsdmi13.C: New test.

Added:
    branches/gcc-6-branch/gcc/testsuite/g++.dg/cpp0x/nsdmi13.C
Modified:
    branches/gcc-6-branch/gcc/cp/ChangeLog
    branches/gcc-6-branch/gcc/cp/call.c
    branches/gcc-6-branch/gcc/testsuite/ChangeLog
Comment 9 Marek Polacek 2017-03-07 17:44:55 UTC
Fixed in GCC 6 too.