aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2017-08-04 11:28:04 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2017-08-04 11:28:04 +0000
commitf4f2c2ece3c309ac3d7e8a6bfd9f6cd9c6cb95a1 (patch)
tree036d0f437c35140e96e4226f26fbaf9c690128ba /gcc/fold-const.c
parent62c8a2cf17cd794241c8f978c8fcfc4682ca4315 (diff)
downloadgcc-f4f2c2ece3c309ac3d7e8a6bfd9f6cd9c6cb95a1.zip
gcc-f4f2c2ece3c309ac3d7e8a6bfd9f6cd9c6cb95a1.tar.gz
gcc-f4f2c2ece3c309ac3d7e8a6bfd9f6cd9c6cb95a1.tar.bz2
re PR middle-end/81695 (internal compiler error: in size_binop_loc, at fold-const.c:1768)
PR middle-end/81695 * fold-const.c (fold_indirect_ref_1): For ((int *)&a + 4 -> a[1], perform the computation in offset_int. * gcc.dg/pr81695.c: New test. From-SVN: r250871
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 53428b89..d563ba7 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -14107,14 +14107,21 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
&& type == TREE_TYPE (op00type))
{
tree type_domain = TYPE_DOMAIN (op00type);
- tree min_val = size_zero_node;
- if (type_domain && TYPE_MIN_VALUE (type_domain))
- min_val = TYPE_MIN_VALUE (type_domain);
- op01 = size_binop_loc (loc, EXACT_DIV_EXPR, op01,
- TYPE_SIZE_UNIT (type));
- op01 = size_binop_loc (loc, PLUS_EXPR, op01, min_val);
- return build4_loc (loc, ARRAY_REF, type, op00, op01,
- NULL_TREE, NULL_TREE);
+ tree min = TYPE_MIN_VALUE (type_domain);
+ if (min && TREE_CODE (min) == INTEGER_CST)
+ {
+ offset_int off = wi::to_offset (op01);
+ offset_int el_sz = wi::to_offset (TYPE_SIZE_UNIT (type));
+ offset_int remainder;
+ off = wi::divmod_trunc (off, el_sz, SIGNED, &remainder);
+ if (remainder == 0)
+ {
+ off = off + wi::to_offset (min);
+ op01 = wide_int_to_tree (sizetype, off);
+ return build4_loc (loc, ARRAY_REF, type, op00, op01,
+ NULL_TREE, NULL_TREE);
+ }
+ }
}
}
}