re PR driver/71063 (ICE: Segmentation fault with --help="^")
authorMarek Polacek <polacek@redhat.com>
Thu, 12 May 2016 10:59:11 +0000 (10:59 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Thu, 12 May 2016 10:59:11 +0000 (10:59 +0000)
PR driver/71063
* opts.c (common_handle_option): Detect missing argument for --help^.

* gcc.dg/opts-7.c: New test.

From-SVN: r236170

gcc/ChangeLog
gcc/opts.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/opts-7.c [new file with mode: 0644]

index 23a486928f41725d847dc36d801941278e0c2f30..711d8d590929ca17b11ae2f99b36c8b537f429dc 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-12  Marek Polacek  <polacek@redhat.com>
+
+       PR driver/71063
+       * opts.c (common_handle_option): Detect missing argument for --help^.
+
 2016-05-12  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        PR target/70830
index 0f9431a0b3231e57605a1af44774bc1e6980bfc3..63d41ca9deb5da2a0f9402a176669f9c8aead289 100644 (file)
@@ -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",
index 41e5d51d8a972d180eff68f8273b8bfb7dd7fcc7..c1b2323e07caa89500c63947187e0823701e34ef 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-12  Marek Polacek  <polacek@redhat.com>
+
+       PR driver/71063
+       * gcc.dg/opts-7.c: New test.
+
 2016-05-12  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        PR target/70830
diff --git a/gcc/testsuite/gcc.dg/opts-7.c b/gcc/testsuite/gcc.dg/opts-7.c
new file mode 100644 (file)
index 0000000..c54d0b8
--- /dev/null
@@ -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 } */