From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id EC5333858288; Fri, 2 Dec 2022 16:10:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC5333858288 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669997448; bh=aScPekKE+xUj+pfBbIixIvyNs3Pb6Zd1BCsb4f3FbU4=; h=From:To:Subject:Date:From; b=WEHmZKpfITuqVmOuq3vw4xK5pBluHcaVt7C2Vqf2RZ6mlnZY728+/0AHvBhB5TdQb PCh/XNHkj8Y6Ty+/JRjNz3ucNhAtVQg9FSoykRR/djvQ4bOquboA2VTociQTouyWgO SKtIMrPe8C1ofG/bXSe8ortpJYsZnIUnIGY9ng0k= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4467] driver: fix validate_switches logic X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/master X-Git-Oldrev: 70596a0fb2a2ec072e1e97e37616e05041dfa4e5 X-Git-Newrev: 6d3c634c8baebd9ff12c39d61947752486758bd3 Message-Id: <20221202161048.EC5333858288@sourceware.org> Date: Fri, 2 Dec 2022 16:10:48 +0000 (GMT) List-Id: https://gcc.gnu.org/g:6d3c634c8baebd9ff12c39d61947752486758bd3 commit r13-4467-g6d3c634c8baebd9ff12c39d61947752486758bd3 Author: Jason Merrill Date: Sun Nov 27 14:30:14 2022 -0500 driver: fix validate_switches logic 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++. Diff: --- gcc/cp/g++spec.cc | 4 +++- gcc/gcc.cc | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/gcc/cp/g++spec.cc b/gcc/cp/g++spec.cc index e599ac906f6..3d3b042dd56 100644 --- a/gcc/cp/g++spec.cc +++ b/gcc/cp/g++spec.cc @@ -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; 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 == '!')