2017-10-02 Jakub Jelinek <jakub@redhat.com>
+ * tree-dfa.c (get_ref_base_and_extent): Set *pmax_size to -1
+ if *poffset + *pmax_size overflows in HOST_WIDE_INT.
+ Set *poffset to 0 and *psize and *pmax_size to -1 if
+ *poffset + *psize overflows in HOST_WIDE_INT.
+
PR tree-optimization/82387
PR tree-optimization/82388
PR tree-optimization/82389
2017-10-02 Jakub Jelinek <jakub@redhat.com>
+ * gcc.dg/pr82389.c: New test.
+
PR tree-optimization/82387
PR tree-optimization/82388
PR tree-optimization/82389
--- /dev/null
+/* PR tree-optimization/82389 */
+/* { dg-do compile { target lp64 } } */
+/* { dg-options "-w -O3" } */
+
+struct S { char s[0x40000000]; } s;
+
+void
+foo (struct S *p)
+{
+ char b[0x0ffffffff0000000L];
+ *(struct S *)&b[0x0fffffffef000000L] = s;
+ *p = *(struct S *)&b[0x0fffffffefffffffL];
+}
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;
}