aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Kenner <kenner@gcc.gnu.org>1995-07-28 09:36:30 -0400
committerRichard Kenner <kenner@gcc.gnu.org>1995-07-28 09:36:30 -0400
commitba11c17994a5aba402252e4a7d0e5c91cad0aea9 (patch)
tree4e1cbd749e872edf73c87f35b7de6e3682d478c2 /gcc
parent307d8cd67d3339e79da8160b95eed56cabe6d37e (diff)
downloadgcc-ba11c17994a5aba402252e4a7d0e5c91cad0aea9.zip
gcc-ba11c17994a5aba402252e4a7d0e5c91cad0aea9.tar.gz
gcc-ba11c17994a5aba402252e4a7d0e5c91cad0aea9.tar.bz2
(pointer_int_sum): Don't distribute if intop is unsigned and not the
same size as ptrop. From-SVN: r10186
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c-typeck.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 4e41e5f..b16a7bf 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -2648,7 +2648,13 @@ pointer_int_sum (resultcode, ptrop, intop)
&& TREE_CONSTANT (size_exp)
/* If the constant comes from pointer subtraction,
skip this optimization--it would cause an error. */
- && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE)
+ && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE
+ /* If the constant is unsigned, and smaller than the pointer size,
+ then we must skip this optimization. This is because it could cause
+ an overflow error if the constant is negative but INTOP is not. */
+ && (! TREE_UNSIGNED (TREE_TYPE (intop))
+ || (TYPE_PRECISION (TREE_TYPE (intop))
+ == TYPE_PRECISION (TREE_TYPE (ptrop)))))
{
enum tree_code subcode = resultcode;
tree int_type = TREE_TYPE (intop);