From 3f628e4105cffc507341c7d11af28152ec1ce67f Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 10 Jul 2020 17:07:45 -0400
Subject: [PATCH 303/315] FIXME: add tests for BZs

---
 .../gcc.dg/analyzer/FOLLOWUPS-pr94714.c       | 12 +++++++++
 .../gcc.dg/analyzer/FOLLOWUPS-pr95000.c       | 26 ++++++++++++++++++
 gcc/testsuite/gcc.dg/analyzer/pr94399.c       | 13 +++++++++
 gcc/testsuite/gcc.dg/analyzer/pr94458.c       | 23 ++++++++++++++++
 gcc/testsuite/gcc.dg/analyzer/pr94640.c       | 17 ++++++++++++
 gcc/testsuite/gcc.dg/analyzer/pr94688.c       |  6 +++++
 gcc/testsuite/gcc.dg/analyzer/pr94839.c       | 20 ++++++++++++++
 gcc/testsuite/gcc.dg/analyzer/pr95240.c       | 27 +++++++++++++++++++
 8 files changed, 144 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/FOLLOWUPS-pr94714.c
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/FOLLOWUPS-pr95000.c
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr94399.c
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr94458.c
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr94640.c
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr94688.c
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr94839.c
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr95240.c

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" } */
+}
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr94399.c b/gcc/testsuite/gcc.dg/analyzer/pr94399.c
new file mode 100644
index 00000000000..e897c04a007
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/pr94399.c
@@ -0,0 +1,13 @@
+#include <stdlib.h>
+
+#define _cleanup_(f) __attribute__((cleanup(f)))
+
+static inline void freep(void **p) {
+  free(*p);
+}
+
+void test(void) {
+  _cleanup_(freep) void *ptr;
+
+  ptr = malloc(3);
+} /* { dg-bogus "leak" } */
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr94458.c b/gcc/testsuite/gcc.dg/analyzer/pr94458.c
new file mode 100644
index 00000000000..ad9bfc94ad4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/pr94458.c
@@ -0,0 +1,23 @@
+#include <stdlib.h>
+
+struct ret
+{
+  int **array;
+};
+
+struct ret *allocate_stuff(void)
+{
+  struct ret *ret;
+
+  ret = calloc(1, sizeof (struct ret));
+  if (!ret) {
+    abort();
+  }
+
+  ret->array = calloc (10, sizeof(int *));
+  if (!ret->array) {
+    abort();
+  }
+
+  return ret;
+}
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr94640.c b/gcc/testsuite/gcc.dg/analyzer/pr94640.c
new file mode 100644
index 00000000000..9722a179fcd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/pr94640.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+  
+int debug;
+
+int opencfgfile(const char *cfgfile, FILE **fd)
+{
+  if (cfgfile[0] != '\0') {
+
+    if ((*fd = fopen(cfgfile, "r")) != NULL) {
+      if (debug)
+	printf("Config file: --config\n");
+    }
+    
+  }
+
+  return 2;
+}
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr94688.c b/gcc/testsuite/gcc.dg/analyzer/pr94688.c
new file mode 100644
index 00000000000..f553b8cfdad
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/pr94688.c
@@ -0,0 +1,6 @@
+int a, b;
+void d();
+void c()
+{
+  d((void (*)()) & a + b);
+}
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr94839.c b/gcc/testsuite/gcc.dg/analyzer/pr94839.c
new file mode 100644
index 00000000000..46c8bb98bd2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/pr94839.c
@@ -0,0 +1,20 @@
+struct bitmap
+{
+  int min;
+  int max;
+  int *vec;
+};
+
+int bitmap_create(struct bitmap *bm, int min, int max)
+{
+  int sz;
+
+  sz = (max / sizeof(int)) + 1;
+
+  bm->min = min;
+  bm->max = max;
+  bm->vec = __builtin_calloc(sz, sizeof(int));
+  if (!bm->vec)
+    return (-12);
+  return 0; /* { dg-bogus "leak" } */
+}
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr95240.c b/gcc/testsuite/gcc.dg/analyzer/pr95240.c
new file mode 100644
index 00000000000..c84c64de8b8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/pr95240.c
@@ -0,0 +1,27 @@
+typedef __SIZE_TYPE__ size_t;
+
+extern void *calloc(size_t nmemb, size_t size);
+extern void free(void *ptr);
+
+static char *activeTroubleArray;
+
+int
+initActiveTroubleArray ()
+{
+  activeTroubleArray = calloc (1, 1);
+  return activeTroubleArray ? 0 : 1;
+}
+
+void
+freeActiveTroubleArray ()
+{
+  free (activeTroubleArray);
+}
+
+int main (int argc, char *argv[])
+{
+  initActiveTroubleArray ();
+  freeActiveTroubleArray ();
+
+  return 1;
+}
-- 
2.26.2

