This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH][RFC] Enable -Wuninitialized at -O0
On Wed, 30 Jul 2008, Joseph S. Myers wrote:
> On Wed, 30 Jul 2008, Richard Guenther wrote:
>
> > where the missed diagnostics are to be emitted from the late
> > uninitialized pass. Is it ok to split these into separate testcases
> > and disable optimization for the uninit testcases or should I
> > simply duplicate all of them like above (taking out the not working
> > stuff)?
>
> My view is duplicate them.
>
> Places in the manual that say -Wuninitialized doesn't work at -O0 (in the
> documentation of -Wall, -Wextra, -Winit-self, and of -Wuninitialized
> itself, at least) need updating. passes.texi discusses uninitialized
> variable warnings and may also need updating.
So the following is what I give another round of testing then.
Ok if everything passes?
Thanks,
Richard.
2008-07-30 Richard Guenther <rguenther@suse.de>
* passes.c (init_optimization_passes): Always call
pass_early_warn_uninitialized.
* opts.c (decode_options): Do not warn about -Wuninitialized
at -O0.
* doc/invoke.texi (-Wuninitialized): Correct for enabling at -O0.
* doc/passes.texi (Warn for uninitialized variables): Adjust.
* gcc.dg/uninit-1-O0.c: New testcase.
* gcc.dg/uninit-2-O0.c: Likewise.
* gcc.dg/uninit-3-O0.c: Likewise.
* gcc.dg/uninit-4-O0.c: Likewise.
* gcc.dg/uninit-5-O0.c: Likewise.
* gcc.dg/uninit-6-O0.c: Likewise.
* gcc.dg/uninit-8-O0.c: Likewise.
* gcc.dg/uninit-9-O0.c: Likewise.
* gcc.dg/uninit-A-O0.c: Likewise.
* gcc.dg/uninit-B-O0.c: Likewise.
* gcc.dg/uninit-C-O0.c: Likewise.
* gcc.dg/uninit-D-O0.c: Likewise.
* gcc.dg/uninit-E-O0.c: Likewise.
* gcc.dg/uninit-F-O0.c: Likewise.
* gcc.dg/uninit-G-O0.c: Likewise.
* gcc.dg/uninit-H-O0.c: Likewise.
* gcc.dg/uninit-I-O0.c: Likewise.
* gcc.dg/uninit-10-O0.c: Likewise.
* gcc.dg/uninit-11-O0.c: Likewise.
* gcc.dg/uninit-12-O0.c: Likewise.
* gcc.dg/uninit-13-O0.c: Likewise.
* gcc.dg/uninit-14-O0.c: Likewise.
* gcc.dg/uninit-15-O0.c: Likewise.
* gcc.dg/Wall.c: Avoid uninitialized warning.
* gcc.dg/Wno-all.c: Likewise.
* gcc.dg/pr3074-1.c: Likewise.
Index: gcc/passes.c
===================================================================
*** gcc/passes.c.orig 2008-07-30 17:10:10.000000000 +0200
--- gcc/passes.c 2008-07-30 17:10:12.000000000 +0200
*************** init_optimization_passes (void)
*** 544,553 ****
NEXT_PASS (pass_referenced_vars);
NEXT_PASS (pass_reset_cc_flags);
NEXT_PASS (pass_build_ssa);
NEXT_PASS (pass_all_early_optimizations);
{
struct opt_pass **p = &pass_all_early_optimizations.pass.sub;
- NEXT_PASS (pass_early_warn_uninitialized);
NEXT_PASS (pass_rebuild_cgraph_edges);
NEXT_PASS (pass_early_inline);
NEXT_PASS (pass_cleanup_cfg);
--- 544,553 ----
NEXT_PASS (pass_referenced_vars);
NEXT_PASS (pass_reset_cc_flags);
NEXT_PASS (pass_build_ssa);
+ NEXT_PASS (pass_early_warn_uninitialized);
NEXT_PASS (pass_all_early_optimizations);
{
struct opt_pass **p = &pass_all_early_optimizations.pass.sub;
NEXT_PASS (pass_rebuild_cgraph_edges);
NEXT_PASS (pass_early_inline);
NEXT_PASS (pass_cleanup_cfg);
Index: gcc/opts.c
===================================================================
*** gcc/opts.c.orig 2008-07-30 17:10:10.000000000 +0200
--- gcc/opts.c 2008-07-30 17:10:12.000000000 +0200
*************** decode_options (unsigned int argc, const
*** 1080,1092 ****
so force it not to be done. */
warn_inline = 0;
flag_no_inline = 1;
-
- /* The c_decode_option function and decode_option hook set
- this to `2' if -Wall is used, so we can avoid giving out
- lots of errors for people who don't realize what -Wall does. */
- if (warn_uninitialized == 1)
- warning (OPT_Wuninitialized,
- "-Wuninitialized is not supported without -O");
}
/* The optimization to partition hot and cold basic blocks into separate
--- 1080,1085 ----
Index: gcc/testsuite/gcc.dg/Wall.c
===================================================================
*** gcc/testsuite/gcc.dg/Wall.c.orig 2008-07-30 17:10:10.000000000 +0200
--- gcc/testsuite/gcc.dg/Wall.c 2008-07-30 17:10:12.000000000 +0200
***************
*** 3,10 ****
/* { dg-do compile } */
/* { dg-options "-Wall" } */
! void foo()
{
- int a;
5 * (a == 1) | (a == 2); /* { dg-warning "no effect" "no effect" } */
}
--- 3,9 ----
/* { dg-do compile } */
/* { dg-options "-Wall" } */
! void foo(int a)
{
5 * (a == 1) | (a == 2); /* { dg-warning "no effect" "no effect" } */
}
Index: gcc/testsuite/gcc.dg/Wno-all.c
===================================================================
*** gcc/testsuite/gcc.dg/Wno-all.c.orig 2008-07-30 17:10:10.000000000 +0200
--- gcc/testsuite/gcc.dg/Wno-all.c 2008-07-30 17:10:12.000000000 +0200
***************
*** 3,11 ****
/* { dg-do compile } */
/* { dg-options "-Wall -Wno-all" } */
! void foo()
{
- int a;
5 * (a == 1) | (a == 2); /* { dg-bogus "no effect" "no effect" } */
}
--- 3,10 ----
/* { dg-do compile } */
/* { dg-options "-Wall -Wno-all" } */
! void foo(int a)
{
5 * (a == 1) | (a == 2); /* { dg-bogus "no effect" "no effect" } */
}
Index: gcc/testsuite/gcc.dg/uninit-1-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-1-O0.c 2008-07-30 17:13:04.000000000 +0200
***************
*** 0 ****
--- 1,30 ----
+ /* Spurious uninitialized variable warnings, case 1.
+ Taken from cppfiles.c (merge_include_chains) */
+ /* { dg-do compile } */
+ /* { dg-options "-Wuninitialized" } */
+
+ struct list
+ {
+ struct list *next;
+ int id;
+ };
+
+ extern void free (void *);
+
+ void remove_dupes (struct list *el)
+ {
+ struct list *p, *q, *r; /* { dg-bogus "r" "uninitialized variable warning" } */
+
+ for (p = el; p; p = p->next)
+ {
+ for (q = el; q != p; q = q->next)
+ if (q->id == p->id)
+ {
+ r->next = p->next;
+ free (p);
+ p = r;
+ break;
+ }
+ r = p;
+ }
+ }
Index: gcc/testsuite/gcc.dg/uninit-10-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-10-O0.c 2008-07-30 17:13:08.000000000 +0200
***************
*** 0 ****
--- 1,109 ----
+ /* { dg-do compile } */
+ /* { dg-options "-Wall" } */
+ /* On Alpha EV4, dead code elimination and cfg simplification conspired
+ to leave the register containing 'C' marked live, though all references
+ to the variable had been removed. */
+
+ struct operand_data
+ {
+ struct operand_data *next;
+ int index;
+ const char *predicate;
+ const char *constraint;
+ int mode;
+ unsigned char n_alternatives;
+ char address_p;
+ char strict_low;
+ char eliminable;
+ char seen;
+ };
+
+ struct data
+ {
+ struct data *next;
+ const char *name;
+ const char *template;
+ int code_number;
+ int index_number;
+ int lineno;
+ int n_operands;
+ int n_dups;
+ int n_alternatives;
+ int operand_number;
+ int output_format;
+ struct operand_data operand[40];
+ };
+
+ extern void message_with_line (int, const char *, ...)
+ __attribute__ ((__format__ (__printf__, 2, 3)));
+ extern int have_error;
+
+ extern char *strchr (__const char *__s, int __c) __attribute__ ((__pure__));
+
+ void
+ validate_insn_alternatives (d)
+ struct data *d;
+ {
+ int n = 0, start;
+
+ for (start = 0; start < d->n_operands; start++)
+ if (d->operand[start].n_alternatives > 0)
+ {
+ int len, i;
+ const char *p;
+ char c; /* { dg-bogus "used uninitialized" "uninitialized variable warning" } */
+ int which_alternative = 0;
+ int alternative_count_unsure = 0;
+
+ for (p = d->operand[start].constraint; (c = *p); p += len)
+ {
+ len = 1;
+
+ if (len < 1 || (len > 1 && strchr (",#*+=&%!0123456789", c)))
+ {
+ message_with_line (d->lineno,
+ "invalid length %d for char '%c' in alternative %d of operand %d",
+ len, c, which_alternative, start);
+ len = 1;
+ have_error = 1;
+ }
+
+ if (c == ',')
+ {
+ which_alternative++;
+ continue;
+ }
+
+ for (i = 1; i < len; i++)
+ if (p[i] == '\0')
+ {
+ message_with_line (d->lineno,
+ "NUL in alternative %d of operand %d",
+ which_alternative, start);
+ alternative_count_unsure = 1;
+ break;
+ }
+ else if (strchr (",#*", p[i]))
+ {
+ message_with_line (d->lineno,
+ "'%c' in alternative %d of operand %d",
+ p[i], which_alternative, start);
+ alternative_count_unsure = 1;
+ }
+ }
+ if (alternative_count_unsure)
+ have_error = 1;
+ else if (n == 0)
+ n = d->operand[start].n_alternatives;
+ else if (n != d->operand[start].n_alternatives)
+ {
+ message_with_line (d->lineno,
+ "wrong number of alternatives in operand %d",
+ start);
+ have_error = 1;
+ }
+ }
+
+
+ d->n_alternatives = n;
+ }
Index: gcc/testsuite/gcc.dg/uninit-11-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-11-O0.c 2008-07-30 17:15:15.000000000 +0200
***************
*** 0 ****
--- 1,42 ----
+ /* Positive test for uninitialized variables. */
+ /* { dg-do compile } */
+ /* { dg-options "-Wuninitialized" } */
+
+ int sink;
+
+ void f1(int parm) /* { dg-bogus "uninitialized" "parameter" } */
+ {
+ sink = parm; /* { dg-bogus "uninitialized" "parameter" } */
+ }
+
+ void f2(void)
+ {
+ int x;
+ sink = x; /* { dg-warning "is used" "unconditional" } */
+ }
+
+ void f3(int p)
+ {
+ int x; /* { dg-warning "may be used" "conditional" { xfail *-*-* } } */
+ if (p)
+ x = p;
+ sink = x;
+ }
+
+ void f4(int p)
+ {
+ int x; /* { dg-bogus "uninitialized" "easy if" } */
+ if (p)
+ x = 1;
+ else
+ x = 2;
+ sink = x;
+ }
+
+ void f5(void)
+ {
+ int x, i; /* { dg-bogus "uninitialized" "easy loop" } */
+ for (i = 0; i < 10; ++i)
+ x = 1;
+ sink = x;
+ }
Index: gcc/testsuite/gcc.dg/uninit-12-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-12-O0.c 2008-07-30 17:13:14.000000000 +0200
***************
*** 0 ****
--- 1,12 ----
+ /* PR 23497 */
+ /* { dg-do compile } */
+ /* { dg-options "-Wuninitialized" } */
+
+ typedef _Complex float C;
+ C foo()
+ {
+ C f;
+ __real__ f = 0;
+ __imag__ f = 0;
+ return f;
+ }
Index: gcc/testsuite/gcc.dg/uninit-13-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-13-O0.c 2008-07-30 17:15:35.000000000 +0200
***************
*** 0 ****
--- 1,10 ----
+ /* { dg-do compile } */
+ /* { dg-options "-Wuninitialized" } */
+
+ typedef _Complex float C;
+ C foo()
+ {
+ C f;
+ __imag__ f = 0; /* { dg-warning "is used" "unconditional" { xfail *-*-* } } */
+ return f;
+ }
Index: gcc/testsuite/gcc.dg/uninit-14-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-14-O0.c 2008-07-30 17:13:21.000000000 +0200
***************
*** 0 ****
--- 1,20 ----
+ /* PR 24931 */
+ /* { dg-do compile } */
+ /* { dg-options "-Wuninitialized" } */
+
+ struct p {
+ short x, y;
+ };
+
+ struct s {
+ int i;
+ struct p p;
+ };
+
+ struct s f()
+ {
+ struct s s;
+ s.p = (struct p){};
+ s.i = (s.p.x || s.p.y);
+ return s;
+ }
Index: gcc/testsuite/gcc.dg/uninit-15-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-15-O0.c 2008-07-30 17:25:12.000000000 +0200
***************
*** 0 ****
--- 1,20 ----
+ /* { dg-do compile } */
+ /* { dg-options "-Wuninitialized" } */
+
+ /* XFAIL for now, the uninitialized pass runs before inlining only at -O0. */
+
+ inline int __attribute__((always_inline))
+ foo (int i)
+ {
+ if (i) return 1; /* { dg-warning "is used uninitialized" {} { xfail *-*-* } } */
+ return 0;
+ }
+
+ void baz();
+
+ void bar()
+ {
+ int j; /* { dg-message "was declared here" {} { xfail *-*-* } } */
+ for (; foo(j); ++j)
+ baz();
+ }
Index: gcc/testsuite/gcc.dg/uninit-2-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-2-O0.c 2008-07-30 17:13:30.000000000 +0200
***************
*** 0 ****
--- 1,52 ----
+ /* Spurious uninitialized variable warnings, case 2.
+ Taken from cpphash.c (macroexpand) */
+ /* { dg-do compile } */
+ /* { dg-options "-Wuninitialized" } */
+
+ struct definition
+ {
+ int nargs;
+ int rest_args;
+ };
+
+ struct cpp_reader;
+
+ enum cpp_token
+ {
+ CPP_EOF, CPP_POP, CPP_COMMA, CPP_RPAREN
+ };
+
+ extern enum cpp_token macarg (struct cpp_reader *, int);
+
+ void
+ macroexpand (struct cpp_reader *pfile, struct definition *defn)
+ {
+ int nargs = defn->nargs;
+
+ if (nargs >= 0)
+ {
+ enum cpp_token token; /* { dg-bogus "token" "uninitialized variable warning" } */
+ int i, rest_args;
+ i = 0;
+ rest_args = 0;
+ do
+ {
+ if (rest_args)
+ continue;
+ if (i < nargs || (nargs == 0 && i == 0))
+ {
+ /* if we are working on last arg which absorbs rest of args... */
+ if (i == nargs - 1 && defn->rest_args)
+ rest_args = 1;
+ token = macarg (pfile, rest_args);
+ }
+ else
+ token = macarg (pfile, 0);
+ if (token == CPP_EOF || token == CPP_POP)
+ return;
+
+ i++;
+ }
+ while (token == CPP_COMMA);
+ }
+ }
Index: gcc/testsuite/gcc.dg/uninit-3-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-3-O0.c 2008-07-30 17:13:34.000000000 +0200
***************
*** 0 ****
--- 1,33 ----
+ /* Spurious uninit variable warnings, case 3.
+ Inspired by cppexp.c (parse_charconst) */
+ /* { dg-do compile } */
+ /* { dg-options "-Wuninitialized" } */
+
+ extern void error (char *);
+
+ int
+ parse_charconst (const char *start, const char *end)
+ {
+ int c; /* { dg-bogus "c" "uninitialized variable warning" } */
+ int nchars, retval;
+
+ nchars = 0;
+ retval = 0;
+ while (start < end)
+ {
+ c = *start++;
+ if (c == '\'')
+ break;
+ nchars++;
+ retval += c;
+ retval <<= 8;
+ }
+
+ if (nchars == 0)
+ return 0;
+
+ if (c != '\'')
+ error ("malformed character constant");
+
+ return retval;
+ }
Index: gcc/testsuite/gcc.dg/uninit-4-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-4-O0.c 2008-07-30 17:13:38.000000000 +0200
***************
*** 0 ****
--- 1,52 ----
+ /* Spurious uninit variable warnings, case 4.
+ Simplified version of cppexp.c (cpp_parse_expr).
+
+ This one is really fragile, it gets it right if you take out case
+ 1, or if the structure is replaced by an int, or if the structure
+ has fewer members (!) */
+
+ /* { dg-do compile } */
+ /* { dg-options "-Wuninitialized" } */
+
+ extern void abort (void);
+
+ struct operation {
+ short op;
+ char rprio;
+ char flags;
+ char unsignedp;
+ long value;
+ };
+
+ extern struct operation cpp_lex (void);
+
+ void
+ cpp_parse_expr (void)
+ {
+ int rprio; /* { dg-bogus "rprio" "uninitialized variable warning PR19833" } */
+ struct operation op;
+
+ for (;;)
+ {
+ op = cpp_lex ();
+
+ switch (op.op)
+ {
+ case 0:
+ break;
+ case 1:
+ return;
+ case 2:
+ rprio = 1;
+ break;
+ default:
+ return;
+ }
+
+ if (op.op == 0)
+ return;
+
+ if (rprio != 1)
+ abort();
+ }
+ }
Index: gcc/testsuite/gcc.dg/uninit-5-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-5-O0.c 2008-07-30 17:13:42.000000000 +0200
***************
*** 0 ****
--- 1,39 ----
+ /* Spurious uninitialized-variable warnings. */
+
+ /* { dg-do compile } */
+ /* { dg-options "-Wuninitialized" } */
+
+ extern void use(int);
+ extern void foo(void);
+
+ void
+ func1(int cond)
+ {
+ int x; /* { dg-bogus "x" "uninitialized variable warning" } */
+
+ if(cond)
+ x = 1;
+
+ foo();
+
+ if(cond)
+ use(x);
+ }
+
+ void
+ func2 (int cond)
+ {
+ int x; /* { dg-bogus "x" "uninitialized variable warning" } */
+ int flag = 0;
+
+ if(cond)
+ {
+ x = 1;
+ flag = 1;
+ }
+
+ foo();
+
+ if(flag)
+ use(x);
+ }
Index: gcc/testsuite/gcc.dg/uninit-6-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-6-O0.c 2008-07-30 17:13:46.000000000 +0200
***************
*** 0 ****
--- 1,47 ----
+ /* Spurious uninitialized variable warnings.
+ This one inspired by java/class.c:build_utf8_ref. */
+
+ /* { dg-do compile } */
+ /* { dg-options "-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;
+
+ rv = malloc (sizeof (struct tree));
+ rv->car = 0;
+
+ APPEND(rv, field, INTEGER_T, a); /* { dg-bogus "field" "uninitialized variable warning" { xfail *-*-* } } */
+ APPEND(rv, field, PTR_T, b);
+ APPEND(rv, field, INTEGER_T, c);
+
+ return rv;
+ }
Index: gcc/testsuite/gcc.dg/uninit-8-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-8-O0.c 2008-07-30 17:13:49.000000000 +0200
***************
*** 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 "-Wuninitialized" } */
+
+ #include <limits.h>
+
+ void
+ add_bignums (int *out, int *x, int *y)
+ {
+ int p, sum;
+ int carry; /* { dg-bogus "carry" "uninitialized variable warning" } */
+
+ 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;
+ }
+ }
Index: gcc/testsuite/gcc.dg/uninit-9-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-9-O0.c 2008-07-30 17:13:53.000000000 +0200
***************
*** 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 "-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" } */
+
+ if(list[0].type == PARALLEL)
+ {
+ clob_list = __builtin_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]);
+ }
Index: gcc/testsuite/gcc.dg/uninit-A-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-A-O0.c 2008-07-30 17:14:00.000000000 +0200
***************
*** 0 ****
--- 1,117 ----
+ /* Inspired by part of java/parse.y.
+ May be a real bug in CSE. */
+
+ /* { dg-do compile } */
+ /* { dg-options "-Wall" } */
+
+ struct tree
+ {
+ struct tree *car, *cdr, *wfl;
+ int code;
+ struct { unsigned int renp:1;
+ unsigned int rtnp:1;
+ unsigned int rpnp:1; } flags;
+ };
+ typedef struct tree *tree;
+ #define NULL_TREE ((tree)0)
+
+ /* Codes */
+ enum
+ {
+ CALL_EXPR, NEW_ARRAY_EXPR, NEW_CLASS_EXPR, CONVERT_EXPR,
+ ARRAY_REF, CONDITIONAL_EXPR, STRING_CST, EXPR_WITH_FILE_LOCATION
+ };
+
+ /* Flags */
+ #define RESOLVE_EXPRESSION_NAME_P(t) ((t)->flags.renp)
+ #define RESOLVE_TYPE_NAME_P(t) ((t)->flags.rtnp)
+ #define RESOLVE_PACKAGE_NAME_P(t) ((t)->flags.rpnp)
+
+ /* Macros */
+ #define EXPR_WFL_QUALIFICATION(t) ((t)->wfl)
+ #define QUAL_WFL(t) ((t)->wfl)
+ #define EXPR_WFL_NODE(t) ((t)->wfl)
+ #define TREE_CODE(t) ((t)->code)
+ #define TREE_OPERAND(t,x) ((t)->car)
+ #define CLASSTYPE_SUPER(t) ((t)->car)
+ #define IDENTIFIER_LOCAL_VALUE(t) ((t)->car)
+ #define TREE_CHAIN(t) ((t)->cdr)
+ #define QUAL_RESOLUTION(t) ((t)->cdr)
+
+ extern tree current_class, this_identifier_node;
+ extern tree super_identifier_node, length_identifier_node;
+
+ tree resolve_and_layout (tree, tree);
+ tree lookup_field_wrapper (tree, tree);
+
+ void
+ qualify_ambiguous_name (id)
+ tree id;
+ {
+ tree qual, qual_wfl, decl;
+ tree name; /* { dg-bogus "name" "uninitialized variable warning" } */
+ tree ptr_type; /* { dg-bogus "ptr_type" "uninitialized variable warning" } */
+ int again, new_array_found = 0;
+ int super_found = 0, this_found = 0;
+
+ qual = EXPR_WFL_QUALIFICATION (id);
+ do {
+ qual_wfl = QUAL_WFL (qual);
+ switch (TREE_CODE (qual_wfl))
+ {
+ case CALL_EXPR:
+ qual_wfl = TREE_OPERAND (qual_wfl, 0);
+ if (TREE_CODE (qual_wfl) != EXPR_WITH_FILE_LOCATION)
+ {
+ qual = EXPR_WFL_QUALIFICATION (qual_wfl);
+ qual_wfl = QUAL_WFL (qual);
+ }
+ break;
+ case NEW_ARRAY_EXPR:
+ qual = TREE_CHAIN (qual);
+ new_array_found = again = 1;
+ continue;
+ case NEW_CLASS_EXPR:
+ case CONVERT_EXPR:
+ qual_wfl = TREE_OPERAND (qual_wfl, 0);
+ break;
+ case ARRAY_REF:
+ while (TREE_CODE (qual_wfl) == ARRAY_REF)
+ qual_wfl = TREE_OPERAND (qual_wfl, 0);
+ break;
+ default:
+ break;
+ }
+
+ name = EXPR_WFL_NODE (qual_wfl);
+ ptr_type = current_class;
+ again = 0;
+
+ } while (again);
+
+ /* If you put straightforward uses of name and ptr_type here
+ instead of the if-else sequence below, the warnings go away.
+ Therefore I suspect a real bug. */
+
+ if (!this_found && !super_found && (decl = IDENTIFIER_LOCAL_VALUE (name)))
+ {
+ RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
+ QUAL_RESOLUTION (qual) = decl;
+ }
+ else if ((decl = lookup_field_wrapper (ptr_type, name))
+ || (new_array_found && name == length_identifier_node))
+ {
+ RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
+ QUAL_RESOLUTION (qual) = (new_array_found ? NULL_TREE : decl);
+ }
+ else if ((decl = resolve_and_layout (name, NULL_TREE)))
+ {
+ RESOLVE_TYPE_NAME_P (qual_wfl) = 1;
+ QUAL_RESOLUTION (qual) = decl;
+ }
+ else if (TREE_CODE (QUAL_WFL (qual)) == CALL_EXPR
+ || TREE_CODE (QUAL_WFL (qual)) == ARRAY_REF)
+ RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
+ else
+ RESOLVE_PACKAGE_NAME_P (qual_wfl) = 1;
+ }
Index: gcc/testsuite/gcc.dg/uninit-B-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-B-O0.c 2008-07-30 17:14:06.000000000 +0200
***************
*** 0 ****
--- 1,15 ----
+ /* Origin: PR c/179 from Gray Watson <gray@256.com>, adapted as a testcase
+ by Joseph Myers <jsm28@cam.ac.uk>. */
+ /* { dg-do compile } */
+ /* { dg-options "-Wuninitialized" } */
+ extern void foo (int *);
+ extern void bar (int);
+
+ void
+ baz (void)
+ {
+ int i;
+ if (i) /* { dg-warning "uninit" "uninit i warning" { xfail *-*-* } } */
+ bar (i);
+ foo (&i);
+ }
Index: gcc/testsuite/gcc.dg/uninit-C-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-C-O0.c 2008-07-30 17:14:10.000000000 +0200
***************
*** 0 ****
--- 1,21 ----
+ /* Spurious uninitialized variable warning, inspired by libgcc2.c. */
+ /* { dg-do compile } */
+ /* { dg-options "-Wuninitialized" } */
+
+ /* Not all platforms support TImode integers. */
+ #if defined(__LP64__) && !defined(__hppa__)
+ typedef int TItype __attribute__ ((mode (TI)));
+ #else
+ typedef long TItype;
+ #endif
+
+
+ TItype
+ __subvdi3 (TItype a, TItype b)
+ {
+ TItype w;
+
+ w = a - b;
+
+ return w;
+ }
Index: gcc/testsuite/gcc.dg/uninit-D-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-D-O0.c 2008-07-30 17:14:13.000000000 +0200
***************
*** 0 ****
--- 1,9 ----
+ /* Test we do not warn about initializing variable with self. */
+ /* { dg-do compile } */
+ /* { dg-options "-Wuninitialized" } */
+
+ int f()
+ {
+ int i = i;
+ return i;
+ }
Index: gcc/testsuite/gcc.dg/uninit-E-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-E-O0.c 2008-07-30 17:14:16.000000000 +0200
***************
*** 0 ****
--- 1,9 ----
+ /* Test we do warn about initializing variable with self when -Winit-self is supplied. */
+ /* { dg-do compile } */
+ /* { dg-options "-Wuninitialized -Winit-self" } */
+
+ int f()
+ {
+ int i = i; /* { dg-warning "i" "uninitialized variable warning" } */
+ return i;
+ }
Index: gcc/testsuite/gcc.dg/uninit-F-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-F-O0.c 2008-07-30 17:14:20.000000000 +0200
***************
*** 0 ****
--- 1,9 ----
+ /* Test we do warn about initializing variable with self in the initialization. */
+ /* { dg-do compile } */
+ /* { dg-options "-Wuninitialized" } */
+
+ int f()
+ {
+ int i = i + 1; /* { dg-warning "i" "uninitialized variable warning" } */
+ return i;
+ }
Index: gcc/testsuite/gcc.dg/uninit-G-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-G-O0.c 2008-07-30 17:14:24.000000000 +0200
***************
*** 0 ****
--- 1,9 ----
+ /* Test we do not warn about initializing variable with address of self in the initialization. */
+ /* { dg-do compile } */
+ /* { dg-options "-Wuninitialized" } */
+
+ void *f()
+ {
+ void *i = &i;
+ return i;
+ }
Index: gcc/testsuite/gcc.dg/uninit-H-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-H-O0.c 2008-07-30 17:14:28.000000000 +0200
***************
*** 0 ****
--- 1,33 ----
+ /* PR 14204 */
+ /* { dg-do compile } */
+ /* { dg-options "-Wall -Werror" } */
+
+ #if defined __alpha__
+ # define ASM __asm__("$30")
+ #elif defined __i386__
+ # define ASM __asm__("esp")
+ #elif defined (__powerpc__) || defined (__PPC__) || defined (__ppc__) || defined (_POWER)
+ # define ASM __asm__("r1")
+ #elif defined __s390__
+ # define ASM __asm__("r15")
+ #elif defined __mips
+ # define ASM __asm__("$sp")
+ #elif defined __sparc__
+ # define ASM __asm__("sp")
+ #elif defined __ia64__
+ # define ASM __asm__("r12")
+ #elif defined __hppa__
+ # define ASM __asm__("%r30")
+ #elif defined __xtensa__
+ # define ASM __asm__("sp")
+ #else
+ /* The register name should be target-dependent so for other targets,
+ we just silence the test. */
+ # define ASM = 0
+ #endif
+
+ void *load_PCB (void)
+ {
+ register void *sp ASM;
+ return sp; /* { dg-bogus "uninitialized" } */
+ }
Index: gcc/testsuite/gcc.dg/uninit-I-O0.c
===================================================================
*** /dev/null 1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/uninit-I-O0.c 2008-07-30 17:24:55.000000000 +0200
***************
*** 0 ****
--- 1,8 ----
+ /* { dg-do compile } */
+ /* { dg-options "-Wuninitialized" } */
+
+ int sys_msgctl (void)
+ {
+ struct { int mode; } setbuf; /* { dg-warning "'setbuf\.mode' is used" {} { xfail *-*-* } } */
+ return setbuf.mode;
+ }
Index: gcc/doc/invoke.texi
===================================================================
*** gcc/doc/invoke.texi.orig 2008-07-24 13:57:32.000000000 +0200
--- gcc/doc/invoke.texi 2008-07-30 17:19:44.000000000 +0200
*************** Options} and @ref{Objective-C and Object
*** 2694,2700 ****
-Wstrict-overflow=1 @gol
-Wswitch @gol
-Wtrigraphs @gol
! -Wuninitialized @r{(only with} @option{-O1} @r{and above)} @gol
-Wunknown-pragmas @gol
-Wunused-function @gol
-Wunused-label @gol
--- 2694,2700 ----
-Wstrict-overflow=1 @gol
-Wswitch @gol
-Wtrigraphs @gol
! -Wuninitialized @gol
-Wunknown-pragmas @gol
-Wunused-function @gol
-Wunused-label @gol
*************** name is still supported, but the newer n
*** 2728,2734 ****
-Woverride-init @gol
-Wsign-compare @gol
-Wtype-limits @gol
! -Wuninitialized @r{(only with} @option{-O1} @r{and above)} @gol
-Wunused-parameter @r{(only with} @option{-Wunused} @r{or} @option{-Wall}@r{)} @gol
}
--- 2728,2734 ----
-Woverride-init @gol
-Wsign-compare @gol
-Wtype-limits @gol
! -Wuninitialized @gol
-Wunused-parameter @r{(only with} @option{-Wunused} @r{or} @option{-Wall}@r{)} @gol
}
*************** can be disabled with the @option{-Wno-no
*** 2890,2897 ****
@opindex Winit-self
@opindex Wno-init-self
Warn about uninitialized variables which are initialized with themselves.
! Note this option can only be used with the @option{-Wuninitialized} option,
! which in turn only works with @option{-O1} and above.
For example, GCC will warn about @code{i} being uninitialized in the
following snippet only when @option{-Winit-self} has been specified:
--- 2890,2896 ----
@opindex Winit-self
@opindex Wno-init-self
Warn about uninitialized variables which are initialized with themselves.
! Note this option can only be used with the @option{-Wuninitialized} option.
For example, GCC will warn about @code{i} being uninitialized in the
following snippet only when @option{-Winit-self} has been specified:
*************** either specify @samp{-Wextra -Wunused} (
*** 3174,3185 ****
Warn if an automatic variable is used without first being initialized or
if a variable may be clobbered by a @code{setjmp} call.
- These warnings are possible only in optimizing compilation,
- because they require data flow information that is computed only
- when optimizing. If you do not specify @option{-O}, you will not get
- these warnings. Instead, GCC will issue a warning about @option{-Wuninitialized}
- requiring @option{-O}.
-
If you want to warn about code which uses the uninitialized value of the
variable in its own initializer, use the @option{-Winit-self} option.
--- 3173,3178 ----
*************** Some spurious warnings can be avoided if
*** 3250,3257 ****
you use that never return as @code{noreturn}. @xref{Function
Attributes}.
! This warning is enabled by @option{-Wall} or @option{-Wextra} in
! optimizing compilations (@option{-O1} and above).
@item -Wunknown-pragmas
@opindex Wunknown-pragmas
--- 3243,3249 ----
you use that never return as @code{noreturn}. @xref{Function
Attributes}.
! This warning is enabled by @option{-Wall} or @option{-Wextra}.
@item -Wunknown-pragmas
@opindex Wunknown-pragmas
Index: gcc/doc/passes.texi
===================================================================
*** gcc/doc/passes.texi.orig 2008-07-30 17:20:54.000000000 +0200
--- gcc/doc/passes.texi 2008-07-30 17:21:10.000000000 +0200
*************** located in @file{tree-ssa.c} and is desc
*** 275,281 ****
This pass scans the function for uses of @code{SSA_NAME}s that
are fed by default definition. For non-parameter variables, such
uses are uninitialized. The pass is run twice, before and after
! optimization. In the first pass we only warn for uses that are
positively uninitialized; in the second pass we warn for uses that
are possibly uninitialized. The pass is located in @file{tree-ssa.c}
and is defined by @code{pass_early_warn_uninitialized} and
--- 275,281 ----
This pass scans the function for uses of @code{SSA_NAME}s that
are fed by default definition. For non-parameter variables, such
uses are uninitialized. The pass is run twice, before and after
! optimization (if turned on). In the first pass we only warn for uses that are
positively uninitialized; in the second pass we warn for uses that
are possibly uninitialized. The pass is located in @file{tree-ssa.c}
and is defined by @code{pass_early_warn_uninitialized} and
Index: gcc/testsuite/gcc.dg/pr3074-1.c
===================================================================
*** gcc/testsuite/gcc.dg/pr3074-1.c.orig 2006-02-07 11:14:14.000000000 +0100
--- gcc/testsuite/gcc.dg/pr3074-1.c 2008-07-30 17:26:56.000000000 +0200
***************
*** 2,10 ****
/* { dg-do compile } */
/* { dg-options "-Wall" } */
! void foo()
{
- int a;
5 * (a == 1) | (a == 2); /* { dg-warning "no effect" "no effect" } */
}
--- 2,9 ----
/* { dg-do compile } */
/* { dg-options "-Wall" } */
! void foo(int a)
{
5 * (a == 1) | (a == 2); /* { dg-warning "no effect" "no effect" } */
}