Commit 476dec78 by Jakub Jelinek Committed by Jakub Jelinek

tree-dfa.c (get_ref_base_and_extent): Set *pmax_size to -1 if *poffset +…

tree-dfa.c (get_ref_base_and_extent): Set *pmax_size to -1 if *poffset + *pmax_size overflows in HOST_WIDE_INT.

	* 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.

	* gcc.dg/pr82389.c: New test.

From-SVN: r253357
parent f240a230
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
......
/* 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];
}
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment