PR middle-end/58344
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 16 Jan 2014 19:54:23 +0000 (19:54 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 16 Jan 2014 19:54:23 +0000 (19:54 +0000)
* expr.c (expand_expr_real_1): Handle init == NULL_TREE.

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

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@206685 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 098e0c1..f7a764f 100644 (file)
@@ -1,5 +1,8 @@
 2014-01-16  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/58344
+       * expr.c (expand_expr_real_1): Handle init == NULL_TREE.
+
        PR target/59839
        * config/i386/i386.c (ix86_expand_builtin): If target doesn't
        satisfy operand 0 predicate for gathers, use a new pseudo as
index 400a152..878a51b 100644 (file)
@@ -9832,7 +9832,25 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
                     || TREE_CODE (array) == CONST_DECL)
                 && (init = ctor_for_folding (array)) != error_mark_node)
          {
-           if (TREE_CODE (init) == CONSTRUCTOR)
+           if (init == NULL_TREE)
+             {
+               tree value = build_zero_cst (type);
+               if (TREE_CODE (value) == CONSTRUCTOR)
+                 {
+                   /* If VALUE is a CONSTRUCTOR, this optimization is only
+                      useful if this doesn't store the CONSTRUCTOR into
+                      memory.  If it does, it is more efficient to just
+                      load the data from the array directly.  */
+                   rtx ret = expand_constructor (value, target,
+                                                 modifier, true);
+                   if (ret == NULL_RTX)
+                     value = NULL_TREE;
+                 }
+
+               if (value)
+                 return expand_expr (value, target, tmode, modifier);
+             }
+           else if (TREE_CODE (init) == CONSTRUCTOR)
              {
                unsigned HOST_WIDE_INT ix;
                tree field, value;
index 6482650..fa17276 100644 (file)
@@ -1,5 +1,8 @@
 2014-01-16  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/58344
+       * gcc.c-torture/compile/pr58344.c: New test.
+
        PR target/59839
        * gcc.target/i386/pr59839.c: New test.
 
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr58344.c b/gcc/testsuite/gcc.c-torture/compile/pr58344.c
new file mode 100644 (file)
index 0000000..42b646f
--- /dev/null
@@ -0,0 +1,12 @@
+/* PR middle-end/58344 */
+/* { dg-do compile } */
+
+struct U {};
+static struct U a[1];
+extern void bar (struct U);
+
+void
+foo (void)
+{
+  bar (a[0]);
+}