]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Check if varying may also be non-negative.
authorAndrew MacLeod <amacleod@redhat.com>
Tue, 25 Oct 2022 19:16:47 +0000 (15:16 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Wed, 26 Oct 2022 13:48:45 +0000 (09:48 -0400)
When using strict enums, we can sometimes turn varying into a better
range.

* gimple-range-fold.cc (fold_using_range::fold_stmt): Check if
stmt is non-negative and adjust the range.

gcc/gimple-range-fold.cc

index f91923782dca96f7e0bcfd2bdfc101b37f9c49ad..a899d8260b3d0834ebece5047df2286b3c351197 100644 (file)
@@ -494,6 +494,14 @@ fold_using_range::fold_stmt (vrange &r, gimple *s, fur_source &src, tree name)
   else if (is_a<gassign *> (s) && gimple_assign_rhs_code (s) == COND_EXPR)
     res = range_of_cond_expr (r, as_a<gassign *> (s), src);
 
+  // If the result is varying, check for basic nonnegativeness.
+  // Specifically this helps for now with strict enum in cases like
+  // g++.dg/warn/pr33738.C.
+  bool so_p;
+  if (res && r.varying_p () && INTEGRAL_TYPE_P (r.type ())
+      && gimple_stmt_nonnegative_warnv_p (s, &so_p))
+    r.set_nonnegative (r.type ());
+
   if (!res)
     {
       // If no name specified or range is unsupported, bail.