public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/80095, ICE with this pointer in NSDMI
@ 2017-03-29 17:08 Marek Polacek
  2017-03-29 19:11 ` Jason Merrill
  0 siblings, 1 reply; 5+ messages in thread
From: Marek Polacek @ 2017-03-29 17:08 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

Here we have a reference initialization with NSDMI and *this.  We are crashing
because a PLACEHOLDER_EXPR crept into the gimplifier.

This happens since r218653 where set_up_extended_ref_temp was changed to
use split_nonconstant_init.  As a consequence, cp_gimplify_init_expr might
now be receiving 

  D.2051.p = (void *) &<PLACEHOLDER_EXPR struct A>

instead of 

  D.2051 = {.p = (void *) &<PLACEHOLDER_EXPR struct A>}

where the RHS was a CONSTRUCTOR.  It no longer is, so replace_placeholders is
not called anymore.  It occurred to me that we should use the same check as in
store_init_value (i.e. check that the object to be used in the substitution is
a class), but given what split_nonconstant_init might produce, handle
COMPONENT_REFs specially.

Bootstrapped/regtested on x86_64-linux, ok for trunk and 6?

2017-03-29  Marek Polacek  <polacek@redhat.com>

	PR c++/80095 - ICE with this pointer in NSDMI.
	* cp-gimplify.c (cp_gimplify_init_expr): Call replace_placeholders
	when TO is a class.

	* g++.dg/cpp1y/nsdmi-aggr8.C: New test.

diff --git gcc/cp/cp-gimplify.c gcc/cp/cp-gimplify.c
index 354ae1a..e530daf 100644
--- gcc/cp/cp-gimplify.c
+++ gcc/cp/cp-gimplify.c
@@ -496,7 +496,16 @@ cp_gimplify_init_expr (tree *expr_p)
 	    TREE_TYPE (from) = void_type_node;
 	}
 
-      if (cxx_dialect >= cxx14 && TREE_CODE (sub) == CONSTRUCTOR)
+      /* split_nonconstant_init might've produced something like
+	 D.2051.p = (void *) &<PLACEHOLDER_EXPR struct A>
+	 in which case we want to substitute the placeholder with
+	 D.2051.  */
+      tree op0 = to;
+      while (TREE_CODE (op0) == COMPONENT_REF)
+	op0 = TREE_OPERAND (op0, 0);
+      tree type = TREE_TYPE (op0);
+
+      if (cxx_dialect >= cxx14 && CLASS_TYPE_P (strip_array_types (type)))
 	/* Handle aggregate NSDMI.  */
 	replace_placeholders (sub, to);
 
diff --git gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr8.C gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr8.C
index e69de29..8c99ffb 100644
--- gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr8.C
+++ gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr8.C
@@ -0,0 +1,16 @@
+// PR c++/80095
+// { dg-do compile { target c++14 } }
+
+struct A
+{
+  void* p = this;
+};
+
+void
+foo ()
+{
+  const A& a = A{};
+  A&& a2 = A{};
+  const A& a3{};
+  A&& a4{};
+}

	Marek

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-04-07 17:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-29 17:08 C++ PATCH for c++/80095, ICE with this pointer in NSDMI Marek Polacek
2017-03-29 19:11 ` Jason Merrill
2017-03-29 21:51   ` Marek Polacek
2017-04-05  9:49     ` Marek Polacek
2017-04-07 17:03       ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).