* tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Also
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 15 May 2009 12:13:02 +0000 (12:13 +0000)
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 15 May 2009 12:13:02 +0000 (12:13 +0000)
recurse on an invariant address if a conversion from a pointer
type to a wider integer type is involved.

testsuite:
* gcc.c-torture/compile/ptr-conv-1.c: New test.

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

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/ptr-conv-1.c [new file with mode: 0644]
gcc/tree-ssa-forwprop.c

index 39cd78d..ac138ca 100644 (file)
@@ -1,3 +1,9 @@
+2009-05-15  Joseph Myers  <joseph@codesourcery.com>
+
+       * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Also
+       recurse on an invariant address if a conversion from a pointer
+       type to a wider integer type is involved.
+
 2009-05-15  Jan Hubicka  <jh@suse.cz>
 
        * cgraph.c (dump_cgraph_node): Dump size/time/benefit.
index 2733cb5..b8ab7d4 100644 (file)
@@ -1,3 +1,7 @@
+2009-05-15  Joseph Myers  <joseph@codesourcery.com>
+
+       * gcc.c-torture/compile/ptr-conv-1.c: New test.
+
 2009-05-14  Ian Lance Taylor  <iant@google.com>
 
        * gcc.dg/Wcxx-compat-9.c: New testcase.
diff --git a/gcc/testsuite/gcc.c-torture/compile/ptr-conv-1.c b/gcc/testsuite/gcc.c-torture/compile/ptr-conv-1.c
new file mode 100644 (file)
index 0000000..11dc8ce
--- /dev/null
@@ -0,0 +1,11 @@
+/* The intermediate conversion to __PTRDIFF_TYPE__ could be lost,
+   resulting in an "invalid types in nop conversion" ICE.  */
+long long a;
+void
+f (void)
+{
+  int c = 1;
+  volatile int *p = &c;
+  a = (long long) (__PTRDIFF_TYPE__) p;
+  *p;
+}
index 65b02af..ef78703 100644 (file)
@@ -739,7 +739,11 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs,
         address which we cannot do in a single statement.  */
       if (!single_use_p
          || (!useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (def_rhs))
-             && !is_gimple_min_invariant (def_rhs)))
+             && (!is_gimple_min_invariant (def_rhs)
+                 || (INTEGRAL_TYPE_P (TREE_TYPE (lhs))
+                     && POINTER_TYPE_P (TREE_TYPE (def_rhs))
+                     && (TYPE_PRECISION (TREE_TYPE (lhs))
+                         > TYPE_PRECISION (TREE_TYPE (def_rhs)))))))
        return forward_propagate_addr_expr (lhs, def_rhs);
 
       gimple_assign_set_rhs1 (use_stmt, unshare_expr (def_rhs));