From patchwork Thu Dec 1 16:50:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 28457 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp369036wrr; Thu, 1 Dec 2022 08:51:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf43tkadugIQx0/4QI0dEQRzY2xNkgf41dh+xcXN0XHayEslT2q85vHGIXrjgYe4Ux3vWp46 X-Received: by 2002:a17:906:3291:b0:7c0:bda4:2dab with SMTP id 17-20020a170906329100b007c0bda42dabmr239890ejw.521.1669913512307; Thu, 01 Dec 2022 08:51:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669913512; cv=none; d=google.com; s=arc-20160816; b=bJxYpYS7WBhbv5VaTYU6VzMosQsdMBw3NO0oHumxbrw8idFtMyeCe/b/R0x6Si7t9u 7EqicBLoznHL8eDEoJ2UqXAOyjMrFlAyzW84fUaraQcrnsc5KqytoH7aA0CZ1EUiKDxN IMGbOXufPt9qYdip90hyB727eTRZBACjSL9dVAOzyd1I2s3jovDhITikwFfwy2vqeSlk Yl++M/C1ifOVaPqsRgwS/MxRUrTCrpl25MWQm+y3wiHOGha2DV3WWy6z4Ksi4OK9/1jJ jNfNfsdINfv1/s0QYOYXD8rePQB7CLXgSqH5iXp+X6bxXatmiJ6KN9A9FGdBhwA/Ovc1 2BOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=zlkzWRZO2JkO762935fWqgFSeJ1CCbzh4rlQ48jAba4=; b=QqazPWEunKHyLSTg0hp3meD+47eWDZE06Sv8DLh1RE/Gf7sKnWi52I8HHZQ784v4ni aCTNIWU6OdzJOK/3fuZ5a3Sg/v94sog/PWkbbjTRo6FY443sHLklB06LvkNCEtSB9XQG FGkyN81b8pCZZ/CRNzr4LGRcFNZHmgY12MxDEvR3NVeyCAgIabwRIFpBC8ZSbwk8nG0G sliGmoHe0KnjIFlJ3XNJcUw16b+a5FLbb04D2rbfLGA+czS88cInfbNvBXnFAF2Cr5el c3F4PhjCQV2chn//0Rb3OezSlBtzYJo1xSp4OCe89GsPBPH1YIQSklImaxRU0Cp7JVcb cMkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dfYhOflT; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b14-20020a056402350e00b0046af2ddb0a6si4631714edd.94.2022.12.01.08.51.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 08:51:52 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dfYhOflT; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2414A3858421 for ; Thu, 1 Dec 2022 16:51:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2414A3858421 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669913511; bh=zlkzWRZO2JkO762935fWqgFSeJ1CCbzh4rlQ48jAba4=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=dfYhOflT02ep07la0swyylg8JTGDLJ116WJ9hpZrNY5Hr6pRZKoCkeaLPQCep06VS PvgqKeB3Rn6ly2vaBUH5ITSHVSXoGEUZIPVFPlRRCyJ8IEIeP3M7MMEa/VMK+/Y7Yw gX1C1bZ7ELvOsFo2dcu5LqRatKfuqZZnsmBC3yRg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 523F03858428 for ; Thu, 1 Dec 2022 16:50:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 523F03858428 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-172-1_TgnHxDOL2tw9aMCun39Q-1; Thu, 01 Dec 2022 11:50:56 -0500 X-MC-Unique: 1_TgnHxDOL2tw9aMCun39Q-1 Received: by mail-qv1-f69.google.com with SMTP id 71-20020a0c804d000000b004b2fb260447so6007595qva.10 for ; Thu, 01 Dec 2022 08:50:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zlkzWRZO2JkO762935fWqgFSeJ1CCbzh4rlQ48jAba4=; b=5FJVnzbBczle/35cJ5PRTDR9FGNnjLKhBo615zEHKyxVvWJenZi815iWixOdFJw5Z0 mh83+PpXiJt1F58sO4JQWvFElz1Wu3SQywk8SeO49MwfX7oHadAIk6DL6kTn3IHSnrsq kMttfObylRVwQdLEZAbdxRrc1lHPC/CkyhiCK6kevZuBkejiyYzoTAiIIqtnd2OpsjKV dLvTd5RDwPen/Fe272lCoTgZ5qKXbqkmu+EUZlUQqVVmnWaJDnO6T2g6SqpjTRRtY20l 57pKBbQcB2rUu2B8szeg5CvSTY8O8fT9ciCphCA8/aNMTyC8GTSliSf5iLD+Vv49G4sG e3bA== X-Gm-Message-State: ANoB5pk65oKi3myWUEj6VFhlRzehnv5rAKLnyLMld1p1k991PvBDcbpN 4CGMmdPz420Y9lFuglUNSXwqyqZ5YYOI/oLX6UvghWnFBUW5Qf1ViK93oLbxqVcbKPjc9S0hEQt VJBVNRKM3VqTNqqJ0XAi1HmZ/wx6kbwMpDmHor/uPR//r8bFfdBcYT+FK5K8Lg08KbA== X-Received: by 2002:a05:620a:1905:b0:6fa:6636:a7b0 with SMTP id bj5-20020a05620a190500b006fa6636a7b0mr42632524qkb.55.1669913455348; Thu, 01 Dec 2022 08:50:55 -0800 (PST) X-Received: by 2002:a05:620a:1905:b0:6fa:6636:a7b0 with SMTP id bj5-20020a05620a190500b006fa6636a7b0mr42632489qkb.55.1669913454871; Thu, 01 Dec 2022 08:50:54 -0800 (PST) Received: from jason.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id i6-20020a05620a404600b006fc9fe67e34sm3277049qko.81.2022.12.01.08.50.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 08:50:54 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: oliva@adacore.com Subject: [PATCH RFA] driver: fix validate_switches logic Date: Thu, 1 Dec 2022 11:50:51 -0500 Message-Id: <20221201165051.51853-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751031230740316272?= X-GMAIL-MSGID: =?utf-8?q?1751031230740316272?= Tested x86_64-pc-linux-gnu, OK for trunk? -- 8< -- 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 | 4 +++- gcc/gcc.cc | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) base-commit: 4304e09a1617bcf1c87f5bc96017ae5017379d75 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 == '!')