From ba81e48854565e06257f8241333623af20800efb Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 14 Mar 2019 16:42:14 -0400
Subject: [PATCH 110/161] FIXME: add loop.c testcase

---
 .../gcc.dg/TODO-analyzer/facts/loop/input.c        | 36 -------------------
 .../gcc.dg/TODO-analyzer/facts/loop/script.py      | 42 ----------------------
 .../gcc.dg/TODO-analyzer/facts/loop/stdout.txt     |  0
 gcc/testsuite/gcc.dg/analyzer/loop.c               | 19 ++++++++++
 4 files changed, 19 insertions(+), 78 deletions(-)
 delete mode 100644 gcc/testsuite/gcc.dg/TODO-analyzer/facts/loop/input.c
 delete mode 100644 gcc/testsuite/gcc.dg/TODO-analyzer/facts/loop/script.py
 delete mode 100644 gcc/testsuite/gcc.dg/TODO-analyzer/facts/loop/stdout.txt
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/loop.c

diff --git a/gcc/testsuite/gcc.dg/TODO-analyzer/facts/loop/input.c b/gcc/testsuite/gcc.dg/TODO-analyzer/facts/loop/input.c
deleted file mode 100644
index 40a0dc6..0000000
--- a/gcc/testsuite/gcc.dg/TODO-analyzer/facts/loop/input.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
-   Copyright 2012 David Malcolm <dmalcolm@redhat.com>
-   Copyright 2012 Red Hat, Inc.
-
-   This is free software: you can redistribute it and/or modify it
-   under the terms of the GNU General Public License as published by
-   the Free Software Foundation, either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see
-   <http://www.gnu.org/licenses/>.
-*/
-
-extern void marker_A(void);
-extern void marker_B(void);
-extern void marker_C(void);
-extern void marker_D(void);
-
-void test(void)
-{
-  int i;
-
-  marker_A();
-
-  for (i=0; i<256; i++) {
-    marker_B();
-  }
-
-  marker_C();
-}
diff --git a/gcc/testsuite/gcc.dg/TODO-analyzer/facts/loop/script.py b/gcc/testsuite/gcc.dg/TODO-analyzer/facts/loop/script.py
deleted file mode 100644
index 9e0681d..0000000
--- a/gcc/testsuite/gcc.dg/TODO-analyzer/facts/loop/script.py
+++ /dev/null
@@ -1,42 +0,0 @@
-# -*- coding: utf-8 -*-
-#   Copyright 2012, 2013 David Malcolm <dmalcolm@redhat.com>
-#   Copyright 2012, 2013 Red Hat, Inc.
-#
-#   This is free software: you can redistribute it and/or modify it
-#   under the terms of the GNU General Public License as published by
-#   the Free Software Foundation, either version 3 of the License, or
-#   (at your option) any later version.
-#
-#   This program is distributed in the hope that it will be useful, but
-#   WITHOUT ANY WARRANTY; without even the implied warranty of
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-#   General Public License for more details.
-#
-#   You should have received a copy of the GNU General Public License
-#   along with this program.  If not, see
-#   <http://www.gnu.org/licenses/>.
-
-from sm import main
-from sm.parser import parse_file
-
-def selftest(ctxt, solution):
-    if 0:
-        import sys
-        solution.dump(sys.stderr)
-
-    node = ctxt.find_call_of('marker_A')
-
-    # Check that we know the constraints on i within the loop:
-    node = ctxt.find_call_of('marker_B')
-    ctxt.assert_fact(node, 'i', '<=', 255)
-    ctxt.assert_not_fact(node, 'i', '==', 0)
-
-    # Check that we know the constraints on i after the loop:
-    node = ctxt.find_call_of('marker_C')
-    ctxt.assert_fact(node, 'i', '>', 255)
-
-    # TODO: we don't yet do interval analysis, so we can't prove
-    # that (i == 256) after the loop.
-
-checker = parse_file('sm/checkers/malloc_checker.sm')
-main([checker], selftest=selftest)
diff --git a/gcc/testsuite/gcc.dg/TODO-analyzer/facts/loop/stdout.txt b/gcc/testsuite/gcc.dg/TODO-analyzer/facts/loop/stdout.txt
deleted file mode 100644
index e69de29..0000000
diff --git a/gcc/testsuite/gcc.dg/analyzer/loop.c b/gcc/testsuite/gcc.dg/analyzer/loop.c
new file mode 100644
index 0000000..7d1d95d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/loop.c
@@ -0,0 +1,19 @@
+void test(void)
+{
+  int i;
+
+  for (i=0; i<256; i++) {
+      __analyzer_eval (i < 256); /* { dg-warning "TRUE" } */
+
+      __analyzer_eval (i == 0); /* { dg-warning "UNKNOWN" "" { xfail *-*-* } } */
+      /* { dg-warning "TRUE" "" { target *-*-* } .-1 } */
+      /* TODO(xfail^^^): we're only capturing the first iteration, so
+	 we erroneously get i == 0.  */
+
+      __analyzer_eval (i >= 0); /* { dg-warning "TRUE" } */
+  }
+
+  __analyzer_eval (i >= 256); /* { dg-warning "TRUE" "" { xfail *-*-* } } */
+  __analyzer_eval (i == 256); /* { dg-warning "TRUE" "" { xfail *-*-* } } */
+  /* TODO(xfail): we're not reaching the end of the loop.  */
+}
-- 
1.8.5.3

