]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Pass correct type to irange::contains_p() in ipa-cp.cc.
authorAldy Hernandez <aldyh@redhat.com>
Mon, 21 Nov 2022 22:18:43 +0000 (23:18 +0100)
committerAldy Hernandez <aldyh@redhat.com>
Tue, 25 Apr 2023 07:38:33 +0000 (09:38 +0200)
There is a call to contains_p() in ipa-cp.cc which passes incompatible
types.  This currently works because deep in the call chain, the legacy
code uses tree_int_cst_lt which performs the operation with
widest_int.  With the upcoming removal of legacy, contains_p() will be
stricter.

gcc/ChangeLog:

* ipa-cp.cc (ipa_range_contains_p): New.
(decide_whether_version_node): Use it.

gcc/ipa-cp.cc

index b3e0f62e400359ff901997b73fcee32982d85a47..65c49558b588e6c2223a7ac51664d05307a9e45a 100644 (file)
@@ -6180,6 +6180,23 @@ decide_about_value (struct cgraph_node *node, int index, HOST_WIDE_INT offset,
   return true;
 }
 
+/* Like irange::contains_p(), but convert VAL to the range of R if
+   necessary.  */
+
+static inline bool
+ipa_range_contains_p (const irange &r, tree val)
+{
+  if (r.undefined_p ())
+    return false;
+
+  tree type = r.type ();
+  if (!wi::fits_to_tree_p (wi::to_wide (val), type))
+    return false;
+
+  val = fold_convert (type, val);
+  return r.contains_p (val);
+}
+
 /* Decide whether and what specialized clones of NODE should be created.  */
 
 static bool
@@ -6221,7 +6238,8 @@ decide_whether_version_node (struct cgraph_node *node)
                 supports this only for integers now.  */
              if (TREE_CODE (val->value) == INTEGER_CST
                  && !plats->m_value_range.bottom_p ()
-                 && !plats->m_value_range.m_vr.contains_p (val->value))
+                 && !ipa_range_contains_p (plats->m_value_range.m_vr,
+                                           val->value))
                {
                  /* This can happen also if a constant present in the source
                     code falls outside of the range of parameter's type, so we