diff options
author | Aldy Hernandez <aldyh@redhat.com> | 2020-10-08 11:33:30 +0200 |
---|---|---|
committer | Aldy Hernandez <aldyh@redhat.com> | 2020-10-08 11:33:30 +0200 |
commit | 91ae6930ed4a87d7b8e25e10378388b3f0dc1729 (patch) | |
tree | 836ee5c9ce2998193b962ac2f7e45f3296a536e5 | |
parent | 214d514fafcd78cd54e4a4aa9ae08c89abf9cc57 (diff) | |
download | gcc-91ae6930ed4a87d7b8e25e10378388b3f0dc1729.zip gcc-91ae6930ed4a87d7b8e25e10378388b3f0dc1729.tar.gz gcc-91ae6930ed4a87d7b8e25e10378388b3f0dc1729.tar.bz2 |
Fix PR97315 (part 2 of 2)
gcc/ChangeLog:
PR tree-optimization/97315
* range-op.cc (value_range_with_overflow): Change any
non-overflow calculation in which both bounds are
overflow/underflow to be undefined.
gcc/testsuite/ChangeLog:
* gcc.dg/pr97315-2.c: New test.
-rw-r--r-- | gcc/range-op.cc | 9 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr97315-2.c | 11 |
2 files changed, 20 insertions, 0 deletions
diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 87c6d82..22bc23c 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -287,6 +287,15 @@ value_range_with_overflow (irange &r, tree type, } else { + // If both bounds either underflowed or overflowed, then the result + // is undefined. + if ((min_ovf == wi::OVF_OVERFLOW && max_ovf == wi::OVF_OVERFLOW) + || (min_ovf == wi::OVF_UNDERFLOW && max_ovf == wi::OVF_UNDERFLOW)) + { + r.set_undefined (); + return; + } + // If overflow does not wrap, saturate to [MIN, MAX]. wide_int new_lb, new_ub; if (min_ovf == wi::OVF_UNDERFLOW) diff --git a/gcc/testsuite/gcc.dg/pr97315-2.c b/gcc/testsuite/gcc.dg/pr97315-2.c new file mode 100644 index 0000000..5dd1b6a --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr97315-2.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +void c(int); + +int a; +void b() +{ + if (a >= 2147483647) + c(a + 1); +} |