Hi,
in the testcase we fail to analyze SSA name because flag do_dataflow is set
and thus triggers early exist in analyze_ssa_name.  Fixed by disabling
early exits when handling deferred names.

Bootstrapped/regtested x86_64-linux, comitted.

gcc/ChangeLog:

2021-12-20  Jan Hubicka  <hubi...@ucw.cz>

        PR ipa/103669
        * ipa-modref.c (modref_eaf_analysis::analyze_ssa_name): Add deferred
        parameter.
        (modref_eaf_analysis::propagate): Use it.

gcc/testsuite/ChangeLog:

2021-12-20  Jan Hubicka  <hubi...@ucw.cz>

        PR ipa/103669
        * g++.dg/torture/pr103669.C: New test.

diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c
index 9c411a6297a..733fc212fcc 100644
--- a/gcc/ipa-modref.c
+++ b/gcc/ipa-modref.c
@@ -2232,7 +2232,7 @@ class modref_eaf_analysis
 {
 public:
   /* Mark NAME as relevant for analysis.  */
-  void analyze_ssa_name (tree name);
+  void analyze_ssa_name (tree name, bool deferred = false);
   /* Dataflow slover.  */
   void propagate ();
   /* Return flags computed earlier for NAME.  */
@@ -2373,33 +2373,36 @@ callee_to_caller_flags (int call_flags, bool 
ignore_stores,
    are processed later)  */
 
 void
-modref_eaf_analysis::analyze_ssa_name (tree name)
+modref_eaf_analysis::analyze_ssa_name (tree name, bool deferred)
 {
   imm_use_iterator ui;
   gimple *use_stmt;
   int index = SSA_NAME_VERSION (name);
 
-  /* See if value is already computed.  */
-  if (m_lattice[index].known || m_lattice[index].do_dataflow)
-   return;
-  if (m_lattice[index].open)
+  if (!deferred)
     {
-      if (dump_file)
-       fprintf (dump_file,
-                "%*sCycle in SSA graph\n",
-                m_depth * 4, "");
-      return;
-    }
-  /* Recursion guard.  */
-  m_lattice[index].init ();
-  if (m_depth == param_modref_max_depth)
-    {
-      if (dump_file)
-       fprintf (dump_file,
-                "%*sMax recursion depth reached; postponing\n",
-                m_depth * 4, "");
-      m_deferred_names.safe_push (name);
-      return;
+      /* See if value is already computed.  */
+      if (m_lattice[index].known || m_lattice[index].do_dataflow)
+       return;
+      if (m_lattice[index].open)
+       {
+         if (dump_file)
+           fprintf (dump_file,
+                    "%*sCycle in SSA graph\n",
+                    m_depth * 4, "");
+         return;
+       }
+      /* Recursion guard.  */
+      m_lattice[index].init ();
+      if (m_depth == param_modref_max_depth)
+       {
+         if (dump_file)
+           fprintf (dump_file,
+                    "%*sMax recursion depth reached; postponing\n",
+                    m_depth * 4, "");
+         m_deferred_names.safe_push (name);
+         return;
+       }
     }
 
   if (dump_file)
@@ -2742,10 +2745,9 @@ modref_eaf_analysis::propagate ()
   while (m_deferred_names.length ())
     {
       tree name = m_deferred_names.pop ();
-      m_lattice[SSA_NAME_VERSION (name)].open = false;
       if (dump_file)
        fprintf (dump_file, "Analyzing deferred SSA name\n");
-      analyze_ssa_name (name);
+      analyze_ssa_name (name, true);
     }
 
   if (!m_names_to_propagate.length ())
diff --git a/gcc/testsuite/g++.dg/torture/pr103669.C 
b/gcc/testsuite/g++.dg/torture/pr103669.C
new file mode 100644
index 00000000000..a9509c354f1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr103669.C
@@ -0,0 +1,22 @@
+// { dg-do run }
+/* { dg-additional-options "--param=modref-max-depth=1" } */
+#include <list>
+
+typedef std::list<void *> PtrList;
+
+void
+SlList (PtrList *l)
+{
+  PtrList temp = *l;
+  PtrList::iterator iter;
+  for (iter = temp.begin (); iter != temp.end (); ++iter)
+    __builtin_abort ();
+}
+
+int
+main (void)
+{
+  PtrList list;
+  SlList (&list);
+  return 0;
+}

Reply via email to