From 369dcbd9d2f7d4577f689b46ee3028bc7949049c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20L=C3=B3pez-Ib=C3=A1=C3=B1ez?= Date: Mon, 25 Feb 2008 23:41:43 +0000 Subject: [PATCH] re PR other/28322 (GCC new warnings and compatibility) 2008-02-26 Manuel Lopez-Ibanez PR 28322 * toplev.c (toplev_main): If there are warnings or error, print errors for ignored options. * opts.c (ignored_options): New static variable. (postpone_unknown_option_error): New. (print_ignored_options): New. (handle_option): Postpone errors for unknown -Wno-* options. * opts.h (print_ignored_options): Declare. testsuite/ * gcc.dg/pr28322.c: New. * gcc.dg/pr28322-2.c: New. * lib/prune.exp: Ignore "At top level" even if there is no ':' preceding it. From-SVN: r132648 --- gcc/ChangeLog | 11 +++++++++ gcc/opts.c | 41 ++++++++++++++++++++++++++++++++ gcc/opts.h | 1 + gcc/testsuite/ChangeLog | 8 +++++++ gcc/testsuite/gcc.dg/pr28322-2.c | 12 ++++++++++ gcc/testsuite/gcc.dg/pr28322.c | 8 +++++++ gcc/testsuite/lib/prune.exp | 2 +- gcc/toplev.c | 3 +++ 8 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr28322-2.c create mode 100644 gcc/testsuite/gcc.dg/pr28322.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c05c70cee99..3607c3ce1e7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2008-02-26 Manuel Lopez-Ibanez + + PR 28322 + * toplev.c (toplev_main): If there are warnings or error, print + errors for ignored options. + * opts.c (ignored_options): New static variable. + (postpone_unknown_option_error): New. + (print_ignored_options): New. + (handle_option): Postpone errors for unknown -Wno-* options. + * opts.h (print_ignored_options): Declare. + 2008-02-25 Richard Sandiford * config/mips/mips.md (loadgp_blockage, blockage): Change type diff --git a/gcc/opts.c b/gcc/opts.c index 8b8a1a9c364..8bee44b947a 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -365,6 +365,12 @@ DEF_VEC_ALLOC_P(char_p,heap); static VEC(char_p,heap) *flag_instrument_functions_exclude_functions; static VEC(char_p,heap) *flag_instrument_functions_exclude_files; +typedef const char *const_char_p; /* For DEF_VEC_P. */ +DEF_VEC_P(const_char_p); +DEF_VEC_ALLOC_P(const_char_p,heap); + +static VEC(const_char_p,heap) *ignored_options; + /* Input file names. */ const char **in_fnames; unsigned num_in_fnames; @@ -443,6 +449,33 @@ complain_wrong_lang (const char *text, const struct cl_option *option, free (bad_lang); } +/* Buffer the unknown option described by the string OPT. Currently, + we only complain about unknown -Wno-* options if they may have + prevented a diagnostic. Otherwise, we just ignore them. */ + +static void postpone_unknown_option_error(const char *opt) +{ + VEC_safe_push (const_char_p, heap, ignored_options, opt); +} + +/* Produce an error for each option previously buffered. */ + +void print_ignored_options (void) +{ + location_t saved_loc = input_location; + + input_location = 0; + + while (!VEC_empty (const_char_p, ignored_options)) + { + const char *opt; + opt = VEC_pop (const_char_p, ignored_options); + error ("unrecognized command line option \"%s\"", opt); + } + + input_location = saved_loc; +} + /* Handle the switch beginning at ARGV for the language indicated by LANG_MASK. Returns the number of switches consumed. */ static unsigned int @@ -472,6 +505,14 @@ handle_option (const char **argv, unsigned int lang_mask) opt = dup; value = 0; opt_index = find_opt (opt + 1, lang_mask | CL_COMMON | CL_TARGET); + if (opt_index == cl_options_count) + { + /* We don't generate errors for unknown -Wno-* options + unless we issue diagnostics. */ + postpone_unknown_option_error (argv[0]); + result = 1; + goto done; + } } if (opt_index == cl_options_count) diff --git a/gcc/opts.h b/gcc/opts.h index e6bee109e48..2f543407de0 100644 --- a/gcc/opts.h +++ b/gcc/opts.h @@ -105,4 +105,5 @@ extern bool get_option_state (int, struct cl_option_state *); extern void enable_warning_as_error (const char *arg, int value, unsigned int lang_mask); +extern void print_ignored_options (void); #endif diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 415cae7ccc5..7dd0ff39611 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2008-02-26 Manuel Lopez-Ibanez + + PR 28322 + * gcc.dg/pr28322.c: New. + * gcc.dg/pr28322-2.c: New. + * lib/prune.exp: Ignore "At top level" even if there is no ':' + preceding it. + 2008-02-25 Paolo Carlini PR c++/35333 diff --git a/gcc/testsuite/gcc.dg/pr28322-2.c b/gcc/testsuite/gcc.dg/pr28322-2.c new file mode 100644 index 00000000000..8fde7b21aa3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr28322-2.c @@ -0,0 +1,12 @@ +/* PR28322: ignore unknown -Wno-* if no warning is emitted. */ +/* { dg-do compile } */ +/* { dg-options "-Wall -Wextra -Wno-foobar" } */ + +int foo (void) +{ + int i = 1/0; /* { dg-warning "division by zero" } */ + return i; +} + +/* { dg-message "unrecognized command line option .-Wno-foobar." "" { target *-*-* } 0 } */ + diff --git a/gcc/testsuite/gcc.dg/pr28322.c b/gcc/testsuite/gcc.dg/pr28322.c new file mode 100644 index 00000000000..99872fca8ee --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr28322.c @@ -0,0 +1,8 @@ +/* PR28322: ignore unknown -Wno-* if no warning is emitted. */ +/* { dg-do compile } */ +/* { dg-options " -Wno-foobar -Wno-div-by-zero" } */ + +void foo(void) +{ + int i = 1/0; +} diff --git a/gcc/testsuite/lib/prune.exp b/gcc/testsuite/lib/prune.exp index 2e901a08f4d..d1a9f95bd46 100644 --- a/gcc/testsuite/lib/prune.exp +++ b/gcc/testsuite/lib/prune.exp @@ -21,7 +21,7 @@ proc prune_gcc_output { text } { #send_user "Before:$text\n" regsub -all "(^|\n)(\[^\n\]*: )?In ((static member )?function|member|method|(copy )?constructor|destructor|instantiation|program|subroutine|block-data) \[^\n\]*" $text "" text - regsub -all "(^|\n)\[^\n\]*: At (top level|global scope):\[^\n\]*" $text "" text + regsub -all "(^|\n)\[^\n\]*(: )?At (top level|global scope):\[^\n\]*" $text "" text regsub -all "(^|\n)\[^\n\]*: instantiated from \[^\n\]*" $text "" text regsub -all "(^|\n) inlined from \[^\n\]*" $text "" text regsub -all "(^|\n)collect2: ld returned \[^\n\]*" $text "" text diff --git a/gcc/toplev.c b/gcc/toplev.c index 7a6be498a72..fddf13f3924 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -2282,6 +2282,9 @@ toplev_main (unsigned int argc, const char **argv) if (!exit_after_options) do_compile (); + if (warningcount || errorcount) + print_ignored_options (); + if (errorcount || sorrycount) return (FATAL_EXIT_CODE); -- 2.30.2