driver: fix validate_switches logic
authorJason Merrill <jason@redhat.com>
Sun, 27 Nov 2022 19:30:14 +0000 (14:30 -0500)
committerJason Merrill <jason@redhat.com>
Fri, 2 Dec 2022 15:38:32 +0000 (10:38 -0500)
Under the old logic for validate_switches, once suffix or starred got set,
they stayed set for all later switches found in the spec.  So for e.g.

%{g*:%{%:debug-level-gt(0):

Once we see g*, starred is set.  Then we see %:, and it sees that as a
zero-length switch, which because starred is still set, matches any and all
command-line options.  So targets that use such a spec accept all options in
the driver, while ones that don't reject some, such as the recent
-nostdlib++.

This patch fixes the inconsistency, so all targets would complain about
-nostdlib++, and then sets SKIPOPT for it so they don't.

gcc/ChangeLog:

* gcc.cc (validate_switches): Reset suffix/starred on loop.

gcc/cp/ChangeLog:

* g++spec.cc (lang_specific_driver): Set SKIPOPT for nostdlib++.

gcc/cp/g++spec.cc
gcc/gcc.cc

index e599ac9..3d3b042 100644 (file)
@@ -167,8 +167,10 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
          need_experimental = true;
          break;
 
-       case OPT_nostdlib:
        case OPT_nostdlib__:
+         args[i] |= SKIPOPT;
+         /* FALLTHRU */
+       case OPT_nostdlib:
        case OPT_nodefaultlibs:
          library = -1;
          break;
index ca1c9e2..2278e2b 100644 (file)
@@ -9299,12 +9299,15 @@ validate_switches (const char *start, bool user_spec, bool braced)
   const char *atom;
   size_t len;
   int i;
-  bool suffix = false;
-  bool starred = false;
+  bool suffix;
+  bool starred;
 
 #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0)
 
 next_member:
+  suffix = false;
+  starred = false;
+
   SKIP_WHITE ();
 
   if (*p == '!')