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-2926] tree-optimization/105646 - re-interpret always executed in uninit diag
Date: Thu, 29 Sep 2022 08:24:01 +0000 (GMT)	[thread overview]
Message-ID: <20220929082401.21C043858D28@sourceware.org> (raw)

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

commit r13-2926-ga1cd4d52d6ef90b977fb2d80c1cf17f3efa5b01d
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Aug 19 15:11:14 2022 +0200

    tree-optimization/105646 - re-interpret always executed in uninit diag
    
    The following fixes PR105646, not diagnosing
    
    int f1();
    int f3(){
        auto const & a = f1();
        bool v3{v3};
        return a;
    }
    
    with optimization because the early uninit diagnostic pass only
    diagnoses always executed cases.  The patch does this by
    re-interpreting what always executed means and choosing to
    ignore exceptional and abnormal control flow for this.  At the
    same time it improves things as suggested in a comment - when
    the value-numbering run done without optimizing figures there's
    a fallthru path, consider blocks on it as always executed.
    
            PR tree-optimization/105646
            * tree-ssa-uninit.cc (warn_uninitialized_vars): Pre-compute
            the set of fallthru reachable blocks from function entry
            and use that to determine wlims.always_executed.
    
            * g++.dg/uninit-pr105646.C: New testcase.

Diff:
---
 gcc/testsuite/g++.dg/uninit-pr105646.C | 17 +++++++++++++++++
 gcc/tree-ssa-uninit.cc                 | 10 ++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/g++.dg/uninit-pr105646.C b/gcc/testsuite/g++.dg/uninit-pr105646.C
new file mode 100644
index 00000000000..48ceb986ec6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/uninit-pr105646.C
@@ -0,0 +1,17 @@
+// { dg-do compile }
+// { dg-require-effective-target c++11 }
+// { dg-options "-O2 -Wuninitialized" }
+
+int f1();
+int f2(){
+    bool v2{v2}; // { dg-warning "is used uninitialized" }
+    auto const & a = f1();
+    return a;
+}
+int f3(){
+    auto const & a = f1();
+    // Diagnose the following when optimizing and as unconditional
+    // uninitialized use despite f1 possibly throwing
+    bool v3{v3}; // { dg-warning "is used uninitialized" }
+    return a;
+}
diff --git a/gcc/tree-ssa-uninit.cc b/gcc/tree-ssa-uninit.cc
index eae29f88f9d..bde23997a0a 100644
--- a/gcc/tree-ssa-uninit.cc
+++ b/gcc/tree-ssa-uninit.cc
@@ -991,14 +991,20 @@ warn_uninitialized_vars (bool wmaybe_uninit)
   auto_bb_flag ft_reachable (cfun);
 
   /* Mark blocks that are always executed when we ignore provably
-     not executed edges.  */
+     not executed and EH and abnormal edges.  */
   basic_block bb = single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun));
   while (!(bb->flags & ft_reachable))
     {
       bb->flags |= ft_reachable;
+      edge e = find_fallthru_edge (bb->succs);
+      if (e && e->flags & EDGE_EXECUTABLE)
+	{
+	  bb = e->dest;
+	  continue;
+	}
       /* Find a single executable edge.  */
       edge_iterator ei;
-      edge e, ee = NULL;
+      edge ee = NULL;
       FOR_EACH_EDGE (e, ei, bb->succs)
 	if (e->flags & EDGE_EXECUTABLE)
 	  {

                 reply	other threads:[~2022-09-29  8:24 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=20220929082401.21C043858D28@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).