public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-2334] analyzer: handle self-referential phis
@ 2021-07-15 19:02 David Malcolm
0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2021-07-15 19:02 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:a9241df96e1950c630550ada9371c0b4a03496cf
commit r12-2334-ga9241df96e1950c630550ada9371c0b4a03496cf
Author: David Malcolm <dmalcolm@redhat.com>
Date: Thu Jul 15 15:01:57 2021 -0400
analyzer: handle self-referential phis
gcc/analyzer/ChangeLog:
* state-purge.cc (self_referential_phi_p): New.
(state_purge_per_ssa_name::process_point): Don't purge an SSA name
at its def-stmt if the def-stmt is self-referential.
gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/phi-1.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diff:
---
gcc/analyzer/state-purge.cc | 37 ++++++++++++++++++++++++++++++++---
gcc/testsuite/gcc.dg/analyzer/phi-1.c | 24 +++++++++++++++++++++++
2 files changed, 58 insertions(+), 3 deletions(-)
diff --git a/gcc/analyzer/state-purge.cc b/gcc/analyzer/state-purge.cc
index 70a09ed581f..e82ea87e735 100644
--- a/gcc/analyzer/state-purge.cc
+++ b/gcc/analyzer/state-purge.cc
@@ -288,6 +288,20 @@ state_purge_per_ssa_name::add_to_worklist (const function_point &point,
}
}
+/* Does this phi depend on itself?
+ e.g. in:
+ added_2 = PHI <added_6(2), added_2(3), added_11(4)>
+ the middle defn (from edge 3) requires added_2 itself. */
+
+static bool
+self_referential_phi_p (const gphi *phi)
+{
+ for (unsigned i = 0; i < gimple_phi_num_args (phi); i++)
+ if (gimple_phi_arg_def (phi, i) == gimple_phi_result (phi))
+ return true;
+ return false;
+}
+
/* Process POINT, popped from WORKLIST.
Iterate over predecessors of POINT, adding to WORKLIST. */
@@ -326,11 +340,28 @@ state_purge_per_ssa_name::process_point (const function_point &point,
!gsi_end_p (gpi); gsi_next (&gpi))
{
gphi *phi = gpi.phi ();
+ /* Are we at the def-stmt for m_name? */
if (phi == def_stmt)
{
- if (logger)
- logger->log ("def stmt within phis; terminating");
- return;
+ /* Does this phi depend on itself?
+ e.g. in:
+ added_2 = PHI <added_6(2), added_2(3), added_11(4)>
+ the middle defn (from edge 3) requires added_2 itself
+ so we can't purge it here. */
+ if (self_referential_phi_p (phi))
+ {
+ if (logger)
+ logger->log ("self-referential def stmt within phis;"
+ " continuing");
+ }
+ else
+ {
+ /* Otherwise, we can stop here, so that m_name
+ can be purged. */
+ if (logger)
+ logger->log ("def stmt within phis; terminating");
+ return;
+ }
}
}
diff --git a/gcc/testsuite/gcc.dg/analyzer/phi-1.c b/gcc/testsuite/gcc.dg/analyzer/phi-1.c
new file mode 100644
index 00000000000..09260033fef
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/phi-1.c
@@ -0,0 +1,24 @@
+/* { dg-do "compile" } */
+
+typedef __SIZE_TYPE__ size_t;
+#define NULL ((void *) 0)
+
+extern const char *foo (void);
+extern size_t bar (void);
+
+void
+_nl_expand_alias (const char *locale_alias_path)
+{
+ size_t added;
+ do
+ {
+ added = 0;
+ while (added == 0 && locale_alias_path[0] != '\0')
+ {
+ const char *start = foo ();
+ if (start < locale_alias_path)
+ added = bar ();
+ }
+ }
+ while (added != 0);
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-07-15 19:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-15 19:02 [gcc r12-2334] analyzer: handle self-referential phis David Malcolm
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).