From 0e74112cf494c93f170739b87ecc89b2d5d97f92 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Sun, 27 Nov 2022 14:30:14 -0500 Subject: [PATCH] driver: fix validate_switches logic To: gcc-patches@gcc.gnu.org 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 reject -nostdlib++. gcc/ChangeLog: * gcc.cc (validate_switches): Reset suffix/starred on loop. --- gcc/gcc.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gcc/gcc.cc b/gcc/gcc.cc index ca1c9e27a94..2278e2b6bb1 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -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 == '!') -- 2.31.1