* [PATCH] Fix crash with --help=^ (PR driver/71063)
@ 2016-05-11 20:40 Marek Polacek
2016-05-11 20:51 ` Jakub Jelinek
0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2016-05-11 20:40 UTC (permalink / raw)
To: GCC Patches
We crashed when given --help=^ and Kyrill explained why in the PR
(<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71063#c2>). The following
seems as good a fix as any, I think.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2016-05-11 Marek Polacek <polacek@redhat.com>
PR driver/71063
* opts.c (common_handle_option): Detect missing argument for --help^.
* gcc.dg/opts-7.c: New test.
diff --git gcc/opts.c gcc/opts.c
index 0f9431a..71e0779 100644
--- gcc/opts.c
+++ gcc/opts.c
@@ -1640,6 +1640,11 @@ common_handle_option (struct gcc_options *opts,
if (* a == '^')
{
++ a;
+ if (*a == '\0')
+ {
+ error_at (loc, "missing argument to %qs", "--help=^");
+ break;
+ }
pflags = & exclude_flags;
}
else
diff --git gcc/testsuite/gcc.dg/opts-7.c gcc/testsuite/gcc.dg/opts-7.c
index e69de29..c54d0b8 100644
--- gcc/testsuite/gcc.dg/opts-7.c
+++ gcc/testsuite/gcc.dg/opts-7.c
@@ -0,0 +1,6 @@
+/* PR driver/71063 */
+/* Test we don't ICE. */
+/* { dg-do compile } */
+/* { dg-options "--help=^" } */
+
+/* { dg-error "missing argument to" "" { target *-*-* } 0 } */
Marek
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix crash with --help=^ (PR driver/71063)
2016-05-11 20:40 [PATCH] Fix crash with --help=^ (PR driver/71063) Marek Polacek
@ 2016-05-11 20:51 ` Jakub Jelinek
2016-05-12 10:36 ` Marek Polacek
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2016-05-11 20:51 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches
On Wed, May 11, 2016 at 10:40:36PM +0200, Marek Polacek wrote:
> We crashed when given --help=^ and Kyrill explained why in the PR
> (<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71063#c2>). The following
> seems as good a fix as any, I think.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2016-05-11 Marek Polacek <polacek@redhat.com>
>
> PR driver/71063
> * opts.c (common_handle_option): Detect missing argument for --help^.
>
> * gcc.dg/opts-7.c: New test.
Ok. But while touching this, can you fix the formatting around too?
space between * and a, or ++ a, or & exclude_flags?
>
> diff --git gcc/opts.c gcc/opts.c
> index 0f9431a..71e0779 100644
> --- gcc/opts.c
> +++ gcc/opts.c
> @@ -1640,6 +1640,11 @@ common_handle_option (struct gcc_options *opts,
> if (* a == '^')
> {
> ++ a;
> + if (*a == '\0')
> + {
> + error_at (loc, "missing argument to %qs", "--help=^");
> + break;
> + }
> pflags = & exclude_flags;
> }
> else
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix crash with --help=^ (PR driver/71063)
2016-05-11 20:51 ` Jakub Jelinek
@ 2016-05-12 10:36 ` Marek Polacek
2016-05-12 10:48 ` Jakub Jelinek
0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2016-05-12 10:36 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: GCC Patches
On Wed, May 11, 2016 at 10:50:55PM +0200, Jakub Jelinek wrote:
> On Wed, May 11, 2016 at 10:40:36PM +0200, Marek Polacek wrote:
> > We crashed when given --help=^ and Kyrill explained why in the PR
> > (<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71063#c2>). The following
> > seems as good a fix as any, I think.
> >
> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> >
> > 2016-05-11 Marek Polacek <polacek@redhat.com>
> >
> > PR driver/71063
> > * opts.c (common_handle_option): Detect missing argument for --help^.
> >
> > * gcc.dg/opts-7.c: New test.
>
> Ok. But while touching this, can you fix the formatting around too?
> space between * and a, or ++ a, or & exclude_flags?
Happy to. I've fixed the whole OPT__help_ case:
Bootstrapped/regtested on x86_64-linux, applying to trunk.
2016-05-12 Marek Polacek <polacek@redhat.com>
PR driver/71063
* opts.c (common_handle_option): Detect missing argument for --help^.
* gcc.dg/opts-7.c: New test.
diff --git gcc/opts.c gcc/opts.c
index 0f9431a..63d41ca 100644
--- gcc/opts.c
+++ gcc/opts.c
@@ -1595,7 +1595,7 @@ common_handle_option (struct gcc_options *opts,
case OPT__help_:
{
- const char * a = arg;
+ const char *a = arg;
unsigned int include_flags = 0;
/* Note - by default we include undocumented options when listing
specific classes. If you only want to see documented options
@@ -1612,11 +1612,11 @@ common_handle_option (struct gcc_options *opts,
arg = [^]{word}[,{arg}]
word = {optimizers|target|warnings|undocumented|
params|common|<language>} */
- while (* a != 0)
+ while (*a != 0)
{
static const struct
{
- const char * string;
+ const char *string;
unsigned int flag;
}
specifics[] =
@@ -1631,19 +1631,24 @@ common_handle_option (struct gcc_options *opts,
{ "common", CL_COMMON },
{ NULL, 0 }
};
- unsigned int * pflags;
- const char * comma;
+ unsigned int *pflags;
+ const char *comma;
unsigned int lang_flag, specific_flag;
unsigned int len;
unsigned int i;
- if (* a == '^')
+ if (*a == '^')
{
- ++ a;
- pflags = & exclude_flags;
+ ++a;
+ if (*a == '\0')
+ {
+ error_at (loc, "missing argument to %qs", "--help=^");
+ break;
+ }
+ pflags = &exclude_flags;
}
else
- pflags = & include_flags;
+ pflags = &include_flags;
comma = strchr (a, ',');
if (comma == NULL)
@@ -1680,7 +1685,7 @@ common_handle_option (struct gcc_options *opts,
if (specific_flag != 0)
{
if (lang_flag == 0)
- * pflags |= specific_flag;
+ *pflags |= specific_flag;
else
{
/* The option's argument matches both the start of a
@@ -1689,7 +1694,7 @@ common_handle_option (struct gcc_options *opts,
specified "--help=c", but otherwise we have to issue
a warning. */
if (strncasecmp (a, "c", len) == 0)
- * pflags |= lang_flag;
+ *pflags |= lang_flag;
else
warning_at (loc, 0,
"--help argument %q.*s is ambiguous, "
@@ -1698,7 +1703,7 @@ common_handle_option (struct gcc_options *opts,
}
}
else if (lang_flag != 0)
- * pflags |= lang_flag;
+ *pflags |= lang_flag;
else
warning_at (loc, 0,
"unrecognized argument to --help= option: %q.*s",
diff --git gcc/testsuite/gcc.dg/opts-7.c gcc/testsuite/gcc.dg/opts-7.c
index e69de29..c54d0b8 100644
--- gcc/testsuite/gcc.dg/opts-7.c
+++ gcc/testsuite/gcc.dg/opts-7.c
@@ -0,0 +1,6 @@
+/* PR driver/71063 */
+/* Test we don't ICE. */
+/* { dg-do compile } */
+/* { dg-options "--help=^" } */
+
+/* { dg-error "missing argument to" "" { target *-*-* } 0 } */
Marek
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix crash with --help=^ (PR driver/71063)
2016-05-12 10:36 ` Marek Polacek
@ 2016-05-12 10:48 ` Jakub Jelinek
0 siblings, 0 replies; 4+ messages in thread
From: Jakub Jelinek @ 2016-05-12 10:48 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches
On Thu, May 12, 2016 at 12:35:58PM +0200, Marek Polacek wrote:
> 2016-05-12 Marek Polacek <polacek@redhat.com>
>
> PR driver/71063
> * opts.c (common_handle_option): Detect missing argument for --help^.
>
> * gcc.dg/opts-7.c: New test.
Thanks.
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-05-12 10:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-11 20:40 [PATCH] Fix crash with --help=^ (PR driver/71063) Marek Polacek
2016-05-11 20:51 ` Jakub Jelinek
2016-05-12 10:36 ` Marek Polacek
2016-05-12 10:48 ` Jakub Jelinek
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).