OSDN Git Service

More tests for uninitialized variable warnings
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 14 Mar 1999 20:19:03 +0000 (20:19 +0000)
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 14 Mar 1999 20:19:03 +0000 (20:19 +0000)
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@25770 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/testsuite/gcc.dg/uninit-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-6.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-8.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-9.c [new file with mode: 0644]

diff --git a/gcc/testsuite/gcc.dg/uninit-5.c b/gcc/testsuite/gcc.dg/uninit-5.c
new file mode 100644 (file)
index 0000000..ac760d6
--- /dev/null
@@ -0,0 +1,40 @@
+/* Spurious uninitialized-variable warnings.
+   These cases are documented as not working in the gcc manual. */
+
+/* { dg-do compile } */
+/* { dg-options "-O -Wuninitialized" } */
+
+extern void use(int);
+extern void foo(void);
+
+void
+func1(int cond)
+{
+    int x;  /* { dg-bogus "x" "uninitialized variable warning" { xfail *-*-* } } */
+
+    if(cond)
+       x = 1;
+
+    foo();
+
+    if(cond)
+       use(x);
+}
+
+void
+func2 (int cond)
+{
+    int x;  /* { dg-bogus "x" "uninitialized variable warning" { xfail *-*-* } } */
+    int flag = 0;
+
+    if(cond)
+    {
+       x = 1;
+       flag = 1;
+    }
+
+    foo();
+
+    if(flag)
+       use(x);
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-6.c b/gcc/testsuite/gcc.dg/uninit-6.c
new file mode 100644 (file)
index 0000000..2c428df
--- /dev/null
@@ -0,0 +1,47 @@
+/* Spurious uninitialized variable warnings.
+   This one inspired by java/class.c:build_utf8_ref.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O -Wuninitialized" } */
+
+#include <stddef.h>
+
+struct tree
+{
+    struct tree *car;
+    struct tree *cdr;
+    int type, data;
+};
+
+extern void *malloc(size_t);
+
+#define INTEGER_T 1
+#define PTR_T    2
+
+#define APPEND(TREE, LAST, TYPE, VALUE)                                \
+do {                                                           \
+     struct tree *tmp = malloc (sizeof (struct tree));         \
+     tmp->car = 0; tmp->cdr = 0; tmp->type = TYPE;             \
+     tmp->data = VALUE;                                                \
+     if (TREE->car)                                            \
+        LAST->cdr = tmp;                                       \
+     else                                                      \
+        TREE->car = tmp;                                       \
+     LAST = tmp;                                               \
+} while(0)
+struct tree *
+make_something(int a, int b, int c)
+{
+    struct tree *rv;
+    struct tree *field;  /* { dg-bogus "field" "uninitialized variable warning" { xfail *-*-* } } */
+
+    rv = malloc (sizeof (struct tree));
+    rv->car = 0;
+
+    APPEND(rv, field, INTEGER_T, a);
+    APPEND(rv, field, PTR_T, b);
+    APPEND(rv, field, INTEGER_T, c);
+
+    return rv;
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-8.c b/gcc/testsuite/gcc.dg/uninit-8.c
new file mode 100644 (file)
index 0000000..94117da
--- /dev/null
@@ -0,0 +1,32 @@
+/* Uninitialized variable warning tests...
+   Inspired by part of optabs.c:expand_binop.
+   May be the same as uninit-1.c.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O -Wuninitialized" } */
+
+#include <limits.h>
+
+void
+add_bignums (int *out, int *x, int *y)
+{
+    int p, sum;
+    int carry; /* { dg-bogus "carry" "uninitialized variable warning" { xfail *-*-* } } */
+
+    p = 0;
+    for (; *x; x++, y++, out++, p++)
+    {
+       if (p)
+           sum = *x + *y + carry;
+       else
+           sum = *x + *y;
+
+       if (sum < 0)
+       {
+           carry = 1;
+           sum -= INT_MAX;
+       }
+       else
+           carry = 0;
+    }
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-9.c b/gcc/testsuite/gcc.dg/uninit-9.c
new file mode 100644 (file)
index 0000000..8b439a4
--- /dev/null
@@ -0,0 +1,41 @@
+/* Spurious uninitialized variable warnings.  Slight variant on the
+   documented case, inspired by reg-stack.c:record_asm_reg_life.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O -Wuninitialized" } */
+
+struct foo
+{
+    int type;
+    struct foo *car;
+    struct foo *cdr;
+    char *data;
+    int data2;
+};
+
+extern void use(struct foo *);
+
+#define CLOBBER 6
+#define PARALLEL 3
+
+void
+func(struct foo *list, int count)
+{
+    int n_clobbers = 0;
+    int i;
+    struct foo **clob_list;   /* { dg-bogus "clob_list" "uninitialized variable warning" { xfail *-*-* } } */
+
+    if(list[0].type == PARALLEL)
+    {
+       clob_list = alloca(count * sizeof(struct foo *));
+       
+       for(i = 1; i < count; i++)
+       {
+           if(list[i].type == CLOBBER)
+               clob_list[n_clobbers++] = &list[i];
+       }
+    }
+
+    for(i = 0; i < n_clobbers; i++)
+       use(clob_list[i]);
+}