From: Martin Liska Date: Mon, 22 Jul 2019 09:38:26 +0000 (+0200) Subject: Backport r273660 X-Git-Tag: releases/gcc-7.5.0~343 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5a7b9f065ef49947ea63955eec767b82641a941;p=thirdparty%2Fgcc.git Backport r273660 2019-07-22 Martin Liska Backport from mainline 2019-07-22 Martin Liska PR driver/91172 * opts-common.c (decode_cmdline_option): Decode argument of -Werror and check it for a wrong language. * opts-global.c (complain_wrong_lang): Remove such case. 2019-07-22 Martin Liska Backport from mainline 2019-07-22 Martin Liska PR driver/91172 * gcc.dg/pr91172.c: New test. From-SVN: r273666 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9f12f4238153..7661fff3153b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2019-07-22 Martin Liska + + Backport from mainline + 2019-07-22 Martin Liska + + PR driver/91172 + * opts-common.c (decode_cmdline_option): Decode + argument of -Werror and check it for a wrong language. + * opts-global.c (complain_wrong_lang): Remove such case. + 2019-07-16 Wilco Dijkstra Backport from mainline diff --git a/gcc/opts-common.c b/gcc/opts-common.c index 3c2553368ace..9b0d76d11485 100644 --- a/gcc/opts-common.c +++ b/gcc/opts-common.c @@ -438,7 +438,8 @@ decode_cmdline_option (const char **argv, unsigned int lang_mask, extra_args = 0; - opt_index = find_opt (argv[0] + 1, lang_mask); + const char *opt_value = argv[0] + 1; + opt_index = find_opt (opt_value, lang_mask); i = 0; while (opt_index == OPT_SPECIAL_unknown && i < ARRAY_SIZE (option_map)) @@ -641,6 +642,23 @@ decode_cmdline_option (const char **argv, unsigned int lang_mask, /* Check if this is a switch for a different front end. */ if (!option_ok_for_language (option, lang_mask)) errors |= CL_ERR_WRONG_LANG; + else if (strcmp (option->opt_text, "-Werror=") == 0 + && strchr (opt_value, ',') == NULL) + { + /* Verify that -Werror argument is a valid warning + for a language. */ + char *werror_arg = xstrdup (opt_value + 6); + werror_arg[0] = 'W'; + + size_t warning_index = find_opt (werror_arg, lang_mask); + if (warning_index != OPT_SPECIAL_unknown) + { + const struct cl_option *warning_option + = &cl_options[warning_index]; + if (!option_ok_for_language (warning_option, lang_mask)) + errors |= CL_ERR_WRONG_LANG; + } + } /* Convert the argument to lowercase if appropriate. */ if (arg && option->cl_tolower) diff --git a/gcc/opts-global.c b/gcc/opts-global.c index bfa2afb1987a..b45d18996a38 100644 --- a/gcc/opts-global.c +++ b/gcc/opts-global.c @@ -100,10 +100,14 @@ complain_wrong_lang (const struct cl_decoded_option *decoded, text, bad_lang); else if (lang_mask == CL_DRIVER) gcc_unreachable (); - else + else if (ok_langs[0] != '\0') /* Eventually this should become a hard error IMO. */ warning (0, "command line option %qs is valid for %s but not for %s", text, ok_langs, bad_lang); + else + /* Happens for -Werror=warning_name. */ + warning (0, "%<-Werror=%> argument %qs is not valid for %s", + text, bad_lang); free (ok_langs); free (bad_lang); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 296f93cb95b1..e0c5f0a39388 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2019-07-22 Martin Liska + + Backport from mainline + 2019-07-22 Martin Liska + + PR driver/91172 + * gcc.dg/pr91172.c: New test. + 2019-07-16 Wilco Dijkstra Backport from mainline