]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/82159 (ICE: in assign_temp, at function.c:961)
authorJakub Jelinek <jakub@redhat.com>
Mon, 25 Jun 2018 16:43:16 +0000 (18:43 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 25 Jun 2018 16:43:16 +0000 (18:43 +0200)
Backported from mainline
2017-09-27  Jakub Jelinek  <jakub@redhat.com>

PR c++/82159
* gimplify.c (gimplify_modify_expr): Don't optimize away zero sized
lhs from calls if the lhs has addressable type.

* g++.dg/opt/pr82159.C: New test.

From-SVN: r262026

gcc/ChangeLog
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/pr82159.C [new file with mode: 0644]

index 3ec50a873c001f95b072cc1b9c827f513af94fce..62309f352e26fe3c601dbf8672984ea581179da5 100644 (file)
@@ -1,3 +1,12 @@
+2018-06-25  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2017-09-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/82159
+       * gimplify.c (gimplify_modify_expr): Don't optimize away zero sized
+       lhs from calls if the lhs has addressable type.
+
 2018-06-23  Richard Sandiford  <richard.sandiford@linaro.org>
 
        PR tree-optimization/85989
index 450c061011b63d3fa8d6f62759f161c1f95f0905..e55f5b4216ddddcfcf723b4bdc3298e8ee66d338 100644 (file)
@@ -4696,7 +4696,12 @@ gimplify_modify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
      side as statements and throw away the assignment.  Do this after
      gimplify_modify_expr_rhs so we handle TARGET_EXPRs of addressable
      types properly.  */
-  if (zero_sized_type (TREE_TYPE (*from_p)) && !want_value)
+  if (zero_sized_type (TREE_TYPE (*from_p))
+      && !want_value
+      /* Don't do this for calls that return addressable types, expand_call
+        relies on those having a lhs.  */
+      && !(TREE_ADDRESSABLE (TREE_TYPE (*from_p))
+          && TREE_CODE (*from_p) == CALL_EXPR))
     {
       gimplify_stmt (from_p, pre_p);
       gimplify_stmt (to_p, pre_p);
index 4b40b0e5631b090ef871d507e45f568422195f34..2404a59569a6d72eef66414810965b913d8d51ff 100644 (file)
@@ -1,3 +1,11 @@
+2018-06-25  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2017-09-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/82159
+       * g++.dg/opt/pr82159.C: New test.
+
 2018-06-23  Richard Sandiford  <richard.sandiford@linaro.org>
 
        PR tree-optimization/85989
diff --git a/gcc/testsuite/g++.dg/opt/pr82159.C b/gcc/testsuite/g++.dg/opt/pr82159.C
new file mode 100644 (file)
index 0000000..e39dbc3
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/82159
+// { dg-do compile }
+// { dg-options "" }
+
+template<int N>
+struct S
+{
+  ~S () {}
+  template<int M> S<M> foo () { return S<M> (); }
+  unsigned char data[N];
+};
+
+int
+main ()
+{
+  S<16> d;
+  S<0> t = d.foo<0> ();
+}