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-2310] tree-optimization/90994 - fix uninit diagnostics with EH
Date: Wed, 31 Aug 2022 13:20:50 +0000 (GMT)	[thread overview]
Message-ID: <20220831132050.B18F438582A7@sourceware.org> (raw)

https://gcc.gnu.org/g:88f29a8aa82f2788baf2f9865940d4c83012c580

commit r13-2310-g88f29a8aa82f2788baf2f9865940d4c83012c580
Author: Richard Biener <rguenther@suse.de>
Date:   Wed Aug 31 14:04:46 2022 +0200

    tree-optimization/90994 - fix uninit diagnostics with EH
    
    r12-3640-g94c12ffac234b2 sneaked in a hack to avoid the diagnostic
    for the testcase in PR90994 which sees non-call EH control flow
    confusing predicate analysis.  The following patch instead adjusts
    the existing code handling EH to handle non-calls and do what I
    think was intented.
    
            PR tree-optimization/90994
            * gimple-predicate-analysis.cc (predicate::init_from_control_deps):
            Ignore exceptional control flow and skip the edge for the purpose of
            predicate generation also for non-calls.
    
            * g++.dg/torture/pr90994.C: New testcase.

Diff:
---
 gcc/gimple-predicate-analysis.cc       | 13 ++++++-----
 gcc/testsuite/g++.dg/torture/pr90994.C | 40 ++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/gcc/gimple-predicate-analysis.cc b/gcc/gimple-predicate-analysis.cc
index 49500b77832..58eade433dc 100644
--- a/gcc/gimple-predicate-analysis.cc
+++ b/gcc/gimple-predicate-analysis.cc
@@ -41,6 +41,7 @@
 #include "calls.h"
 #include "value-query.h"
 #include "cfganal.h"
+#include "tree-eh.h"
 
 #include "gimple-predicate-analysis.h"
 
@@ -1709,9 +1710,6 @@ predicate::init_from_control_deps (const vec<edge> *dep_chains,
 	    }
 	  /* Get the conditional controlling the bb exit edge.  */
 	  gimple *cond_stmt = gsi_stmt (gsi);
-	  if (is_gimple_call (cond_stmt) && EDGE_COUNT (e->src->succs) >= 2)
-	    /* Ignore EH edge.  Can add assertion on the other edge's flag.  */
-	    continue;
 	  /* Skip this edge if it is bypassing an abort - when the
 	     condition is not satisfied we are neither reaching the
 	     definition nor the use so it isn't meaningful.  Note if
@@ -1819,10 +1817,15 @@ predicate::init_from_control_deps (const vec<edge> *dep_chains,
 		  has_valid_pred = true;
 		}
 	    }
+	  else if (stmt_can_throw_internal (cfun, cond_stmt)
+		   && !(e->flags & EDGE_EH))
+	    /* Ignore the exceptional control flow and proceed as if
+	       E were a fallthru without a controlling predicate for
+	       both the USE (valid) and DEF (questionable) case.  */
+	    has_valid_pred = true;
 	  else
 	    {
-	      /* Disabled.  See PR 90994.
-		 has_valid_pred = false;  */
+	      has_valid_pred = false;
 	      break;
 	    }
 	}
diff --git a/gcc/testsuite/g++.dg/torture/pr90994.C b/gcc/testsuite/g++.dg/torture/pr90994.C
new file mode 100644
index 00000000000..8feb36f2361
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr90994.C
@@ -0,0 +1,40 @@
+// { dg-do compile }
+// { dg-additional-options "-fnon-call-exceptions -Wuninitialized" }
+
+extern void printval(unsigned char v);
+
+inline int readbyte(unsigned char *__restrict presult,
+		    unsigned char volatile *ptr)
+{
+  unsigned char v;
+  try {
+      v = *ptr;
+  } catch (...) {
+      return -1;
+  }
+  *presult = v;
+  return 0;
+}
+
+int incorrectWarning(unsigned char volatile *ptr)
+{
+  int error;
+  unsigned char first;
+  unsigned char second;
+
+  error = readbyte(&first, ptr);
+  asm("\n\n\n\n\n" : : "X" (error != 0));
+  if (error != 0)
+    goto err;
+
+  error = readbyte(&second, ptr);
+  if (error != 0)
+    goto err;
+
+  printval(first);   // { dg-bogus "uninitialized" }
+  printval(second);
+  return 0;
+
+err:
+  return error;
+}

                 reply	other threads:[~2022-08-31 13:20 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=20220831132050.B18F438582A7@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).