]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/179 (-Wuninitialized missing warning with &var)
authorManuel López-Ibáñez <manu@gcc.gnu.org>
Wed, 20 Aug 2008 22:23:45 +0000 (22:23 +0000)
committerManuel López-Ibáñez <manu@gcc.gnu.org>
Wed, 20 Aug 2008 22:23:45 +0000 (22:23 +0000)
2008-08-21  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

PR middle-end/179
* tree-ssa.c (warn_uninit): Do not warn for variables that can be
initialized outside the current module.
(warn_uninitialized_var): Ignore left-hand side when walking the
trees. Ignore address expressions. Examine VUSE operands in gimple
statements with a variable declaration on the right-hand side.
testsuite/
* gcc.dg/uninit-6.c (make_something): Remove XFAIL.
* gcc.dg/uninit-6-O0.c (make_something): Remove XFAIL.
* gcc.dg/uninit-B.c (baz): Remove XFAIL.
* gcc.dg/uninit-B-2.c: New.
* gcc.dg/uninit-B-O0-2.c: New.
* gcc.dg/uninit-pr19430-O0.c: New.
* gcc.dg/uninit-pr19430.c: New.
* gcc.dg/uninit-pr19430-2.c: New.

From-SVN: r139347

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/uninit-6-O0.c
gcc/testsuite/gcc.dg/uninit-6.c
gcc/testsuite/gcc.dg/uninit-B-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-B-O0-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-B.c
gcc/testsuite/gcc.dg/uninit-pr19430-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-pr19430-O0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-pr19430.c [new file with mode: 0644]
gcc/tree-ssa.c

index 331e37cb0d68ff8e623f816e290a564f708b8886..3621422d627bec2463b71f6926bb26f852413552 100644 (file)
@@ -1,3 +1,12 @@
+2008-08-21  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       PR middle-end/179
+       * tree-ssa.c (warn_uninit): Do not warn for variables that can be
+       initialized outside the current module.
+       (warn_uninitialized_var): Ignore left-hand side when walking the
+       trees. Ignore address expressions. Examine VUSE operands in gimple
+       statements with a variable declaration on the right-hand side.
+
 2008-08-20  Richard Sandiford  <rdsandiford@googlemail.com>
 
        PR bootstrap/37155
index 448279ef886e400b94f2be714b5b5c9426aa5c75..e8a0678a37bd39bdb3b716ec6ca23fec943533da 100644 (file)
@@ -1,3 +1,15 @@
+2008-08-21  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       PR middle-end/179
+       * gcc.dg/uninit-6.c (make_something): Remove XFAIL.
+       * gcc.dg/uninit-6-O0.c (make_something): Remove XFAIL.
+       * gcc.dg/uninit-B.c (baz): Remove XFAIL.
+       * gcc.dg/uninit-B-2.c: New.
+       * gcc.dg/uninit-B-O0-2.c: New.
+       * gcc.dg/uninit-pr19430-O0.c: New.
+       * gcc.dg/uninit-pr19430.c: New.
+       * gcc.dg/uninit-pr19430-2.c: New.
+
 2008-08-20  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
 
        PR c++/35158
index e3fefe5e1c5ac154fd3fe53a7a361dec2700e49d..f4588305ffa3aaf6b578b4bfd57cfaf3b981e78c 100644 (file)
@@ -39,7 +39,7 @@ make_something(int a, int b, int c)
     rv = malloc (sizeof (struct tree));
     rv->car = 0;
 
-    APPEND(rv, field, INTEGER_T, a);  /* { dg-bogus "field" "uninitialized variable warning" { xfail *-*-* } } */
+    APPEND(rv, field, INTEGER_T, a);  /* { dg-bogus "field" "uninitialized variable warning" } */
     APPEND(rv, field, PTR_T, b);
     APPEND(rv, field, INTEGER_T, c);
 
index b0f2083ab4b8676e128c6f85a7ecfd4b8d0ae779..009e124fccf8972f22ba720224f7400f22f85c89 100644 (file)
@@ -39,7 +39,7 @@ make_something(int a, int b, int c)
     rv = malloc (sizeof (struct tree));
     rv->car = 0;
 
-    APPEND(rv, field, INTEGER_T, a);  /* { dg-bogus "field" "uninitialized variable warning" { xfail *-*-* } } */
+    APPEND(rv, field, INTEGER_T, a);  /* { dg-bogus "field" "uninitialized variable warning" } */
     APPEND(rv, field, PTR_T, b);
     APPEND(rv, field, INTEGER_T, c);
 
diff --git a/gcc/testsuite/gcc.dg/uninit-B-2.c b/gcc/testsuite/gcc.dg/uninit-B-2.c
new file mode 100644 (file)
index 0000000..ee8a885
--- /dev/null
@@ -0,0 +1,16 @@
+/* Origin: PR c/179 inverse of uninit-B-O0.c, we should not warn.  */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wuninitialized" } */
+extern void foo (int *);
+extern void bar (int);
+
+void
+baz (void)
+{
+  int i;
+  foo (&i); /* { dg-bogus "is used uninitialized" "uninit i warning" } */
+  if (i) 
+    bar (i);
+}
+
+
diff --git a/gcc/testsuite/gcc.dg/uninit-B-O0-2.c b/gcc/testsuite/gcc.dg/uninit-B-O0-2.c
new file mode 100644 (file)
index 0000000..dfa3de9
--- /dev/null
@@ -0,0 +1,16 @@
+/* Origin: PR c/179 inverse of uninit-B-O0.c, we should not warn.  */
+/* { dg-do compile } */
+/* { dg-options "-O0 -Wuninitialized" } */
+extern void foo (int *);
+extern void bar (int);
+
+void
+baz (void)
+{
+  int i;
+  foo (&i); /* { dg-bogus "is used uninitialized" "uninit i warning" } */
+  if (i) 
+    bar (i);
+}
+
+
index 450bb388da60074a07c6e72bb28f54a9e33f4409..adb1461d951087ee9658887be607d73e9b51b1b1 100644 (file)
@@ -9,7 +9,7 @@ void
 baz (void)
 {
   int i;
-  if (i) /* { dg-warning "uninit" "uninit i warning" { xfail *-*-* } } */
+  if (i) /* { dg-warning "is used uninitialized" "uninit i warning" } */
     bar (i);
   foo (&i);
 }
diff --git a/gcc/testsuite/gcc.dg/uninit-pr19430-2.c b/gcc/testsuite/gcc.dg/uninit-pr19430-2.c
new file mode 100644 (file)
index 0000000..361a6a0
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O -Wuninitialized" } */
+
+int  *p, *q;
+
+int foo (int b)
+{
+  int i, j = 0;
+  int *x;
+  p = &i;
+  q = &j;
+  if (b)
+    x = p;
+  else
+    x = q;
+  return *x;
+}
+
diff --git a/gcc/testsuite/gcc.dg/uninit-pr19430-O0.c b/gcc/testsuite/gcc.dg/uninit-pr19430-O0.c
new file mode 100644 (file)
index 0000000..4ce2586
--- /dev/null
@@ -0,0 +1,43 @@
+/* { dg-do compile } */
+/* { dg-options "-O0 -Wuninitialized" } */
+extern int bar (int);
+extern void baz (int *);
+
+int
+foo (int i)
+{
+  int j; /* { dg-warning "'j' may be used uninitialized in this function" "uninitialized" { xfail *-*-* } 9 } */
+
+  if (bar (i)) {
+    baz (&j);
+  } else {
+  }
+
+  return j;
+}
+
+
+int foo2( void ) {
+  int rc;  /* { dg-warning "'rc' is used uninitialized in this function" "uninitialized" { xfail *-*-* } 21 } */
+  return rc;
+  *&rc = 0;
+}
+
+extern int printf(const char *, ...);
+void frob(int *pi);
+
+int main(void)
+{
+  int i; 
+  printf("i = %d\n", i); /* { dg-warning "'i' is used uninitialized in this function" "uninitialized" { xfail *-*-* } 32 } */
+  frob(&i);
+
+  return 0;
+}
+
+void foo3(int*);
+void bar3(void) { 
+  int x; 
+  if(x) /* { dg-warning "'x' is used uninitialized in this function" "uninitialized" { xfail *-*-* } 41 } */
+    foo3(&x); 
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-pr19430.c b/gcc/testsuite/gcc.dg/uninit-pr19430.c
new file mode 100644 (file)
index 0000000..ecf9c00
--- /dev/null
@@ -0,0 +1,43 @@
+/* { dg-do compile } */
+/* { dg-options "-O -Wuninitialized" } */
+extern int bar (int);
+extern void baz (int *);
+int
+foo (int i)
+{
+  int j; /* { dg-warning "'j' may be used uninitialized in this function" "uninitialized" { xfail *-*-* } 8 } */
+
+  if (bar (i)) { 
+    baz (&j);
+  } else {
+  }
+
+  return j;
+}
+
+
+
+int foo2( void ) {
+  int rc;  /* { dg-warning "'rc' is used uninitialized in this function" } */
+  return rc;
+  *&rc = 0;
+}
+
+extern int printf(const char *, ...);
+void frob(int *pi);
+
+int main(void)
+{
+  int i; 
+  printf("i = %d\n", i); /* { dg-warning "'i' is used uninitialized in this function" } */
+  frob(&i);
+
+  return 0;
+}
+
+void foo3(int*);
+void bar3(void) { 
+  int x; 
+  if(x) /* { dg-warning "'x' is used uninitialized in this function" "uninitialized" } */
+    foo3(&x); 
+}
index fb692f8daa132b5c0b2bbdca395bdb111de27c96..eed15c6773f7f03067e848f656123577572677a6 100644 (file)
@@ -1411,6 +1411,10 @@ warn_uninit (tree t, const char *gmsgid, void *data)
   if (TREE_NO_WARNING (var))
     return;
 
+  /* Do not warn if it can be initialized outside this module.  */
+  if (is_global_var (var))
+    return;
+  
   location = (context != NULL && gimple_has_location (context))
             ? gimple_location (context)
             : DECL_SOURCE_LOCATION (var);
@@ -1443,8 +1447,46 @@ warn_uninitialized_var (tree *tp, int *walk_subtrees, void *data_)
   struct walk_data *data = (struct walk_data *) wi->info;
   tree t = *tp;
 
+  /* We do not care about LHS.  */
+  if (wi->is_lhs)
+    return NULL_TREE;
+
   switch (TREE_CODE (t))
     {
+    case ADDR_EXPR:
+      /* Taking the address of an uninitialized variable does not
+        count as using it.  */
+      *walk_subtrees = 0;
+      break;
+
+    case VAR_DECL:
+      {
+       /* A VAR_DECL in the RHS of a gimple statement may mean that
+          this variable is loaded from memory.  */
+       use_operand_p vuse;
+       tree op;
+
+       /* If there is not gimple stmt, 
+          or alias information has not been computed,
+          then we cannot check VUSE ops.  */
+       if (data->stmt == NULL
+            || !gimple_aliases_computed_p (cfun))
+         return NULL_TREE;
+
+       vuse = SINGLE_SSA_USE_OPERAND (data->stmt, SSA_OP_VUSE);
+       if (vuse == NULL_USE_OPERAND_P)
+           return NULL_TREE;
+
+       op = USE_FROM_PTR (vuse);
+       if (t != SSA_NAME_VAR (op) 
+           || !SSA_NAME_IS_DEFAULT_DEF (op))
+         return NULL_TREE;
+       /* If this is a VUSE of t and it is the default definition,
+          then warn about op.  */
+       t = op;
+       /* Fall through into SSA_NAME.  */
+      }
+
     case SSA_NAME:
       /* We only do data flow with SSA_NAMEs, so that's all we
         can warn about.  */