]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR middle-end/64067 (ICE in expand_expr_real_1, at expr.c:10540, involvi...
authorJakub Jelinek <jakub@redhat.com>
Fri, 28 Nov 2014 17:06:23 +0000 (18:06 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 28 Nov 2014 17:06:23 +0000 (18:06 +0100)
Backported from mainline
2014-11-27  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/64067
* expr.c (expand_expr_addr_expr_1) <case COMPOUND_LITERAL_EXPR>:
Handle it by returning address of COMPOUND_LITERAL_EXPR_DECL
not only if modifier is EXPAND_INITIALIZER, but whenever
COMPOUND_LITERAL_EXPR_DECL is non-NULL and TREE_STATIC.

* gcc.c-torture/compile/pr64067.c: New test.

From-SVN: r218169

gcc/ChangeLog
gcc/expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr64067.c [new file with mode: 0644]

index 47fefa01be8a175d8b0178cde177f19cb18998a5..7e04d5e7f2245a19371e7750a6961132ca91a817 100644 (file)
@@ -1,6 +1,14 @@
 2014-11-28  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2014-11-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/64067
+       * expr.c (expand_expr_addr_expr_1) <case COMPOUND_LITERAL_EXPR>:
+       Handle it by returning address of COMPOUND_LITERAL_EXPR_DECL
+       not only if modifier is EXPAND_INITIALIZER, but whenever
+       COMPOUND_LITERAL_EXPR_DECL is non-NULL and TREE_STATIC.
+
        2014-10-31  Jakub Jelinek  <jakub@redhat.com>
 
        PR rtl-optimization/63659
index f83a7d0d448ee7683d1a3a6ae65061fcad6ecda0..8a82b7af03f2fc817251103a4cee48a987f705c7 100644 (file)
@@ -7590,11 +7590,13 @@ expand_expr_addr_expr_1 (tree exp, rtx target, enum machine_mode tmode,
       break;
 
     case COMPOUND_LITERAL_EXPR:
-      /* Allow COMPOUND_LITERAL_EXPR in initializers, if e.g.
-        rtl_for_decl_init is called on DECL_INITIAL with
-        COMPOUNT_LITERAL_EXPRs in it, they aren't gimplified.  */
-      if (modifier == EXPAND_INITIALIZER
-         && COMPOUND_LITERAL_EXPR_DECL (exp))
+      /* Allow COMPOUND_LITERAL_EXPR in initializers or coming from
+        initializers, if e.g. rtl_for_decl_init is called on DECL_INITIAL
+        with COMPOUND_LITERAL_EXPRs in it, or ARRAY_REF on a const static
+        array with address of COMPOUND_LITERAL_EXPR in DECL_INITIAL;
+        the initializers aren't gimplified.  */
+      if (COMPOUND_LITERAL_EXPR_DECL (exp)
+         && TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (exp)))
        return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp),
                                        target, tmode, modifier, as);
       /* FALLTHRU */
index 38d5c102bce69415bc74d7cb65e0320ebb8d9e58..714d3f94d7630f008174137ba4ff12a153cfa571 100644 (file)
@@ -1,6 +1,11 @@
 2014-11-28  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2014-11-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/64067
+       * gcc.c-torture/compile/pr64067.c: New test.
+
        2014-10-31  Jakub Jelinek  <jakub@redhat.com>
 
        PR rtl-optimization/63659
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr64067.c b/gcc/testsuite/gcc.c-torture/compile/pr64067.c
new file mode 100644 (file)
index 0000000..24ad996
--- /dev/null
@@ -0,0 +1,10 @@
+/* PR middle-end/64067 */
+
+struct S { int s; };
+int *const v[1] = { &((struct S) { .s = 42 }).s };
+
+int *
+foo (void)
+{
+  return v[0];
+}