public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-3139] [PR107170] Avoid copying incompatible types in legacy VRP.
Date: Thu,  6 Oct 2022 20:41:03 +0000 (GMT)	[thread overview]
Message-ID: <20221006204103.490123898386@sourceware.org> (raw)

https://gcc.gnu.org/g:49b9a8c8cc498b1ed2f566bee858e651e14ba37b

commit r13-3139-g49b9a8c8cc498b1ed2f566bee858e651e14ba37b
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Thu Oct 6 19:11:08 2022 +0200

    [PR107170] Avoid copying incompatible types in legacy VRP.
    
    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.

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

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;

                 reply	other threads:[~2022-10-06 20:41 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=20221006204103.490123898386@sourceware.org \
    --to=aldyh@gcc.gnu.org \
    --cc=gcc-cvs@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).