From 112e0cd28879fd97895155b7d3df3794ca09ca45 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Mon, 3 Aug 2020 18:10:07 -0400
Subject: [PATCH 19/49] FIXME: add FOLLOWUPS-* tests

---
 .../g++.dg/analyzer/FOLLOWUPS-init.not-C      | 89 +++++++++++++++++++
 .../gcc.dg/analyzer/FOLLOWUPS-pr94714.c       | 12 +++
 .../gcc.dg/analyzer/FOLLOWUPS-pr95000.c       | 26 ++++++
 3 files changed, 127 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/analyzer/FOLLOWUPS-init.not-C
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/FOLLOWUPS-pr94714.c
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/FOLLOWUPS-pr95000.c

diff --git a/gcc/testsuite/g++.dg/analyzer/FOLLOWUPS-init.not-C b/gcc/testsuite/g++.dg/analyzer/FOLLOWUPS-init.not-C
new file mode 100644
index 00000000000..96d40ea5a60
--- /dev/null
+++ b/gcc/testsuite/g++.dg/analyzer/FOLLOWUPS-init.not-C
@@ -0,0 +1,89 @@
+/* Tests of brace-enclosed initializers
+   (including the CONSTRUCTOR tree code).  */
+
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
+struct coord
+{
+  int x;
+  int y;
+};
+
+void test_1 (void)
+{
+  struct coord c {3, 4};
+  __analyzer_eval (c.x == 3); /* { dg-warning "TRUE" } */
+  __analyzer_eval (c.y == 4); /* { dg-warning "TRUE" } */  
+}
+
+void test_2 (void)
+{
+  struct coord c {3};
+  __analyzer_eval (c.x == 3); /* { dg-warning "TRUE" } */
+  __analyzer_eval (c.y == 0); /* { dg-warning "TRUE" } */  
+}
+
+// etc; FIXME: how much do we want to copy from c testcase???
+
+void test_3 (void)
+{
+  struct coord c = {};
+  __analyzer_eval (c.x == 0); /* { dg-warning "TRUE" } */
+  __analyzer_eval (c.y == 0); /* { dg-warning "TRUE" } */  
+}
+
+void test_4 (void)
+{
+  int c[2] = {3, 4};
+  __analyzer_eval (c[0] == 3); /* { dg-warning "TRUE" } */
+  __analyzer_eval (c[1] == 4); /* { dg-warning "TRUE" } */  
+}
+
+void test_5 (void)
+{
+  int c[2] = {3};
+  __analyzer_eval (c[0] == 3); /* { dg-warning "TRUE" } */
+  __analyzer_eval (c[1] == 0); /* { dg-warning "TRUE" } */  
+}
+
+void test_6 (void)
+{
+  int c[2] = {};
+  __analyzer_eval (c[0] == 0); /* { dg-warning "TRUE" } */
+  __analyzer_eval (c[1] == 0); /* { dg-warning "TRUE" } */  
+}
+
+void test_7 (void)
+{
+  struct coord c[2] = {{3, 4}, {5, 6}};
+  __analyzer_eval (c[0].x == 3); /* { dg-warning "TRUE" } */
+  __analyzer_eval (c[0].y == 4); /* { dg-warning "TRUE" } */  
+  __analyzer_eval (c[1].x == 5); /* { dg-warning "TRUE" } */
+  __analyzer_eval (c[1].y == 6); /* { dg-warning "TRUE" } */  
+}
+
+void test_8 (void)
+{
+  struct coord c[2] = {{3}, {5}};
+  __analyzer_eval (c[0].x == 3); /* { dg-warning "TRUE" } */
+  __analyzer_eval (c[0].y == 0); /* { dg-warning "TRUE" } */  
+  __analyzer_eval (c[1].x == 5); /* { dg-warning "TRUE" } */
+  __analyzer_eval (c[1].y == 0); /* { dg-warning "TRUE" } */  
+}
+
+void test_9 (void)
+{
+  struct coord c[2] = {{}, {}};
+  __analyzer_eval (c[0].x == 0); /* { dg-warning "TRUE" } */
+  __analyzer_eval (c[0].y == 0); /* { dg-warning "TRUE" } */  
+  __analyzer_eval (c[1].x == 0); /* { dg-warning "TRUE" } */
+  __analyzer_eval (c[1].y == 0); /* { dg-warning "TRUE" } */  
+}
+
+/* TODO:   
+   For RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE:
+   The field INDEX of each constructor_elt is a FIELD_DECL.
+
+   For ARRAY_TYPE:
+
+   CONSTRUCTOR_NO_CLEARING flag.  */
diff --git a/gcc/testsuite/gcc.dg/analyzer/FOLLOWUPS-pr94714.c b/gcc/testsuite/gcc.dg/analyzer/FOLLOWUPS-pr94714.c
new file mode 100644
index 00000000000..87e983de4e4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/FOLLOWUPS-pr94714.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+
+int main (void)
+{
+  int *p;
+  int i;
+
+  p = &i;
+  printf ("%d\n", p[0]);
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/analyzer/FOLLOWUPS-pr95000.c b/gcc/testsuite/gcc.dg/analyzer/FOLLOWUPS-pr95000.c
new file mode 100644
index 00000000000..724a67bbdea
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/FOLLOWUPS-pr95000.c
@@ -0,0 +1,26 @@
+#include "analyzer-decls.h"
+
+void test_switch_char(char x) {
+  switch (x) {
+  case 'b':
+    __analyzer_eval (x == 'b'); /* { dg-warning "TRUE" "true" { xfail *-*-* } } */
+    /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
+  }
+}
+
+void test_switch_int(int x) {
+  switch (x) {
+  case 97:
+    __analyzer_eval (x == 97); /* { dg-warning "TRUE" } */
+  }
+}
+
+void test_if_char(char x) {
+  if (x == 'b')
+    __analyzer_eval (x == 'b'); /* { dg-warning "TRUE" } */
+}
+
+void test_if_int(int x) {
+  if (x == 97)
+    __analyzer_eval (x == 97); /* { dg-warning "TRUE" } */
+}
-- 
2.26.2

