re PR middle-end/51895 (ICE in simplify_subreg)
authorJakub Jelinek <jakub@redhat.com>
Thu, 26 Jan 2012 14:09:29 +0000 (15:09 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 26 Jan 2012 14:09:29 +0000 (15:09 +0100)
PR middle-end/51895
* expr.c (expand_expr_real_1): Handle BLKmode MEM_REF of
non-addressable non-BLKmode base correctly.

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

From-SVN: r183560

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

index 2a45134e7d0a033dbd3a492f973f53093cb7c5b2..cd0671ade09802b1722f2936812b800dd5aec11f 100644 (file)
@@ -1,3 +1,9 @@
+2012-01-26  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/51895
+       * expr.c (expand_expr_real_1): Handle BLKmode MEM_REF of
+       non-addressable non-BLKmode base correctly.
+
 2012-01-26  Michael Matz  <matz@suse.de>
 
        PR tree-optimization/48794
index bd2f6b18f7c5a06d32ee1117c0ffedefb8a05386..8698f18e1e675a823f319b6e856cd314a052a160 100644 (file)
@@ -9327,6 +9327,16 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
                bftype = TREE_TYPE (base);
                if (TYPE_MODE (TREE_TYPE (exp)) != BLKmode)
                  bftype = TREE_TYPE (exp);
+               else
+                 {
+                   temp = assign_stack_temp (DECL_MODE (base),
+                                             GET_MODE_SIZE (DECL_MODE (base)),
+                                             0);
+                   store_expr (base, temp, 0, false);
+                   temp = adjust_address (temp, BLKmode, offset);
+                   set_mem_size (temp, int_size_in_bytes (TREE_TYPE (exp)));
+                   return temp;
+                 }
                return expand_expr (build3 (BIT_FIELD_REF, bftype,
                                            base,
                                            TYPE_SIZE (TREE_TYPE (exp)),
index 3ff49d77c5e7ec24cf2b30c60936659b6bc9a876..32baf0e09a7958fca45830b147f000b912859233 100644 (file)
@@ -1,3 +1,8 @@
+2012-01-26  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/51895
+       * g++.dg/opt/pr51895.C: New test.
+
 2012-01-26  Michael Matz  <matz@suse.de>
 
        PR tree-optimization/48794
diff --git a/gcc/testsuite/g++.dg/opt/pr51895.C b/gcc/testsuite/g++.dg/opt/pr51895.C
new file mode 100644 (file)
index 0000000..84ac5e9
--- /dev/null
@@ -0,0 +1,25 @@
+// PR middle-end/51895
+// { dg-do compile }
+// { dg-options "-O2" }
+
+struct S
+{
+  long a;
+  char b;
+  S () : a (0), b (0) {}
+  bool baz ();
+};
+
+__attribute__((noinline)) static bool
+bar (S x, S y)
+{
+  y = x;
+  return y.baz ();
+}
+
+bool
+foo (S x)
+{
+  S y;
+  return bar (x, y);
+}