* c-common.c (pointer_int_sum): Fold the MULT_EXPR.
authorJason Merrill <jason@redhat.com>
Wed, 28 Oct 2015 18:54:48 +0000 (14:54 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 28 Oct 2015 18:54:48 +0000 (14:54 -0400)
From-SVN: r229500

gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/testsuite/gcc.dg/pointer-arith-10.c

index 4d225726c56ef80f7336a9c8f23c5388df18ea97..fb017fa464e0ad3adf2c6cfe05bd1339361c45d3 100644 (file)
@@ -1,3 +1,7 @@
+2015-10-28  Jason Merrill  <jason@redhat.com>
+
+       * c-common.c (pointer_int_sum): Fold the MULT_EXPR.
+
 2015-10-27  Thomas Schwinge  <thomas@codesourcery.com>
            James Norris  <jnorris@codesourcery.com>
            Cesar Philippidis  <cesar@codesourcery.com>
index 1c75921d5426650b4c1b3139cece6ca55a32c929..f957018845bf19995bff242555684bb042d2addf 100644 (file)
@@ -4849,9 +4849,8 @@ pointer_int_sum (location_t loc, enum tree_code resultcode,
      for the pointer operation and disregard an overflow that occurred only
      because of the sign-extension change in the latter conversion.  */
   {
-    tree t = build_binary_op (loc,
-                             MULT_EXPR, intop,
-                             convert (TREE_TYPE (intop), size_exp), 1);
+    tree t = fold_build2_loc (loc, MULT_EXPR, TREE_TYPE (intop), intop,
+                             convert (TREE_TYPE (intop), size_exp));
     intop = convert (sizetype, t);
     if (TREE_OVERFLOW_P (intop) && !TREE_OVERFLOW (t))
       intop = wide_int_to_tree (TREE_TYPE (intop), intop);
index 00e75973e1721f7a4d7faa52ffd87381d19170f9..35e2b11ef96b74408a27cfa3ed15091d92348383 100644 (file)
@@ -6,4 +6,9 @@ char *foo(char *p, __UINTPTR_TYPE__ i)
   return (char *)i + (__UINTPTR_TYPE__)p;
 }
 
-/* { dg-final { scan-tree-dump "p +" "original" } } */
+/* Check that we use a POINTER_PLUS_EXPR, not something like
+   return (char *) ((sizetype) p + (sizetype) i); */
+/* { dg-final { scan-tree-dump-not "sizetype.*sizetype" "original" } } */
+
+/* And also that we don't swap the operands.  */
+/* { dg-final { scan-tree-dump-not "return p +" "original" } } */