From df97f5bd472b0cd5368229e7f408f946b994686c Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 16 Jul 2020 17:19:45 -0400
Subject: [PATCH 309/315] FIXME: various cleanups and XFAILs for loop tests

---
 gcc/analyzer/region-model2.cc                 |  2 +-
 .../loop-0-up-to-n-by-1-with-iter-obj.c       | 45 +++++++++++--------
 .../gcc.dg/analyzer/loop-0-up-to-n-by-1.c     | 15 +++----
 gcc/testsuite/gcc.dg/analyzer/loop-4.c        | 13 +++---
 .../gcc.dg/analyzer/loop-n-down-to-1-by-1.c   | 12 +++--
 .../analyzer/loop-start-down-to-end-by-1.c    | 14 +++---
 .../analyzer/loop-start-down-to-end-by-step.c | 19 ++++----
 .../analyzer/loop-start-to-end-by-step.c      | 13 +++---
 .../analyzer/loop-start-up-to-end-by-1.c      | 16 ++++---
 9 files changed, 76 insertions(+), 73 deletions(-)

diff --git a/gcc/analyzer/region-model2.cc b/gcc/analyzer/region-model2.cc
index 924b74b1d56..0faced37619 100644
--- a/gcc/analyzer/region-model2.cc
+++ b/gcc/analyzer/region-model2.cc
@@ -266,7 +266,7 @@ svalue2::unwrap_any_unmergeable () const
   return this;
 }
 
-/* FIXME.
+/* Attempt to merge THIS with OTHER, returning the merged svalue2.
    Return NULL if not mergeable.  */
 
 const svalue2 *
diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-0-up-to-n-by-1-with-iter-obj.c b/gcc/testsuite/gcc.dg/analyzer/loop-0-up-to-n-by-1-with-iter-obj.c
index 7871a8462ec..0172c9b324c 100644
--- a/gcc/testsuite/gcc.dg/analyzer/loop-0-up-to-n-by-1-with-iter-obj.c
+++ b/gcc/testsuite/gcc.dg/analyzer/loop-0-up-to-n-by-1-with-iter-obj.c
@@ -1,4 +1,4 @@
-/* { dg-additional-options "-fno-analyzer-state-purge" } */
+#include <stdlib.h>
 
 #include "analyzer-decls.h"
 
@@ -6,15 +6,19 @@ struct iter
 {
   int start;
   int end;
+  int step;
   int val;
 };
 
 struct iter *  __attribute__((noinline))
-iter_new (int start, int end)
+iter_new (int start, int end, int step)
 {
   struct iter *it = (struct iter *)malloc (sizeof (struct iter));
+  if (!it)
+    abort ();
   it->start = start;
   it->end = end;
+  it->step = step;
   it->val = start;
   return it;
 }
@@ -25,36 +29,41 @@ iter_done_p (struct iter *it)
   return it->val >= it->end;
 }
 
-// FIXME: WIP example of an iterator object, to see how well we cope
+void __attribute__((noinline))
+iter_next (struct iter *it)
+{
+  it->val += it->step;
+}
+
+/* Example of an iterator object, to see how well we cope with a well-disguised
+   iteration from 0 to n with a step of 1.  */
 
 void test(int n)
 {
-  int i;
-
   __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
 
-  struct iter *it = iter_new (0, n);
+  struct iter *it = iter_new (0, n, 1);
   while (!iter_done_p (it))
     {
-      __analyzer_eval (i < n); /* { dg-warning "TRUE" } */
-      /* (should report TRUE twice). */
-
-      __analyzer_eval (i == 0); /* { dg-warning "TRUE" "1st" } */
-      /* { dg-warning "FALSE" "2nd" { xfail *-*-* } .-1 } */
-      /* { dg-warning "UNKNOWN" "status quo" { target *-*-* } .-2 } */
+      __analyzer_eval (it->val < n); /* { dg-warning "TRUE" "true" { xfail *-*-* } } */
+      /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
       /* TODO(xfail^^^): ideally we ought to figure out i > 0 after 1st iteration.  */
 
-      __analyzer_eval (i >= 0); /* { dg-warning "TRUE" "1st" } */
-      /* { dg-warning "TRUE" "2nd" { xfail *-*-* } } */
-      /* { dg-warning "UNKNOWN" "status quo" { target *-*-* } .-2 } */
-      /* TODO(xfail^^^): ideally we ought to figure out i >= 0 for all iterations.  */
+      __analyzer_eval (it->val == 0); /* { dg-warning "TRUE" "true on 1st iter" } */
+      /* { dg-warning "UNKNOWN" "unknown" { target *-*-* } .-1 } */
+      /* TODO: should we ought to figure out i > 0 after 1st iteration?  */
+
+      __analyzer_eval (it->val >= 0); /* { dg-warning "TRUE" } */
 
       __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
+
+      iter_next (it);
     }
 
-  __analyzer_eval (i >= n); /* { dg-warning "TRUE" } */
+  __analyzer_eval (it->val >= n); /* { dg-warning "TRUE" "true" { xfail *-*-* } } */
+  /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
 
-  __analyzer_eval (i == n); /* { dg-warning "TRUE" "desired" { xfail *-*-* } } */
+  __analyzer_eval (it->val == n); /* { dg-warning "TRUE" "desired" { xfail *-*-* } } */
   /* { dg-warning "UNKNOWN" "status quo" { target *-*-* } .-1 } */
   /* TODO(xfail^^^): it only figures out i >= 256, rather than i == 256.  */
 
diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-0-up-to-n-by-1.c b/gcc/testsuite/gcc.dg/analyzer/loop-0-up-to-n-by-1.c
index 8295502dd05..31bdbe6a9c5 100644
--- a/gcc/testsuite/gcc.dg/analyzer/loop-0-up-to-n-by-1.c
+++ b/gcc/testsuite/gcc.dg/analyzer/loop-0-up-to-n-by-1.c
@@ -1,6 +1,3 @@
-/* { dg-additional-options "-fno-analyzer-state-purge" } */
-// FIXME: ^^^ review all of these
-
 #include "analyzer-decls.h"
 
 // FIXME
@@ -20,18 +17,16 @@ void test(int n)
       /* { dg-warning "UNKNOWN" "status quo" { target *-*-* } .-2 } */
       /* TODO(xfail^^^): ideally we ought to figure out i > 0 after 1st iteration.  */
 
-      __analyzer_eval (i >= 0); /* { dg-warning "TRUE" "1st" } */
-      /* { dg-warning "TRUE" "2nd" { xfail *-*-* } } */
-      /* { dg-warning "UNKNOWN" "status quo" { target *-*-* } .-2 } */
-      /* TODO(xfail^^^): ideally we ought to figure out i >= 0 for all iterations.  */
+      __analyzer_eval (i >= 0); /* { dg-warning "TRUE" } */
 
       __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
   }
 
-  __analyzer_eval (i >= n); /* { dg-warning "TRUE" } */
+  __analyzer_eval (i >= n); /* { dg-warning "TRUE" "true" { xfail *-*-* } } */
+  /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
 
-  __analyzer_eval (i == n); /* { dg-warning "TRUE" "desired" { xfail *-*-* } } */
-  /* { dg-warning "UNKNOWN" "status quo" { target *-*-* } .-1 } */
+  __analyzer_eval (i == n); /* { dg-warning "TRUE" "true" { xfail *-*-* } } */
+  /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
   /* TODO(xfail^^^): it only figures out i >= 256, rather than i == 256.  */
 
   __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-4.c b/gcc/testsuite/gcc.dg/analyzer/loop-4.c
index e5767de1f96..b66a3459437 100644
--- a/gcc/testsuite/gcc.dg/analyzer/loop-4.c
+++ b/gcc/testsuite/gcc.dg/analyzer/loop-4.c
@@ -1,6 +1,3 @@
-// FIXME:
-/* { dg-additional-options "-fno-analyzer-state-purge" } */
-
 /* Example of nested loops.  */
 
 #include "analyzer-decls.h"
@@ -13,8 +10,7 @@ void test(void)
 
   for (i=0; i<256; i++) {
 
-    __analyzer_eval (i >= 0); /* { dg-warning "TRUE" "true" } */
-      /* { dg-warning "UNKNOWN" "unknown" { target *-*-* } .-1 } */
+    __analyzer_eval (i >= 0); /* { dg-warning "TRUE" } */
 
     __analyzer_eval (i < 256); /* { dg-warning "TRUE" } */
 
@@ -23,7 +19,9 @@ void test(void)
       __analyzer_eval (j >= 0); /* { dg-warning "TRUE" "true" } */
       /* { dg-warning "UNKNOWN" "unknown" { target *-*-* } .-1 } */
 
-      __analyzer_eval (j < 256); /* { dg-warning "TRUE" } */
+      __analyzer_eval (j < 256); /* { dg-warning "TRUE" "true" } */
+      /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
+      /* TODO(xfail^^^): should report TRUE twice. */
 
       __analyzer_dump_exploded_nodes (0); /* { dg-warning "3 processed enodes" } */
 
@@ -32,7 +30,8 @@ void test(void)
 	__analyzer_eval (k >= 0); /* { dg-warning "TRUE" "true" } */
 	/* { dg-warning "UNKNOWN" "unknown" { target *-*-* } .-1 } */
 
-	__analyzer_eval (k < 256); /* { dg-warning "TRUE" } */
+	__analyzer_eval (k < 256); /* { dg-warning "TRUE" "true" } */
+	/* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
 
 	__analyzer_dump_exploded_nodes (0); /* { dg-warning "4 processed enodes" } */
       }
diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-n-down-to-1-by-1.c b/gcc/testsuite/gcc.dg/analyzer/loop-n-down-to-1-by-1.c
index d0634c36b1e..e02a849d4bb 100644
--- a/gcc/testsuite/gcc.dg/analyzer/loop-n-down-to-1-by-1.c
+++ b/gcc/testsuite/gcc.dg/analyzer/loop-n-down-to-1-by-1.c
@@ -1,9 +1,5 @@
-/* { dg-additional-options "-fno-analyzer-state-purge" } */
-
 #include "analyzer-decls.h"
 
-// FIXME
-
 void test(int n)
 {
   int i;
@@ -11,8 +7,9 @@ void test(int n)
   __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
 
   for (i = n; i > 0; i--) {
-      __analyzer_eval (i > 0); /* { dg-warning "TRUE" } */
-      /* (should report TRUE twice). */
+      __analyzer_eval (i > 0); /* { dg-warning "TRUE" "true" } */
+      /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
+      /* TODO(xfail^^^): should report TRUE twice. */
 
       __analyzer_eval (i == n); /* { dg-warning "TRUE" "1st" } */
       /* { dg-warning "FALSE" "2nd" { xfail *-*-* } .-1 } */
@@ -27,7 +24,8 @@ void test(int n)
       __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
   }
 
-  __analyzer_eval (i <= 0); /* { dg-warning "TRUE" } */
+  __analyzer_eval (i <= 0); /* { dg-warning "TRUE" "true" { xfail *-*-* } } */
+  /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
 
   __analyzer_eval (i == 0); /* { dg-warning "TRUE" "desired" { xfail *-*-* } } */
   /* { dg-warning "UNKNOWN" "status quo" { target *-*-* } .-1 } */
diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-start-down-to-end-by-1.c b/gcc/testsuite/gcc.dg/analyzer/loop-start-down-to-end-by-1.c
index 45c5188a2db..3513bf42347 100644
--- a/gcc/testsuite/gcc.dg/analyzer/loop-start-down-to-end-by-1.c
+++ b/gcc/testsuite/gcc.dg/analyzer/loop-start-down-to-end-by-1.c
@@ -1,7 +1,5 @@
 #include "analyzer-decls.h"
 
-// TODO: not sure what the __analyzer_eval should do
-
 void test(int start, int end, int step)
 {
   int i;
@@ -9,20 +7,24 @@ void test(int start, int end, int step)
   __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
 
   for (i = start; i > end; i --) {
-      __analyzer_eval (i > end); /* { dg-warning "TRUE" } */
-      /* (should report TRUE twice). */
+      __analyzer_eval (i > end); /* { dg-warning "TRUE" "true" } */
+      /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
+      /* TODO(xfail^^^): should report TRUE twice. */
 
       __analyzer_eval (i == start); /* { dg-warning "TRUE" "1st" } */
       /* { dg-warning "FALSE" "2nd" { xfail *-*-* } .-1 } */
       /* { dg-warning "UNKNOWN" "status quo" { target *-*-* } .-2 } */
       /* TODO(xfail^^^): ideally we ought to figure out i > 0 after 1st iteration.  */
 
-      __analyzer_eval (i <= start); /* { dg-warning "UNKNOWN" } */
+      __analyzer_eval (i <= start); /* { dg-warning "TRUE" "true" } */
+      /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
+      /* TODO(xfail^^^): should report TRUE twice. */
 
       __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
   }
 
-  __analyzer_eval (i >= end); /* { dg-warning "TRUE" } */
+  __analyzer_eval (i >= end); /* { dg-warning "TRUE" "true" { xfail *-*-* } } */
+  /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
 
   // FIXME: do we know this?  What if we overshoot?
   __analyzer_eval (i == end); /* { dg-warning "TRUE" "desired" { xfail *-*-* } } */
diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-start-down-to-end-by-step.c b/gcc/testsuite/gcc.dg/analyzer/loop-start-down-to-end-by-step.c
index c06cc4fa8b2..2692c503b5c 100644
--- a/gcc/testsuite/gcc.dg/analyzer/loop-start-down-to-end-by-step.c
+++ b/gcc/testsuite/gcc.dg/analyzer/loop-start-down-to-end-by-step.c
@@ -1,7 +1,5 @@
 #include "analyzer-decls.h"
 
-// TODO: not sure what the __analyzer_eval should do
-
 void test(int start, int end, int step)
 {
   int i;
@@ -9,25 +7,24 @@ void test(int start, int end, int step)
   __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
 
   for (i = start; i > end; i -= step) {
-      __analyzer_eval (i > end); /* { dg-warning "TRUE" } */
-      /* (should report TRUE twice). */
+      __analyzer_eval (i > end); /* { dg-warning "TRUE" "true" } */
+      /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
+      /* TODO(xfail^^^): should report TRUE twice. */
 
       __analyzer_eval (i == start); /* { dg-warning "TRUE" "1st" } */
       /* { dg-warning "FALSE" "2nd" { xfail *-*-* } .-1 } */
       /* { dg-warning "UNKNOWN" "status quo" { target *-*-* } .-2 } */
       /* TODO(xfail^^^): ideally we ought to figure out i > 0 after 1st iteration.  */
 
-      __analyzer_eval (i <= start); /* { dg-warning "UNKNOWN" } */
+      /* We don't know the direction of step.  */
+      __analyzer_eval (i <= start); /* { dg-warning "TRUE" "true" } */
+      /* { dg-warning "UNKNOWN" "unknown" { target *-*-* } .-1 } */
 
       __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
   }
 
-  __analyzer_eval (i >= end); /* { dg-warning "TRUE" } */
-
-  // FIXME: do we know this?  What if we overshoot?
-  __analyzer_eval (i == end); /* { dg-warning "TRUE" "desired" { xfail *-*-* } } */
-  /* { dg-warning "UNKNOWN" "status quo" { target *-*-* } .-1 } */
-  /* TODO(xfail^^^): it only figures out i >= 256, rather than i == 256.  */
+  __analyzer_eval (i <= end); /* { dg-warning "TRUE" "true" { xfail *-*-* } } */
+  /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
 
   __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
 }
diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-start-to-end-by-step.c b/gcc/testsuite/gcc.dg/analyzer/loop-start-to-end-by-step.c
index ba578291298..3fc1362d1cf 100644
--- a/gcc/testsuite/gcc.dg/analyzer/loop-start-to-end-by-step.c
+++ b/gcc/testsuite/gcc.dg/analyzer/loop-start-to-end-by-step.c
@@ -1,7 +1,5 @@
 #include "analyzer-decls.h"
 
-// TODO: not sure what the __analyzer_eval should do
-
 void test(int start, int end, int step)
 {
   int i;
@@ -9,8 +7,9 @@ void test(int start, int end, int step)
   __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
 
   for (i = start; i < end; i += step) {
-      __analyzer_eval (i < end); /* { dg-warning "TRUE" } */
-      /* (should report TRUE twice). */
+      __analyzer_eval (i < end); /* { dg-warning "TRUE" "true" } */
+      /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
+      /* TODO(xfail^^^): should report TRUE twice. */
 
       __analyzer_eval (i == start); /* { dg-warning "TRUE" "1st" } */
       /* { dg-warning "FALSE" "2nd" { xfail *-*-* } .-1 } */
@@ -18,13 +17,15 @@ void test(int start, int end, int step)
       /* TODO(xfail^^^): ideally we ought to figure out i > 0 after 1st iteration.  */
 
       /* We don't know the direction of step.  */
-      __analyzer_eval (i >= start); /* { dg-warning "UNKNOWN" } */
+      __analyzer_eval (i >= start); /* { dg-warning "TRUE" "true" } */
+      /* { dg-warning "UNKNOWN" "unknown" { target *-*-* } .-1 } */
 
       __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
   }
 
   // FIXME: do we know this?  What about direction of step?
-  __analyzer_eval (i >= 256); /* { dg-warning "TRUE" } */
+  __analyzer_eval (i >= end); /* { dg-warning "TRUE" "true" { xfail *-*-* } } */
+  /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
 
   // FIXME: do we know this?  What if we overshoot?
   __analyzer_eval (i == end); /* { dg-warning "TRUE" "desired" { xfail *-*-* } } */
diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-start-up-to-end-by-1.c b/gcc/testsuite/gcc.dg/analyzer/loop-start-up-to-end-by-1.c
index da9de0ab039..ca6a862092c 100644
--- a/gcc/testsuite/gcc.dg/analyzer/loop-start-up-to-end-by-1.c
+++ b/gcc/testsuite/gcc.dg/analyzer/loop-start-up-to-end-by-1.c
@@ -1,7 +1,5 @@
 #include "analyzer-decls.h"
 
-// TODO: not sure what the __analyzer_eval should do
-
 void test(int start, int end)
 {
   int i;
@@ -9,24 +7,28 @@ void test(int start, int end)
   __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
 
   for (i = start; i < end; i++) {
-      __analyzer_eval (i < end); /* { dg-warning "TRUE" } */
-      /* (should report TRUE twice). */
+      __analyzer_eval (i < end); /* { dg-warning "TRUE" "true" } */
+      /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
+      /* TODO(xfail^^^): should report TRUE twice. */
 
       __analyzer_eval (i == start); /* { dg-warning "TRUE" "1st" } */
       /* { dg-warning "FALSE" "2nd" { xfail *-*-* } .-1 } */
       /* { dg-warning "UNKNOWN" "status quo" { target *-*-* } .-2 } */
       /* TODO(xfail^^^): ideally we ought to figure out i > 0 after 1st iteration.  */
 
-      __analyzer_eval (i >= start); /* { dg-warning "TRUE" } */
+      __analyzer_eval (i >= start); /* { dg-warning "TRUE" "true" } */
+      /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
+      /* TODO(xfail^^^): should report TRUE twice. */
 
       __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
   }
 
-  __analyzer_eval (i >= end); /* { dg-warning "TRUE" } */
+  __analyzer_eval (i >= end); /* { dg-warning "TRUE" "true" { xfail *-*-* } } */
+  /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
 
   __analyzer_eval (i == end); /* { dg-warning "TRUE" "desired" { xfail *-*-* } } */
   /* { dg-warning "UNKNOWN" "status quo" { target *-*-* } .-1 } */
-  /* TODO(xfail^^^): it only figures out i >= 256, rather than i == 256.  */
+  /* TODO(xfail^^^): it only figures out i >= end, rather than i == end.  */
 
   __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
 }
-- 
2.26.2

