diff options
author | Andrew Pinski <pinskia@gcc.gnu.org> | 2003-08-19 13:12:44 -0700 |
---|---|---|
committer | Andrew Pinski <pinskia@gcc.gnu.org> | 2003-08-19 13:12:44 -0700 |
commit | 02a2edc088afbf09c3c82f5e9d37b58b7155a0ad (patch) | |
tree | 346f1ebd450686d1b4790a3e7d867e9291da3711 /gcc/c-common.c | |
parent | ab3d4713ce0f7e89cde72effba3cb5088e545f0d (diff) | |
download | gcc-02a2edc088afbf09c3c82f5e9d37b58b7155a0ad.zip gcc-02a2edc088afbf09c3c82f5e9d37b58b7155a0ad.tar.gz gcc-02a2edc088afbf09c3c82f5e9d37b58b7155a0ad.tar.bz2 |
*** empty log message ***
From-SVN: r70573
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r-- | gcc/c-common.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c index 267ede3..7b09e5d 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -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" |