* [PATCH] Make a warning for -Werror=wrong-language (PR driver/91172).
@ 2019-07-16 11:18 Martin Liška
2019-07-16 16:40 ` Martin Sebor
0 siblings, 1 reply; 4+ messages in thread
From: Martin Liška @ 2019-07-16 11:18 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1058 bytes --]
Hi.
I noticed in the PR that -Werror=argument argument is not verified
that the option is supported by a language we compile for.
That's changed in the patch. However, it's not ideal as I need to mark
the -Werror as the problematic option and one can't print a proper
list of valid languages for which the rejected option can be used.
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Ready to be installed?
Thanks,
Martin
gcc/ChangeLog:
2019-07-16 Martin Liska <mliska@suse.cz>
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.
gcc/testsuite/ChangeLog:
2019-07-16 Martin Liska <mliska@suse.cz>
PR driver/91172
* gcc.dg/pr91172.c: New test.
---
gcc/opts-common.c | 20 +++++++++++++++++++-
gcc/opts-global.c | 6 +++++-
gcc/testsuite/gcc.dg/pr91172.c | 3 +++
3 files changed, 27 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/pr91172.c
[-- Attachment #2: 0001-Make-a-warning-for-Werror-wrong-language-PR-driver-9.patch --]
[-- Type: text/x-patch, Size: 2468 bytes --]
diff --git a/gcc/opts-common.c b/gcc/opts-common.c
index 660dfe63858..76285bdcf93 100644
--- a/gcc/opts-common.c
+++ b/gcc/opts-common.c
@@ -537,7 +537,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))
@@ -745,6 +746,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 languages. */
+ 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 bf4db775928..f62d6a3cddb 100644
--- a/gcc/opts-global.c
+++ b/gcc/opts-global.c
@@ -103,10 +103,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, "command-line error argument %qs is not valid for %s",
+ text, bad_lang);
free (ok_langs);
free (bad_lang);
diff --git a/gcc/testsuite/gcc.dg/pr91172.c b/gcc/testsuite/gcc.dg/pr91172.c
new file mode 100644
index 00000000000..bf62d94d8a2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr91172.c
@@ -0,0 +1,3 @@
+/* { dg-do compile } */
+/* { dg-options "-Werror=target-lifetime" } */
+/* { dg-warning "command-line error argument '-Werror=target-lifetime' is not valid for C" "" { target *-*-* } 0 } */
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Make a warning for -Werror=wrong-language (PR driver/91172).
2019-07-16 11:18 [PATCH] Make a warning for -Werror=wrong-language (PR driver/91172) Martin Liška
@ 2019-07-16 16:40 ` Martin Sebor
2019-07-17 7:55 ` Martin Liška
0 siblings, 1 reply; 4+ messages in thread
From: Martin Sebor @ 2019-07-16 16:40 UTC (permalink / raw)
To: Martin Liška, gcc-patches
On 7/16/19 5:16 AM, Martin Liška wrote:
> Hi.
>
> I noticed in the PR that -Werror=argument argument is not verified
> that the option is supported by a language we compile for.
> That's changed in the patch. However, it's not ideal as I need to mark
> the -Werror as the problematic option and one can't print a proper
> list of valid languages for which the rejected option can be used.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?
> Thanks,
> Martin
>
> gcc/ChangeLog:
>
> 2019-07-16 Martin Liska <mliska@suse.cz>
>
> 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.
>
> gcc/testsuite/ChangeLog:
>
> 2019-07-16 Martin Liska <mliska@suse.cz>
>
> PR driver/91172
> * gcc.dg/pr91172.c: New test.
> ---
> gcc/opts-common.c | 20 +++++++++++++++++++-
> gcc/opts-global.c | 6 +++++-
> gcc/testsuite/gcc.dg/pr91172.c | 3 +++
> 3 files changed, 27 insertions(+), 2 deletions(-)
> create mode 100644 gcc/testsuite/gcc.dg/pr91172.c
Nice catch!
@@ -745,6 +746,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 languages. */
Typo: "for a language" (singular).
+ else
+ /* Happens for -Werror=warning_name. */
+ warning (0, "command-line error argument %qs is not valid for %s",
+ text, bad_lang);
It might be better phrased as something like
"%<-Werror=%> argument %qs is not valid for %s"
The argument is not one of a "command-line error." It's one
to the -Werror option (which can be specified in other places
besides the command line).
Martin
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Make a warning for -Werror=wrong-language (PR driver/91172).
2019-07-16 16:40 ` Martin Sebor
@ 2019-07-17 7:55 ` Martin Liška
2019-07-21 20:41 ` Jeff Law
0 siblings, 1 reply; 4+ messages in thread
From: Martin Liška @ 2019-07-17 7:55 UTC (permalink / raw)
To: Martin Sebor, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 2690 bytes --]
On 7/16/19 6:40 PM, Martin Sebor wrote:
> On 7/16/19 5:16 AM, Martin Liška wrote:
>> Hi.
>>
>> I noticed in the PR that -Werror=argument argument is not verified
>> that the option is supported by a language we compile for.
>> That's changed in the patch. However, it's not ideal as I need to mark
>> the -Werror as the problematic option and one can't print a proper
>> list of valid languages for which the rejected option can be used.
>>
>> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>>
>> Ready to be installed?
>> Thanks,
>> Martin
>>
>> gcc/ChangeLog:
>>
>> 2019-07-16 Martin Liska <mliska@suse.cz>
>>
>> Â Â Â Â 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.
>>
>> gcc/testsuite/ChangeLog:
>>
>> 2019-07-16 Martin Liska <mliska@suse.cz>
>>
>> Â Â Â Â PR driver/91172
>> Â Â Â Â * gcc.dg/pr91172.c: New test.
>> ---
>>  gcc/opts-common.c             | 20 +++++++++++++++++++-
>>  gcc/opts-global.c             | 6 +++++-
>> Â gcc/testsuite/gcc.dg/pr91172.c |Â 3 +++
>> Â 3 files changed, 27 insertions(+), 2 deletions(-)
>> Â create mode 100644 gcc/testsuite/gcc.dg/pr91172.c
>
> Nice catch!
Yep, I came to the quite accidentally.
>
> @@ -745,6 +746,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 languages. */
>
> Typo: "for a language" (singular).
Fixed.
>
> +Â else
> +   /* Happens for -Werror=warning_name. */
> +Â Â Â warning (0, "command-line error argument %qs is not valid for %s",
> +Â Â Â Â Â Â Â Â text, bad_lang);
>
> It might be better phrased as something like
>
> Â "%<-Werror=%> argument %qs is not valid for %s"
>
> The argument is not one of a "command-line error."Â It's one
> to the -Werror option (which can be specified in other places
> besides the command line).
I like language corrections from native speakers.
I'm sending updated version of the patch.
Thanks,
Martin
>
> Martin
[-- Attachment #2: 0001-Make-a-warning-for-Werror-wrong-language-PR-driver-9.patch --]
[-- Type: text/x-patch, Size: 3298 bytes --]
From 03baf640c12ea6dfda2215ae07d288b292179217 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Tue, 16 Jul 2019 11:11:00 +0200
Subject: [PATCH] Make a warning for -Werror=wrong-language (PR driver/91172).
gcc/ChangeLog:
2019-07-16 Martin Liska <mliska@suse.cz>
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.
gcc/testsuite/ChangeLog:
2019-07-16 Martin Liska <mliska@suse.cz>
PR driver/91172
* gcc.dg/pr91172.c: New test.
---
gcc/opts-common.c | 20 +++++++++++++++++++-
gcc/opts-global.c | 6 +++++-
gcc/testsuite/gcc.dg/pr91172.c | 3 +++
3 files changed, 27 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/pr91172.c
diff --git a/gcc/opts-common.c b/gcc/opts-common.c
index 660dfe63858..e3f9c549b10 100644
--- a/gcc/opts-common.c
+++ b/gcc/opts-common.c
@@ -537,7 +537,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))
@@ -745,6 +746,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 bf4db775928..7c5bd16c7ea 100644
--- a/gcc/opts-global.c
+++ b/gcc/opts-global.c
@@ -103,10 +103,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/gcc.dg/pr91172.c b/gcc/testsuite/gcc.dg/pr91172.c
new file mode 100644
index 00000000000..a38a0580f4a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr91172.c
@@ -0,0 +1,3 @@
+/* { dg-do compile } */
+/* { dg-options "-Werror=target-lifetime" } */
+/* { dg-warning "'-Werror\=' argument '-Werror=target-lifetime' is not valid for C" "" { target *-*-* } 0 } */
--
2.22.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Make a warning for -Werror=wrong-language (PR driver/91172).
2019-07-17 7:55 ` Martin Liška
@ 2019-07-21 20:41 ` Jeff Law
0 siblings, 0 replies; 4+ messages in thread
From: Jeff Law @ 2019-07-21 20:41 UTC (permalink / raw)
To: Martin Liška, Martin Sebor, gcc-patches
On 7/17/19 1:40 AM, Martin Liška wrote:
> On 7/16/19 6:40 PM, Martin Sebor wrote:
>> On 7/16/19 5:16 AM, Martin Liška wrote:
>>> Hi.
>>>
>>> I noticed in the PR that -Werror=argument argument is not verified
>>> that the option is supported by a language we compile for.
>>> That's changed in the patch. However, it's not ideal as I need to mark
>>> the -Werror as the problematic option and one can't print a proper
>>> list of valid languages for which the rejected option can be used.
>>>
>>> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>>>
>>> Ready to be installed?
>>> Thanks,
>>> Martin
>>>
>>> gcc/ChangeLog:
>>>
>>> 2019-07-16 Martin Liska <mliska@suse.cz>
>>>
>>> Â Â Â Â 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.
>>>
>>> gcc/testsuite/ChangeLog:
>>>
>>> 2019-07-16 Martin Liska <mliska@suse.cz>
>>>
>>> Â Â Â Â PR driver/91172
>>> Â Â Â Â * gcc.dg/pr91172.c: New test.
>>> ---
>>>  gcc/opts-common.c             | 20 +++++++++++++++++++-
>>>  gcc/opts-global.c             | 6 +++++-
>>> Â gcc/testsuite/gcc.dg/pr91172.c |Â 3 +++
>>> Â 3 files changed, 27 insertions(+), 2 deletions(-)
>>> Â create mode 100644 gcc/testsuite/gcc.dg/pr91172.c
>> Nice catch!
> Yep, I came to the quite accidentally.
>
>> @@ -745,6 +746,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 languages. */
>>
>> Typo: "for a language" (singular).
> Fixed.
>
>> +Â else
>> +   /* Happens for -Werror=warning_name. */
>> +Â Â Â warning (0, "command-line error argument %qs is not valid for %s",
>> +Â Â Â Â Â Â Â Â text, bad_lang);
>>
>> It might be better phrased as something like
>>
>> Â "%<-Werror=%> argument %qs is not valid for %s"
>>
>> The argument is not one of a "command-line error."Â It's one
>> to the -Werror option (which can be specified in other places
>> besides the command line).
> I like language corrections from native speakers.
>
> I'm sending updated version of the patch.
> Thanks,
> Martin
>
>> Martin
>
>
> 0001-Make-a-warning-for-Werror-wrong-language-PR-driver-9.patch
>
> From 03baf640c12ea6dfda2215ae07d288b292179217 Mon Sep 17 00:00:00 2001
> From: Martin Liska <mliska@suse.cz>
> Date: Tue, 16 Jul 2019 11:11:00 +0200
> Subject: [PATCH] Make a warning for -Werror=wrong-language (PR driver/91172).
>
> gcc/ChangeLog:
>
> 2019-07-16 Martin Liska <mliska@suse.cz>
>
> 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.
>
> gcc/testsuite/ChangeLog:
>
> 2019-07-16 Martin Liska <mliska@suse.cz>
>
> PR driver/91172
> * gcc.dg/pr91172.c: New test.
OK
jeff
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-07-21 20:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-16 11:18 [PATCH] Make a warning for -Werror=wrong-language (PR driver/91172) Martin Liška
2019-07-16 16:40 ` Martin Sebor
2019-07-17 7:55 ` Martin Liška
2019-07-21 20:41 ` Jeff Law
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).