tree-optimization/108547 - robustify uninit predicate analysis
authorRichard Biener <rguenther@suse.de>
Thu, 26 Jan 2023 07:59:20 +0000 (08:59 +0100)
committerRichard Biener <rguenther@suse.de>
Thu, 26 Jan 2023 12:49:30 +0000 (13:49 +0100)
Predicate analysis, when looking through casts doesn't bother to
convert boundary constants to the type of the bounded variables.
The following robustifies value_sat_pred_p to use widest_ints
to deal with this, like other code in predicate analysis.

PR tree-optimization/108547
* gimple-predicate-analysis.cc (value_sat_pred_p):
Use widest_int.

* gcc.dg/uninit-pr108547.c: New testcase.

gcc/gimple-predicate-analysis.cc
gcc/testsuite/gcc.dg/uninit-pr108547.c [new file with mode: 0644]

index a7719ff..094e8c7 100644 (file)
@@ -728,11 +728,11 @@ value_sat_pred_p (tree val, tree boundary, tree_code cmpc,
   if (cmpc != BIT_AND_EXPR)
     return is_value_included_in (val, boundary, cmpc);
 
-  wide_int andw = wi::to_wide (val) & wi::to_wide (boundary);
+  widest_int andw = wi::to_widest (val) & wi::to_widest (boundary);
   if (exact_p)
-    return andw == wi::to_wide (val);
+    return andw == wi::to_widest (val);
 
-  return andw.to_uhwi ();
+  return wi::ne_p (andw, 0);
 }
 
 /* Return true if the domain of single predicate expression PRED1
diff --git a/gcc/testsuite/gcc.dg/uninit-pr108547.c b/gcc/testsuite/gcc.dg/uninit-pr108547.c
new file mode 100644 (file)
index 0000000..d8f6c9f
--- /dev/null
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wuninitialized" } */
+
+int func_7_uc_10li_19 (int);
+int li_4, li_5, us_8;
+unsigned char func_7_ptr_13, func_7_uc_14;
+void func_7_ptr_18() {
+  if (li_5) {
+    for (;;)
+      ;
+    short s_15;
+    for (; func_7_uc_14;) {
+      us_8 = 7;
+      for (; us_8; us_8 += 1)
+      lblD2AF1FAB:
+        if (us_8)
+          li_4 = 1;
+      func_7_uc_14 += (__INTPTR_TYPE__)func_7_ptr_18;
+      if (func_7_ptr_13 & 1 && (func_7_uc_14 &= func_7_ptr_13))
+        s_15 %= func_7_uc_10li_19(s_15); /* { dg-warning "uninitialized" } */
+    }
+  }
+  goto lblD2AF1FAB;
+}