public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@redhat.com>
To: GCC patches <gcc-patches@gcc.gnu.org>
Cc: Andrew MacLeod <amacleod@redhat.com>, Aldy Hernandez <aldyh@redhat.com>
Subject: [COMMITTED] [PR107170] Avoid copying incompatible types in legacy VRP.
Date: Thu,  6 Oct 2022 22:40:35 +0200	[thread overview]
Message-ID: <20221006204035.1796190-1-aldyh@redhat.com> (raw)

Legacy VRP is calling ranger deep inside the bowels, and then trying to
copy an incompatible type.  My previous patch in this area assumed that
the only possibility out of vr_values::get_value_range for an
unsupported type was VARYING, but UNDEFINED can also be returned.

	PR tree-optimization/107170

gcc/ChangeLog:

	* vr-values.cc (vr_values::range_of_expr):  Do not die on
	unsupported types.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/pr107170.c: New test.
---
 gcc/testsuite/gcc.dg/tree-ssa/pr107170.c |  8 ++++++++
 gcc/vr-values.cc                         | 24 +++++++++++++-----------
 2 files changed, 21 insertions(+), 11 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr107170.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107170.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107170.c
new file mode 100644
index 00000000000..7a5a4a363f2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107170.c
@@ -0,0 +1,8 @@
+// { dg-do compile }
+// { dg-options "-O2" }
+
+int main() {
+  double a;
+  if (__builtin_signbit(a))
+    __builtin_abort();
+}
diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc
index 626a9189472..71fed1e6a7e 100644
--- a/gcc/vr-values.cc
+++ b/gcc/vr-values.cc
@@ -184,21 +184,23 @@ vr_values::range_of_expr (vrange &r, tree expr, gimple *stmt)
 
   if (const value_range *vr = get_value_range (expr, stmt))
     {
+      if (!vr->supports_type_p (TREE_TYPE (expr)))
+	{
+	  // vr_values::extract_range_basic() use of ranger's
+	  // fold_range() can create a situation where we are asked
+	  // for the range of an unsupported legacy type.  Since
+	  // get_value_range() above will return varying or undefined
+	  // for such types, avoid copying incompatible range types.
+	  if (vr->undefined_p ())
+	    r.set_undefined ();
+	  else
+	    r.set_varying (TREE_TYPE (expr));
+	  return true;
+	}
       if (vr->undefined_p () || vr->constant_p ())
 	r = *vr;
       else
 	{
-	  if (!vr->supports_type_p (TREE_TYPE (expr)))
-	    {
-	      // vr_values::extract_range_basic() use of ranger's
-	      // fold_range() can create a situation where we are
-	      // asked for the range of an unsupported legacy type.
-	      // Since get_value_range() above will return varying for
-	      // such types, avoid copying incompatible range types.
-	      gcc_checking_assert (vr->varying_p ());
-	      r.set_varying (TREE_TYPE (expr));
-	      return true;
-	    }
 	  value_range tmp = *vr;
 	  tmp.normalize_symbolics ();
 	  r = tmp;
-- 
2.37.1


                 reply	other threads:[~2022-10-06 20:40 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=20221006204035.1796190-1-aldyh@redhat.com \
    --to=aldyh@redhat.com \
    --cc=amacleod@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).