From: Aldy Hernandez <aldyh@redhat.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PUSHED] Fix PR97315 (part 2 of 2)
Date: Thu, 8 Oct 2020 11:36:57 +0200 [thread overview]
Message-ID: <79b7d4c5-a6fd-8661-7e03-7c5f2156f27c@redhat.com> (raw)
This fixes the second testcase in the PR.
I've tested Andrew's patch and pushed it.
Aldy
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.
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 87c6d82f2ac..22bc23c1bbf 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 00000000000..5dd1b6a3fc7
--- /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);
+}
reply other threads:[~2020-10-08 9:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=79b7d4c5-a6fd-8661-7e03-7c5f2156f27c@redhat.com \
--to=aldyh@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).