]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
*** empty log message ***
authorpinskia <pinskia@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 19 Aug 2003 20:12:44 +0000 (20:12 +0000)
committerpinskia <pinskia@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 19 Aug 2003 20:12:44 +0000 (20:12 +0000)
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@70573 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/c-common.c
gcc/testsuite/gcc.dg/uninit-D.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-E.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-F.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-G.c [new file with mode: 0644]

index 267ede38197ab3dcdcd055ed5ad46de4ab5fc172..7b09e5d6f8e00edd5edf9caa38af23ee881199a2 100644 (file)
@@ -412,6 +412,11 @@ int warn_main;
 
 int warn_sequence_point;
 
+/* Nonzero means warn about uninitialized variable when it is initialized with itself.
+   For example: int i = i;, GCC will not warn about this when warn_init_self is nonzero. */
+
+int warn_init_self;
+
 /* Nonzero means to warn about compile-time division by zero.  */
 int warn_div_by_zero = 1;
 
@@ -5729,4 +5734,35 @@ c_estimate_num_insns (tree decl)
   return num;
 }
 
+/* Used by c_decl_uninit to find where expressions like x = x + 1; */
+
+static tree
+c_decl_uninit_1 (tree *t, int *walk_sub_trees, void *x)
+{
+  /* If x = EXP(&x)EXP, then do not warn about the use of x. */
+  if (TREE_CODE (*t) == ADDR_EXPR && TREE_OPERAND (*t, 0) == x)
+    {
+      *walk_sub_trees = 0;
+      return NULL_TREE;
+    }
+  if (*t == x)
+    return *t;
+  return NULL_TREE;
+}
+
+/* Find out if a variable is uninitialized based on DECL_INITIAL.  */
+
+bool
+c_decl_uninit (tree t)
+{
+  /* int x = x; is GCC extension to turn off this warning, only if warn_init_self is zero. */
+  if (DECL_INITIAL (t) == t)
+    return warn_init_self ? true : false;
+
+  /* Walk the trees looking for the variable itself. */
+  if (walk_tree_without_duplicates (&DECL_INITIAL (t), c_decl_uninit_1, t))
+    return true;
+  return false;
+}
+
 #include "gt-c-common.h"
diff --git a/gcc/testsuite/gcc.dg/uninit-D.c b/gcc/testsuite/gcc.dg/uninit-D.c
new file mode 100644 (file)
index 0000000..ea957e4
--- /dev/null
@@ -0,0 +1,9 @@
+/* Test we do not warn about initializing variable with self. */
+/* { dg-do compile } */
+/* { dg-options "-O -Wuninitialized" } */
+
+int f()
+{
+  int i = i;
+  return i;
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-E.c b/gcc/testsuite/gcc.dg/uninit-E.c
new file mode 100644 (file)
index 0000000..42b8430
--- /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 "-O -Wuninitialized -Winit-self" } */
+
+int f()
+{
+  int i = i;
+  return i;
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-F.c b/gcc/testsuite/gcc.dg/uninit-F.c
new file mode 100644 (file)
index 0000000..1dbb365
--- /dev/null
@@ -0,0 +1,9 @@
+/* Test we do warn about initializing variable with self in the initialization. */
+/* { dg-do compile } */
+/* { dg-options "-O -Wuninitialized" } */
+
+int f()
+{
+  int i = i + 1; /* { dg-warning "i" "uninitialized variable warning" }  */
+  return i;
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-G.c b/gcc/testsuite/gcc.dg/uninit-G.c
new file mode 100644 (file)
index 0000000..08f5f53
--- /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 "-O -Wuninitialized" } */
+
+void *f()
+{
+  void *i = &i;
+  return i;
+}