From: Jason Merrill Date: Wed, 28 Oct 2015 18:54:48 +0000 (-0400) Subject: * c-common.c (pointer_int_sum): Fold the MULT_EXPR. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d90ec4f2bc82f513821be7054b1eeb5c200e81af;p=gcc.git * c-common.c (pointer_int_sum): Fold the MULT_EXPR. From-SVN: r229500 --- diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 4d225726c56..fb017fa464e 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,7 @@ +2015-10-28 Jason Merrill + + * c-common.c (pointer_int_sum): Fold the MULT_EXPR. + 2015-10-27 Thomas Schwinge James Norris Cesar Philippidis diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 1c75921d542..f957018845b 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); diff --git a/gcc/testsuite/gcc.dg/pointer-arith-10.c b/gcc/testsuite/gcc.dg/pointer-arith-10.c index 00e75973e17..35e2b11ef96 100644 --- a/gcc/testsuite/gcc.dg/pointer-arith-10.c +++ b/gcc/testsuite/gcc.dg/pointer-arith-10.c @@ -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" } } */