re PR tree-optimization/55920 (ICE in expand_debug_locations, at cfgexpand.c:3753)
authorJakub Jelinek <jakub@redhat.com>
Tue, 15 Jan 2013 16:33:24 +0000 (17:33 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 15 Jan 2013 16:33:24 +0000 (17:33 +0100)
PR tree-optimization/55920
* tree-sra.c (sra_modify_assign): If for lacc->grp_to_be_debug_replaced
there is non-useless type conversion needed from debug rhs to lhs,
use build_debug_ref_for_model and/or VIEW_CONVERT_EXPR.

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

From-SVN: r195209

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr55920.c [new file with mode: 0644]
gcc/tree-sra.c

index f900422f2d9819fff4bc843c6e2eb7fe296695fa..8323062459da7528611c911b7ea5841af13b17e4 100644 (file)
@@ -1,3 +1,10 @@
+2013-01-15  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/55920
+       * tree-sra.c (sra_modify_assign): If for lacc->grp_to_be_debug_replaced
+       there is non-useless type conversion needed from debug rhs to lhs,
+       use build_debug_ref_for_model and/or VIEW_CONVERT_EXPR.
+
 2013-01-15  Joseph Myers  <joseph@codesourcery.com>
            Mikael Pettersson  <mikpe@it.uu.se>
 
index c286a87f06261373938e659eb715d9bcc966a6ec..c20ed625e95323a26855613d5577e747bacda23d 100644 (file)
@@ -1,3 +1,8 @@
+2013-01-15  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/55920
+       * gcc.c-torture/compile/pr55920.c: New test.
+
 2013-01-15  Richard Biener  <rguenther@suse.de>
 
        PR middle-end/55882
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr55920.c b/gcc/testsuite/gcc.c-torture/compile/pr55920.c
new file mode 100644 (file)
index 0000000..9138743
--- /dev/null
@@ -0,0 +1,16 @@
+/* PR tree-optimization/55920 */
+
+struct A { unsigned a; } __attribute__((packed));
+struct B { int b; unsigned char c[16]; };
+void bar (struct A);
+
+void
+foo (struct B *x)
+{
+  struct A a;
+  if (x->b)
+    __builtin_memcpy (&a, x->c, sizeof a);
+  else
+    a.a = 0;
+  bar (a);
+}
index 367e32b69c891dfb6e62a51067b6d076757cd754..e5fbcf2c5c5ffb352e295763059e6d12191fa243 100644 (file)
@@ -3108,8 +3108,20 @@ sra_modify_assign (gimple *stmt, gimple_stmt_iterator *gsi)
 
   if (lacc && lacc->grp_to_be_debug_replaced)
     {
-      gimple ds = gimple_build_debug_bind (get_access_replacement (lacc),
-                                          unshare_expr (rhs), *stmt);
+      tree dlhs = get_access_replacement (lacc);
+      tree drhs = unshare_expr (rhs);
+      if (!useless_type_conversion_p (TREE_TYPE (dlhs), TREE_TYPE (drhs)))
+       {
+         if (AGGREGATE_TYPE_P (TREE_TYPE (drhs))
+             && !contains_vce_or_bfcref_p (drhs))
+           drhs = build_debug_ref_for_model (loc, drhs, 0, lacc);
+         if (drhs
+             && !useless_type_conversion_p (TREE_TYPE (dlhs),
+                                            TREE_TYPE (drhs)))
+           drhs = fold_build1_loc (loc, VIEW_CONVERT_EXPR,
+                                   TREE_TYPE (dlhs), drhs);
+       }
+      gimple ds = gimple_build_debug_bind (dlhs, drhs, *stmt);
       gsi_insert_before (gsi, ds, GSI_SAME_STMT);
     }