This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFC: PATCH to pointer_int_sum vs. pointer-arith-10.c


I made this change on the delayed folding branch and then noticed that it broke pointer-arith-10.c, which you added to the testsuite. The patch changes the -original dump from

  return (char *) ((sizetype) p + (sizetype) i);

to

  return (char *) i + (sizetype) p;

It's not clear to me why the former should be preferred.  Any thoughts?

Jason

commit 798829561671959e9e49965eb8c1b137b48751e0
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Oct 20 00:39:03 2015 -1000

    	* c-common.c (pointer_int_sum): Fold the MULT_EXPR.

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 1c75921..f957018 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]