diff options
author | Zack Weinberg <zack@gcc.gnu.org> | 1999-03-14 20:19:03 +0000 |
---|---|---|
committer | Zack Weinberg <zack@gcc.gnu.org> | 1999-03-14 20:19:03 +0000 |
commit | 47035bb8d29278e8da0c6956ece38850a01bae22 (patch) | |
tree | d4f02d9031d19efbec979e7d6a51a1192f2d52ea | |
parent | 43f856efc55b57625d86c9df2b825e90b5314d5a (diff) | |
download | gcc-47035bb8d29278e8da0c6956ece38850a01bae22.zip gcc-47035bb8d29278e8da0c6956ece38850a01bae22.tar.gz gcc-47035bb8d29278e8da0c6956ece38850a01bae22.tar.bz2 |
More tests for uninitialized variable warnings
From-SVN: r25770
-rw-r--r-- | gcc/testsuite/gcc.dg/uninit-5.c | 40 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/uninit-6.c | 47 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/uninit-8.c | 32 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/uninit-9.c | 41 |
4 files changed, 160 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/uninit-5.c b/gcc/testsuite/gcc.dg/uninit-5.c new file mode 100644 index 0000000..ac760d6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-5.c @@ -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 index 0000000..2c428df --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-6.c @@ -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 index 0000000..94117da --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-8.c @@ -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 index 0000000..8b439a4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-9.c @@ -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]); +} |