From: Manuel López-Ibáñez Date: Thu, 24 Sep 2015 16:37:43 +0000 (+0000) Subject: fdiagnostics-color=never does not disable color for some diagnostics X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3563212292d643dee54ff75771032ea92fe34e78;p=gcc.git fdiagnostics-color=never does not disable color for some diagnostics Actually, I was trying to reject non-warning options as argument to -Werror=. However, the new test fails because -fdiagnostics-color=never is always placed by the driver after the warning options when calling the compiler proper. This patch prunes all -fdiagnostics-color from the command-line but the last one, which is moved to the first position. gcc/ChangeLog: 2015-09-24 Manuel López-Ibáñez PR driver/67640 * opts-common.c (prune_options): Discard all -fdiagnostics-color but the last one, which is moved to the front to be processed first. * opts.c (enable_warning_as_error): Reject options that do not control warnings. gcc/testsuite/ChangeLog: 2015-09-24 Manuel López-Ibáñez PR driver/67640 * gcc.dg/Werror-13.c: New test. From-SVN: r228094 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 05ff03ffa45..d0893001b8e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2015-09-24 Manuel López-Ibáñez + + PR driver/67640 + * opts-common.c (prune_options): Discard all -fdiagnostics-color + but the last one, which is moved to the front to be processed + first. + * opts.c (enable_warning_as_error): Reject options that do not + control warnings. + 2015-09-24 Jiong Wang * config/aarch64/aarch64.c (aarch64_print_operand): Add "CONST" support. diff --git a/gcc/opts-common.c b/gcc/opts-common.c index 3bcbaf18b22..d9bf4d4b897 100644 --- a/gcc/opts-common.c +++ b/gcc/opts-common.c @@ -825,6 +825,7 @@ prune_options (struct cl_decoded_option **decoded_options, = XNEWVEC (struct cl_decoded_option, old_decoded_options_count); unsigned int i; const struct cl_option *option; + unsigned int fdiagnostics_color_idx = 0; /* Remove arguments which are negated by others after them. */ new_decoded_options_count = 0; @@ -844,6 +845,11 @@ prune_options (struct cl_decoded_option **decoded_options, case OPT_SPECIAL_input_file: goto keep; + /* Do not save OPT_fdiagnostics_color_, just remember the last one. */ + case OPT_fdiagnostics_color_: + fdiagnostics_color_idx = i; + continue; + default: gcc_assert (opt_idx < cl_options_count); option = &cl_options[opt_idx]; @@ -879,6 +885,17 @@ keep: } } + if (fdiagnostics_color_idx > 1) + { + /* We put the last -fdiagnostics-color= at the first position + after argv[0] so it can take effect immediately. */ + memmove (new_decoded_options + 2, new_decoded_options + 1, + sizeof (struct cl_decoded_option) + * (new_decoded_options_count - 1)); + new_decoded_options[1] = old_decoded_options[fdiagnostics_color_idx]; + new_decoded_options_count++; + } + free (old_decoded_options); new_decoded_options = XRESIZEVEC (struct cl_decoded_option, new_decoded_options, diff --git a/gcc/opts.c b/gcc/opts.c index f1a9acd7ba0..b437114d401 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -2359,9 +2359,10 @@ enable_warning_as_error (const char *arg, int value, unsigned int lang_mask, strcpy (new_option + 1, arg); option_index = find_opt (new_option, lang_mask); if (option_index == OPT_SPECIAL_unknown) - { - error_at (loc, "-Werror=%s: no option -%s", arg, new_option); - } + error_at (loc, "-Werror=%s: no option -%s", arg, new_option); + else if (!(cl_options[option_index].flags & CL_WARNING)) + error_at (loc, "-Werror=%s: -%s is not an option that controls warnings", + arg, new_option); else { const diagnostic_t kind = value ? DK_ERROR : DK_WARNING; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 912e411d97b..de6131bdd2f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-09-24 Manuel López-Ibáñez + + PR driver/67640 + * gcc.dg/Werror-13.c: New test. + 2015-09-24 Szabolcs Nagy * gcc.target/aarch64/target_attr_10.c (foo): Use dg-message for note. diff --git a/gcc/testsuite/gcc.dg/Werror-13.c b/gcc/testsuite/gcc.dg/Werror-13.c new file mode 100644 index 00000000000..e8aa99261f8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Werror-13.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-Werror=error -Werror=p, -Werror=l, -Werror=fatal-errors" } */ +/* { dg-error "-Wp, is not an option that controls warnings" "" { target *-*-* } 0 } */ +/* { dg-error "-Wl, is not an option that controls warnings" "" { target *-*-* } 0 } */ +/* { dg-error "-Werror is not an option that controls warnings" "" { target *-*-* } 0 } */ +/* { dg-error "-Wfatal-errors is not an option that controls warnings" "" { target *-*-* } 0 } */ + +int i;