aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-dfa.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/tree-dfa.c')
-rw-r--r--gcc/tree-dfa.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/gcc/tree-dfa.c b/gcc/tree-dfa.c
index 2e65a44..db69bda 100644
--- a/gcc/tree-dfa.c
+++ b/gcc/tree-dfa.c
@@ -654,7 +654,22 @@ get_ref_base_and_extent (tree exp, HOST_WIDE_INT *poffset,
if (!wi::fits_shwi_p (maxsize) || wi::neg_p (maxsize))
*pmax_size = -1;
else
- *pmax_size = maxsize.to_shwi ();
+ {
+ *pmax_size = maxsize.to_shwi ();
+ if (*poffset > HOST_WIDE_INT_MAX - *pmax_size)
+ *pmax_size = -1;
+ }
+
+ /* Punt if *POFFSET + *PSIZE overflows in HOST_WIDE_INT, the callers don't
+ check for such overflows individually and assume it works. */
+ if (*psize != -1 && *poffset > HOST_WIDE_INT_MAX - *psize)
+ {
+ *poffset = 0;
+ *psize = -1;
+ *pmax_size = -1;
+
+ return exp;
+ }
return exp;
}