public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-3139] [PR107170] Avoid copying incompatible types in legacy VRP.
@ 2022-10-06 20:41 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2022-10-06 20:41 UTC (permalink / raw)
  To: gcc-cvs

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;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-06 20:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-06 20:41 [gcc r13-3139] [PR107170] Avoid copying incompatible types in legacy VRP Aldy Hernandez

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