diff mbox series

[COMMITTED,PR107170] Avoid copying incompatible types in legacy VRP.

Message ID 20221006204035.1796190-1-aldyh@redhat.com
State New
Headers show
Series [COMMITTED,PR107170] Avoid copying incompatible types in legacy VRP. | expand

Commit Message

Aldy Hernandez Oct. 6, 2022, 8:40 p.m. UTC
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 mbox series

Patch

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;