diff options
author | Richard Kenner <kenner@gcc.gnu.org> | 1994-03-09 16:49:14 -0500 |
---|---|---|
committer | Richard Kenner <kenner@gcc.gnu.org> | 1994-03-09 16:49:14 -0500 |
commit | 6946afd3a556e0681ea8f381d2492c26b98a8a39 (patch) | |
tree | 53ad3150d873ee7e8bebfa9dfb3bf4ef948daa24 /gcc | |
parent | 7a3b13d103dded207b67281ead59e3cf8fe01aaa (diff) | |
download | gcc-6946afd3a556e0681ea8f381d2492c26b98a8a39.zip gcc-6946afd3a556e0681ea8f381d2492c26b98a8a39.tar.gz gcc-6946afd3a556e0681ea8f381d2492c26b98a8a39.tar.bz2 |
(pointer_int_sum): Multiplication should be done signed.
(pointer_diff): Likewise the division.
From-SVN: r6733
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c-typeck.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 9b56bf9..412f3c3 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -2520,10 +2520,13 @@ pointer_int_sum (resultcode, ptrop, intop) if (TYPE_PRECISION (TREE_TYPE (intop)) != POINTER_SIZE) intop = convert (type_for_size (POINTER_SIZE, 0), intop); - /* Replace the integer argument - with a suitable product by the object size. */ + /* Replace the integer argument with a suitable product by the object size. + Do this multiplication as signed, then convert to the appropriate + pointer type (actually unsigned integral). */ - intop = build_binary_op (MULT_EXPR, intop, size_exp, 1); + intop = convert (result_type, + build_binary_op (MULT_EXPR, intop, + convert (TREE_TYPE (intop), size_exp), 1)); /* Create the sum or difference. */ @@ -2563,12 +2566,13 @@ pointer_diff (op0, op1) /* This generates an error if op1 is pointer to incomplete type. */ if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1))) == 0) error ("arithmetic on pointer to an incomplete type"); + /* This generates an error if op0 is pointer to incomplete type. */ op1 = c_size_in_bytes (target_type); /* Divide by the size, in easiest possible way. */ - result = build (EXACT_DIV_EXPR, restype, op0, op1); + result = build (EXACT_DIV_EXPR, restype, op0, convert (restype, op1)); folded = fold (result); if (folded == result) |