From 8ff08a2337dbed86822e7ca803e2181f5054ed75 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Mon, 1 Jul 2019 12:58:21 -0400
Subject: [PATCH 54/85] FIXME: more test coverage

---
 gcc/testsuite/gcc.dg/analyzer/loop-2.c  |  8 +++++-
 gcc/testsuite/gcc.dg/analyzer/loop.c    | 14 +++++++--
 gcc/testsuite/gcc.dg/analyzer/paths-4.c | 51 +++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/paths-4.c

diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-2.c b/gcc/testsuite/gcc.dg/analyzer/loop-2.c
index 444b7c3..589b78d 100644
--- a/gcc/testsuite/gcc.dg/analyzer/loop-2.c
+++ b/gcc/testsuite/gcc.dg/analyzer/loop-2.c
@@ -7,7 +7,7 @@
 
    So we need something smarter to cope with this case.  */
 
-/* { dg-additional-options "-fno-analyzer-state-purge" } */
+/* { dg-additional-options "-fno-analyzer-state-purge -fanalyzer-state-merge" } */
 
 struct s
 {
@@ -18,6 +18,9 @@ void test(void)
 {
   struct s s;
 
+  __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 exploded node" } */
+
+
   for (s.i=0; s.i<256; s.i++) { /* { dg-warning "analysis bailed out early" } */
     //__analyzer_eval (s.i < 256); /* { d-todo-g-warning "TRUE" } */
 
@@ -33,4 +36,7 @@ void test(void)
   //__analyzer_eval (s.i == 256); /* { d-todo-g-warning "TRUE" "" { xfail *-*-* } } */
   /* { d-todo-g-warning "UNKNOWN" "" { target *-*-* } .-1 } */
   /* TODO(xfail^^^): it only figures out i >= 256, rather than i == 256.  */
+
+  __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 exploded node" "" { xfail *-*-* } } */
+  // FIXME: it bails out before making it this far
 }
diff --git a/gcc/testsuite/gcc.dg/analyzer/loop.c b/gcc/testsuite/gcc.dg/analyzer/loop.c
index aeba702..839e6b2 100644
--- a/gcc/testsuite/gcc.dg/analyzer/loop.c
+++ b/gcc/testsuite/gcc.dg/analyzer/loop.c
@@ -1,10 +1,12 @@
 // FIXME:
-/* { dg-additional-options "-fno-analyzer-state-purge" } */
+/* { dg-additional-options "-fno-analyzer-state-purge -fanalyzer-state-merge" } */
 
 void test(void)
 {
   int i;
 
+  __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 exploded node" } */
+
   for (i=0; i<256; i++) {
       __analyzer_eval (i < 256); /* { dg-warning "TRUE" } */
 
@@ -14,10 +16,18 @@ void test(void)
 	 we erroneously get i == 0.  */
 
       __analyzer_eval (i >= 0); /* { dg-warning "TRUE" } */
+
+      __analyzer_dump_exploded_nodes (0); /* { dg-warning "3 exploded nodes" } */
+      // FIXME: why 3 nodes here?
   }
 
-  __analyzer_eval (i >= 256); /* { dg-warning "TRUE" } */
+  __analyzer_eval (i >= 256); /* { dg-warning "TRUE" "" { xfail *-*-* } } */
+  /* { dg-warning "UNKNOWN" "" { target *-*-* } .-1 } */
+  /* TODO(xfail^^^): with state-merging, this becomes unknown; why?  */
+
   __analyzer_eval (i == 256); /* { dg-warning "TRUE" "" { xfail *-*-* } } */
   /* { dg-warning "UNKNOWN" "" { target *-*-* } .-1 } */
   /* TODO(xfail^^^): it only figures out i >= 256, rather than i == 256.  */
+
+  __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 exploded node" } */
 }
diff --git a/gcc/testsuite/gcc.dg/analyzer/paths-4.c b/gcc/testsuite/gcc.dg/analyzer/paths-4.c
new file mode 100644
index 0000000..c1e3ee5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/paths-4.c
@@ -0,0 +1,51 @@
+/* { dg-additional-options "-fanalyzer-state-merge" } */
+
+struct state
+{
+  int mode;
+  int data;
+};
+
+extern void do_stuff (struct state *, int);
+
+int test_1 (struct state *s)
+{
+  __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 exploded node" } */
+  while (1)
+    {
+      __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 exploded nodes" } */
+      __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 exploded nodes" } */
+      do_stuff (s, s->mode);
+    }
+}
+
+int test_2 (struct state *s)
+{
+  __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 exploded node" } */
+  while (1)
+    {
+      __analyzer_dump_exploded_nodes (0); /* { dg-warning "5 exploded nodes" } */
+      __analyzer_dump_exploded_nodes (0); /* { dg-warning "5 exploded nodes" } */
+      switch (s->mode)
+	{
+	case 0:
+	  __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 exploded nodes" } */
+	  do_stuff (s, 0);
+	  break;
+	case 1:
+	  __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 exploded nodes" } */
+	  do_stuff (s, 17);
+	  break;
+	case 2:
+	  __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 exploded nodes" } */
+	  do_stuff (s, 5);
+	  break;
+	case 3:
+	  __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 exploded node" } */
+	  return 42;
+	case 4:
+	  __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 exploded node" } */
+	  return -3;
+	}
+    }
+}
-- 
1.8.5.3

