public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-5383] tree-optimization/108547 - robustify uninit predicate analysis
Date: Thu, 26 Jan 2023 12:49:49 +0000 (GMT)	[thread overview]
Message-ID: <20230126124949.5466B3858412@sourceware.org> (raw)

https://gcc.gnu.org/g:c71a128a3e1ff6ee5274fc2df49ea650bc9e6c2d

commit r13-5383-gc71a128a3e1ff6ee5274fc2df49ea650bc9e6c2d
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Jan 26 08:59:20 2023 +0100

    tree-optimization/108547 - robustify uninit predicate analysis
    
    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.

Diff:
---
 gcc/gimple-predicate-analysis.cc       |  6 +++---
 gcc/testsuite/gcc.dg/uninit-pr108547.c | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/gcc/gimple-predicate-analysis.cc b/gcc/gimple-predicate-analysis.cc
index a7719ff493f..094e8c7aff3 100644
--- a/gcc/gimple-predicate-analysis.cc
+++ b/gcc/gimple-predicate-analysis.cc
@@ -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
index 00000000000..d8f6c9ff87a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/uninit-pr108547.c
@@ -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;
+}

                 reply	other threads:[~2023-01-26 12:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230126124949.5466B3858412@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).