analyzer: fix ICE with equiv_class constant (PR 93649)
authorDavid Malcolm <dmalcolm@redhat.com>
Mon, 10 Feb 2020 21:47:21 +0000 (16:47 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Tue, 11 Feb 2020 18:32:51 +0000 (13:32 -0500)
gcc/analyzer/ChangeLog:
PR analyzer/93649
* constraint-manager.cc (constraint_manager::add_constraint): When
merging equivalence classes and updating m_constant, also update
m_cst_sid.
(constraint_manager::validate): If m_constant is non-NULL assert
that m_cst_sid is non-null and is valid.

gcc/testsuite/ChangeLog:
PR analyzer/93649
* gcc.dg/analyzer/torture/pr93649.c: New test.

gcc/analyzer/ChangeLog
gcc/analyzer/constraint-manager.cc
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/analyzer/torture/pr93649.c [new file with mode: 0644]

index df04b028b9b8607ad6f2e0774cf763c55750f8c3..38afa69da648a151b45a3f050e65a97281fb5352 100644 (file)
@@ -1,3 +1,12 @@
+2020-02-11  David Malcolm  <dmalcolm@redhat.com>
+
+       PR analyzer/93649
+       * constraint-manager.cc (constraint_manager::add_constraint): When
+       merging equivalence classes and updating m_constant, also update
+       m_cst_sid.
+       (constraint_manager::validate): If m_constant is non-NULL assert
+       that m_cst_sid is non-null and is valid.
+
 2020-02-11  David Malcolm  <dmalcolm@redhat.com>
 
        PR analyzer/93657
index d5a6939e7144eeb30092988647ceabcff13fe5e0..a62354356816da896382f92fc0cb3d20d8764422 100644 (file)
@@ -686,8 +686,8 @@ constraint_manager::add_constraint (equiv_class_id lhs_ec_id,
 
        if (rhs_ec_obj.m_constant)
          {
-           //gcc_assert (lhs_ec_obj.m_constant == NULL);
            lhs_ec_obj.m_constant = rhs_ec_obj.m_constant;
+           lhs_ec_obj.m_cst_sid = rhs_ec_obj.m_cst_sid;
          }
 
        /* Drop rhs equivalence class, overwriting it with the
@@ -1516,7 +1516,11 @@ constraint_manager::validate () const
          gcc_assert (sid->as_int () < get_num_svalues ());
        }
       if (ec->m_constant)
-       gcc_assert (CONSTANT_CLASS_P (ec->m_constant));
+       {
+         gcc_assert (CONSTANT_CLASS_P (ec->m_constant));
+         gcc_assert (!ec->m_cst_sid.null_p ());
+         gcc_assert (ec->m_cst_sid.as_int () < get_num_svalues ());
+       }
 #if 0
       else
        gcc_assert (ec->m_vars.length () > 0);
index 27aa4ac1cc5a43cef25f3159ea7e272e17edaa2a..2ca519c51c410fd839c38da12025d1a80516d0a5 100644 (file)
@@ -1,3 +1,8 @@
+2020-02-11  David Malcolm  <dmalcolm@redhat.com>
+
+       PR analyzer/93649
+       * gcc.dg/analyzer/torture/pr93649.c: New test.
+
 2020-02-11  Will Schmidt  <will_schmidt@vnet.ibm.com>
 
        * gcc.target/powerpc/pr70010-2.c: Add -maltivec.
diff --git a/gcc/testsuite/gcc.dg/analyzer/torture/pr93649.c b/gcc/testsuite/gcc.dg/analyzer/torture/pr93649.c
new file mode 100644 (file)
index 0000000..9d92939
--- /dev/null
@@ -0,0 +1,66 @@
+/* { dg-additional-options "-Wno-incompatible-pointer-types -Wno-analyzer-too-complex" } */
+/* TODO: ideally we shouldn't have -Wno-analyzer-too-complex above; it
+   appears to be needed due to the recursion.  */
+
+struct tz {
+  int qc;
+};
+
+struct wp {
+  struct tz *p2;
+} *ov;
+
+struct dz {
+  struct wp *r5;
+};
+
+void
+za (void);
+
+void
+h5 (struct dz *);
+
+int
+e7 (struct wp *f2)
+{
+  return f2 == ov;
+}
+
+void
+wr (struct wp *sw)
+{
+  if (sw != 0)
+    za ();
+}
+
+void
+m6 (const struct dz *gq)
+{
+  wr (gq->r5);
+
+  asm ("" : "+m" (gq));
+
+  if (0)
+    {
+      asm ("" : "+m" (gq->r5->p2->qc));
+      asm ("" : "+m" (gq->r5->p2->qc));
+    }
+
+  asm ("" : "+m" (gq->r5->p2->qc));
+
+  if (e7 (gq->r5))
+    za ();
+}
+
+void
+ts (struct dz *cx)
+{
+  struct dz nt;
+
+  if (nt.r5)
+    {
+      m6 (cx);
+      h5 (cx);
+      ts (&cx);
+    }
+}