public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-3674] Correct a function pre/postcondition [PR102403].
@ 2021-09-19 23:23 Martin Sebor
  0 siblings, 0 replies; only message in thread
From: Martin Sebor @ 2021-09-19 23:23 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:825293da703aa1f7ce870b40afce91c1e8b6c0fa

commit r12-3674-g825293da703aa1f7ce870b40afce91c1e8b6c0fa
Author: Martin Sebor <msebor@redhat.com>
Date:   Sun Sep 19 17:18:48 2021 -0600

    Correct a function pre/postcondition [PR102403].
    
    Resolves:
    PR middle-end/102403 - ICE in init_from_control_deps, at gimple-predicate-analysis.cc:2364
    
    gcc/ChangeLog:
            PR middle-end/102403
            * gimple-predicate-analysis.cc (predicate::init_from_control_deps):
            Correct a function pre/postcondition.
    
    gcc/testsuite/ChangeLog:
            PR middle-end/102403
            * gcc.dg/uninit-pr102403.c: New test.
            * gcc.dg/uninit-pr102403-c2.c: New test.

Diff:
---
 gcc/gimple-predicate-analysis.cc          |  6 +++-
 gcc/testsuite/gcc.dg/uninit-pr102403-c2.c | 34 +++++++++++++++++++++
 gcc/testsuite/gcc.dg/uninit-pr102403.c    | 49 +++++++++++++++++++++++++++++++
 3 files changed, 88 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-predicate-analysis.cc b/gcc/gimple-predicate-analysis.cc
index 3404f2d630a..f0c84446194 100644
--- a/gcc/gimple-predicate-analysis.cc
+++ b/gcc/gimple-predicate-analysis.cc
@@ -2361,7 +2361,11 @@ predicate::init_from_control_deps (const vec<edge> *dep_chains,
       dump (NULL, "");
     }
 
-  gcc_assert (has_valid_pred == (m_preds.length () > 0));
+  if (has_valid_pred)
+    gcc_assert (m_preds.length () != 0);
+  else
+    /* Clear M_PREDS to indicate failure.  */
+    m_preds.release ();
 }
 
 /* Return the predicate expression guarding the definition of
diff --git a/gcc/testsuite/gcc.dg/uninit-pr102403-c2.c b/gcc/testsuite/gcc.dg/uninit-pr102403-c2.c
new file mode 100644
index 00000000000..81811432da5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/uninit-pr102403-c2.c
@@ -0,0 +1,34 @@
+/* PR middle-end/102403 - ICE in init_from_control_deps, at
+   gimple-predicate-analysis.cc:2364
+   { dg-do compile }
+   { dg-options "-O2 -Wall" } */
+
+extern int a[], b, c, d, e, f, g, h;
+
+inline void foo (void) { b = 1 ^ a[b ^ (c & 1)]; }
+
+void bar (void);
+
+int main (void)
+{
+  if (!f && ~h)
+    {
+      if (g)
+	goto L2;
+    }
+  else
+    {
+      int m = 0;              // { dg-message "declared here" }
+    L1:
+      e = m;
+    L2:
+      m ^= 1;                 // { dg-warning "-Wmaybe-uninitialized" }
+      if (d)
+	bar ();
+
+      for (int j = 0; j < 10; j++)
+	foo ();
+
+      goto L1;
+    }
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-pr102403.c b/gcc/testsuite/gcc.dg/uninit-pr102403.c
new file mode 100644
index 00000000000..1e62e988fd6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/uninit-pr102403.c
@@ -0,0 +1,49 @@
+/* PR middle-end/102403 - ICE in init_from_control_deps, at
+   gimple-predicate-analysis.cc:2364
+   { dg-do compile }
+   { dg-options "-O2 -Wall" } */
+
+int __fmaf (void)
+{
+  int a = 0;
+  int b, c, d, e, f;
+
+  int r = 0;
+
+  switch (b)        // { dg-warning "-Wuninitialized" }
+    {
+    default:
+      c |= 1;
+
+    case 0:
+      if (c == 0)
+	a = 1;
+
+      switch (d) {
+      case 15:
+	f = c;
+	break;
+
+      case 11:
+      case 6:
+      case 4:
+	f = c;
+      case 10:
+	e = a;
+      }
+
+      if (e == 0)   // { dg-warning "-Wmaybe-uninitialized" }
+  	f = 0;
+
+      r = f;
+  }
+
+  // The return statement below gets the unhelpful warning:
+  // 'f' may be used uninitialized in this function [-Wmaybe-uninitialized]
+  return r;
+}
+
+/* Prune out warnings issued on the wrong lines, such as:
+   uninit-pr102403.c:9:13: warning: ‘d’ is used uninitialized [-Wuninitialized]
+   { dg-prune-output "-Wuninitialized" }
+   { dg-prune-output "-Wmaybe-uninitialized" } */


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-19 23:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-19 23:23 [gcc r12-3674] Correct a function pre/postcondition [PR102403] Martin Sebor

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).