diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2007-11-26 22:47:23 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2007-11-26 22:47:23 +0000 |
commit | 411b684d5c659555d94f6bd0893da1da15ef157f (patch) | |
tree | 976cb2039c130b2390eb6e951531f6c229500d5a /gnu | |
parent | 39c42e0288ffa508378cb82d08d4718cc37f4a02 (diff) |
Add a new warning to gcc, -Wvariable-decl, which causes it to warn for
auto declarations which size are not known at compile time.
This flag will eventually be added to the kernel makefiles so that we
can rely on -Wstack-larger-than work.
ok deraadt@ mbalmer@ otto@ marco@
Diffstat (limited to 'gnu')
-rw-r--r-- | gnu/egcs/gcc/flags.h | 5 | ||||
-rw-r--r-- | gnu/egcs/gcc/stmt.c | 3 | ||||
-rw-r--r-- | gnu/egcs/gcc/toplev.c | 10 | ||||
-rw-r--r-- | gnu/usr.bin/gcc/gcc/flags.h | 5 | ||||
-rw-r--r-- | gnu/usr.bin/gcc/gcc/stmt.c | 5 | ||||
-rw-r--r-- | gnu/usr.bin/gcc/gcc/toplev.c | 7 |
6 files changed, 33 insertions, 2 deletions
diff --git a/gnu/egcs/gcc/flags.h b/gnu/egcs/gcc/flags.h index a63a4e5ab14..c2e0369ab6b 100644 --- a/gnu/egcs/gcc/flags.h +++ b/gnu/egcs/gcc/flags.h @@ -143,6 +143,11 @@ extern unsigned stack_larger_than_size; extern int warn_aggregate_return; +/* Nonzero means warn about any automatic declaration whose size is not + constant. */ + +extern int warn_variable_decl; + /* Nonzero if generating code to do profiling. */ extern int profile_flag; diff --git a/gnu/egcs/gcc/stmt.c b/gnu/egcs/gcc/stmt.c index 7f8a571c4d1..26950fbafd4 100644 --- a/gnu/egcs/gcc/stmt.c +++ b/gnu/egcs/gcc/stmt.c @@ -3598,6 +3598,9 @@ expand_decl (decl) { rtx address, size; + if (warn_variable_decl) + warning ("variable-sized declaration"); + /* Record the stack pointer on entry to block, if have not already done so. */ if (thisblock->data.block.stack_level == 0) diff --git a/gnu/egcs/gcc/toplev.c b/gnu/egcs/gcc/toplev.c index f8f616fb300..3757bb9ac3f 100644 --- a/gnu/egcs/gcc/toplev.c +++ b/gnu/egcs/gcc/toplev.c @@ -1272,6 +1272,12 @@ int warn_inline; int warn_aggregate_return; +/* Nonzero means warn about any automatic declaration whose size is not + constant. */ + +int warn_variable_decl; + + /* Likewise for -W. */ lang_independent_options W_options[] = @@ -1292,7 +1298,9 @@ lang_independent_options W_options[] = {"stack-protector", &warn_stack_protector, 1, "Warn when disabling stack protector for some reason"}, {"trampolines", &warn_trampolines, 1, - "Warn when trampolines are emitted"} + "Warn when trampolines are emitted"}, + {"variable-decl", &warn_variable_decl, 1, + "Warn about variable-sized declarations"} }; /* Output files for assembler code (real compiler output) diff --git a/gnu/usr.bin/gcc/gcc/flags.h b/gnu/usr.bin/gcc/gcc/flags.h index 1a61fc6d1ce..d4e1adeb373 100644 --- a/gnu/usr.bin/gcc/gcc/flags.h +++ b/gnu/usr.bin/gcc/gcc/flags.h @@ -195,6 +195,11 @@ extern int warn_deprecated_decl; extern int warn_strict_aliasing; +/* Nonzero means warn about any automatic declaration whose size is not + constant. */ + +extern int warn_variable_decl; + /* Nonzero if generating code to do profiling. */ extern int profile_flag; diff --git a/gnu/usr.bin/gcc/gcc/stmt.c b/gnu/usr.bin/gcc/gcc/stmt.c index 89b9840c25d..8749a9b7203 100644 --- a/gnu/usr.bin/gcc/gcc/stmt.c +++ b/gnu/usr.bin/gcc/gcc/stmt.c @@ -546,9 +546,9 @@ expand_computed_goto (exp) { cfun->computed_goto_common_reg = copy_to_mode_reg (Pmode, x); cfun->computed_goto_common_label = gen_label_rtx (); - emit_label (cfun->computed_goto_common_label); do_pending_stack_adjust (); + emit_label (cfun->computed_goto_common_label); emit_indirect_jump (cfun->computed_goto_common_reg); current_function_has_computed_jump = 1; @@ -3996,6 +3996,9 @@ expand_decl (decl) { rtx address, size, x; + if (warn_variable_decl) + warning ("variable-sized declaration"); + /* Record the stack pointer on entry to block, if have not already done so. */ do_pending_stack_adjust (); diff --git a/gnu/usr.bin/gcc/gcc/toplev.c b/gnu/usr.bin/gcc/gcc/toplev.c index c9327da33bd..d9891b2d14e 100644 --- a/gnu/usr.bin/gcc/gcc/toplev.c +++ b/gnu/usr.bin/gcc/gcc/toplev.c @@ -1535,6 +1535,11 @@ int warn_deprecated_decl = 1; int warn_strict_aliasing; +/* Nonzero means warn about any automatic declaration whose size is not + constant. */ + +int warn_variable_decl; + /* Likewise for -W. */ static const lang_independent_options W_options[] = @@ -1587,6 +1592,8 @@ static const lang_independent_options W_options[] = N_("Warn when disabling stack protector for some reason")}, {"trampolines", &warn_trampolines, 1, N_("Warn when trampolines are emitted")}, + {"variable-decl", &warn_variable_decl, 1, + N_("Warn about variable-sized declarations")}, }; void |