Commit 47035bb8 by Zack Weinberg

More tests for uninitialized variable warnings

From-SVN: r25770
parent 43f856ef
/* 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);
}
/* 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;
}
/* 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;
}
}
/* 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]);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment