OSDN Git Service

2008-07-31 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 31 Jul 2008 10:25:11 +0000 (10:25 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 31 Jul 2008 10:25:11 +0000 (10:25 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@138376 138bc75d-0d04-0410-961f-82ee72b054a4

32 files changed:
gcc/ChangeLog
gcc/doc/invoke.texi
gcc/doc/passes.texi
gcc/opts.c
gcc/passes.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wall.c
gcc/testsuite/gcc.dg/Wno-all.c
gcc/testsuite/gcc.dg/pr3074-1.c
gcc/testsuite/gcc.dg/uninit-1-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-10-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-11-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-12-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-13-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-14-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-15-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-2-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-3-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-4-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-5-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-6-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-8-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-9-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-A-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-B-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-C-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-D-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-E-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-F-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-G-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-H-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-I-O0.c [new file with mode: 0644]

index 7da323b..cb7a67b 100644 (file)
@@ -1,3 +1,12 @@
+2008-07-31  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.
+
 2008-07-31  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/36970
index 764edc2..33f0018 100644 (file)
@@ -2696,7 +2696,7 @@ Options} and @ref{Objective-C and Objective-C++ Dialect Options}.
 -Wstrict-overflow=1  @gol
 -Wswitch  @gol
 -Wtrigraphs  @gol
--Wuninitialized @r{(only with} @option{-O1} @r{and above)}  @gol
+-Wuninitialized  @gol
 -Wunknown-pragmas  @gol
 -Wunused-function  @gol
 -Wunused-label     @gol
@@ -2730,7 +2730,7 @@ name is still supported, but the newer name is more descriptive.)
 -Woverride-init  @gol
 -Wsign-compare  @gol
 -Wtype-limits  @gol
--Wuninitialized @r{(only with} @option{-O1} @r{and above)}  @gol
+-Wuninitialized  @gol
 -Wunused-parameter @r{(only with} @option{-Wunused} @r{or} @option{-Wall}@r{)}  @gol
 }
 
@@ -2892,8 +2892,7 @@ can be disabled with the @option{-Wno-nonnull} option.
 @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.
+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:
@@ -3176,12 +3175,6 @@ either specify @samp{-Wextra -Wunused} (note that @samp{-Wall} implies
 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.
 
@@ -3252,8 +3245,7 @@ Some spurious warnings can be avoided if you declare all the functions
 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).
+This warning is enabled by @option{-Wall} or @option{-Wextra}.
 
 @item -Wunknown-pragmas
 @opindex Wunknown-pragmas
index 4b0c0b6..a229538 100644 (file)
@@ -275,7 +275,7 @@ located in @file{tree-ssa.c} and is described by @code{pass_build_ssa}.
 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
+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 13a7de1..5451251 100644 (file)
@@ -1080,13 +1080,6 @@ decode_options (unsigned int argc, const char **argv)
         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
index d07a5ca..c6f6c8a 100644 (file)
@@ -544,10 +544,10 @@ init_optimization_passes (void)
       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_early_warn_uninitialized);
          NEXT_PASS (pass_rebuild_cgraph_edges);
          NEXT_PASS (pass_early_inline);
          NEXT_PASS (pass_cleanup_cfg);
index 40924d4..1900013 100644 (file)
@@ -1,3 +1,32 @@
+2008-07-31  Richard Guenther  <rguenther@suse.de>
+
+       * 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.
+
 2008-07-31  Arnaud Charlet  <charlet@adacore.com>
 
        * gnat.dg/specs/genericppc.ads: New test.
index 86a359b..8984847 100644 (file)
@@ -3,8 +3,7 @@
 /* { dg-do compile } */
 /* { dg-options "-Wall" } */
 
-void foo()
+void foo(int a)
 {
-  int a;
   5 * (a == 1) | (a == 2);  /* { dg-warning "no effect" "no effect" } */
 }
index 3275eb6..de55bbc 100644 (file)
@@ -3,9 +3,8 @@
 /* { dg-do compile } */
 /* { dg-options "-Wall -Wno-all" } */
 
-void foo()
+void foo(int a)
 {
-  int a;
   5 * (a == 1) | (a == 2);  /* { dg-bogus "no effect" "no effect" } */
 }
 
index c2258d5..4716b79 100644 (file)
@@ -2,9 +2,8 @@
 /* { dg-do compile } */
 /* { dg-options "-Wall" } */
 
-void foo()
+void foo(int a)
 {
-  int a;
   5 * (a == 1) | (a == 2);  /* { dg-warning "no effect" "no effect" } */
 }
 
diff --git a/gcc/testsuite/gcc.dg/uninit-1-O0.c b/gcc/testsuite/gcc.dg/uninit-1-O0.c
new file mode 100644 (file)
index 0000000..4fe5d6b
--- /dev/null
@@ -0,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;
+  }
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-10-O0.c b/gcc/testsuite/gcc.dg/uninit-10-O0.c
new file mode 100644 (file)
index 0000000..f761ac9
--- /dev/null
@@ -0,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;
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-11-O0.c b/gcc/testsuite/gcc.dg/uninit-11-O0.c
new file mode 100644 (file)
index 0000000..23af4f6
--- /dev/null
@@ -0,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;
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-12-O0.c b/gcc/testsuite/gcc.dg/uninit-12-O0.c
new file mode 100644 (file)
index 0000000..7c0664e
--- /dev/null
@@ -0,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;
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-13-O0.c b/gcc/testsuite/gcc.dg/uninit-13-O0.c
new file mode 100644 (file)
index 0000000..af80fa8
--- /dev/null
@@ -0,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;
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-14-O0.c b/gcc/testsuite/gcc.dg/uninit-14-O0.c
new file mode 100644 (file)
index 0000000..abde6ca
--- /dev/null
@@ -0,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;
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-15-O0.c b/gcc/testsuite/gcc.dg/uninit-15-O0.c
new file mode 100644 (file)
index 0000000..a3fd2b6
--- /dev/null
@@ -0,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();
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-2-O0.c b/gcc/testsuite/gcc.dg/uninit-2-O0.c
new file mode 100644 (file)
index 0000000..62a23fa
--- /dev/null
@@ -0,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);
+    }
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-3-O0.c b/gcc/testsuite/gcc.dg/uninit-3-O0.c
new file mode 100644 (file)
index 0000000..d3dcf14
--- /dev/null
@@ -0,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;
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-4-O0.c b/gcc/testsuite/gcc.dg/uninit-4-O0.c
new file mode 100644 (file)
index 0000000..0b9aeea
--- /dev/null
@@ -0,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();
+    }
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-5-O0.c b/gcc/testsuite/gcc.dg/uninit-5-O0.c
new file mode 100644 (file)
index 0000000..d9784b3
--- /dev/null
@@ -0,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);
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-6-O0.c b/gcc/testsuite/gcc.dg/uninit-6-O0.c
new file mode 100644 (file)
index 0000000..e3fefe5
--- /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 "-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;
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-8-O0.c b/gcc/testsuite/gcc.dg/uninit-8-O0.c
new file mode 100644 (file)
index 0000000..b386896
--- /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 "-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;
+    }
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-9-O0.c b/gcc/testsuite/gcc.dg/uninit-9-O0.c
new file mode 100644 (file)
index 0000000..493dd68
--- /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 "-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]);
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-A-O0.c b/gcc/testsuite/gcc.dg/uninit-A-O0.c
new file mode 100644 (file)
index 0000000..6937691
--- /dev/null
@@ -0,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;
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-B-O0.c b/gcc/testsuite/gcc.dg/uninit-B-O0.c
new file mode 100644 (file)
index 0000000..e2883a3
--- /dev/null
@@ -0,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);
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-C-O0.c b/gcc/testsuite/gcc.dg/uninit-C-O0.c
new file mode 100644 (file)
index 0000000..305dd36
--- /dev/null
@@ -0,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;
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-D-O0.c b/gcc/testsuite/gcc.dg/uninit-D-O0.c
new file mode 100644 (file)
index 0000000..e63cb80
--- /dev/null
@@ -0,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;
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-E-O0.c b/gcc/testsuite/gcc.dg/uninit-E-O0.c
new file mode 100644 (file)
index 0000000..2cc2459
--- /dev/null
@@ -0,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;
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-F-O0.c b/gcc/testsuite/gcc.dg/uninit-F-O0.c
new file mode 100644 (file)
index 0000000..737cc65
--- /dev/null
@@ -0,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;
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-G-O0.c b/gcc/testsuite/gcc.dg/uninit-G-O0.c
new file mode 100644 (file)
index 0000000..d6edffe
--- /dev/null
@@ -0,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;
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-H-O0.c b/gcc/testsuite/gcc.dg/uninit-H-O0.c
new file mode 100644 (file)
index 0000000..9722146
--- /dev/null
@@ -0,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" } */
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-I-O0.c b/gcc/testsuite/gcc.dg/uninit-I-O0.c
new file mode 100644 (file)
index 0000000..655f548
--- /dev/null
@@ -0,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;
+}