From patchwork Thu May 25 08:05:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 98840 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp194072vqr; Thu, 25 May 2023 01:09:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ79ZMGlIzgZGR5j8uY+gWMOz2NfCgVd0tujFBfm5bTX+3BRrjyy39Z4CrJYzsA6yBvzmPCk X-Received: by 2002:a17:906:6a14:b0:96f:d67b:8095 with SMTP id qw20-20020a1709066a1400b0096fd67b8095mr1011364ejc.1.1685002175899; Thu, 25 May 2023 01:09:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685002175; cv=none; d=google.com; s=arc-20160816; b=Q13Wr6PYruMjXfHhv5YMRaV9snoEDnd8RJ/XMjNd46vdrch+ouLvDbDwySHesEpM51 +KNOe/FpFBJqpot4QaBdjGGGeTvchtNrVqBoesQcVOA29yx0wfk3JDH5UF4xupmYptqQ V+R3pqU97q1F5Y5gK4xXuxjOIRSA4u2Rc4rbLfALbEF6R8H/RTOn5YKB3jI5Dos0JS6R Up4tpFJSYWj9qd93j7OpXZ4o9Nfa9fZe4SlIfKS9DeO/b8kOlFBVxziLItoaP5j+OXiJ RdOYw+0SqhMBxx79r4BxLa5zZcbX9pMHLKbbwi4u9GHeN1DhMQLWzOT6E08D+AsBlzMw LO3Q== 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=HoooE8l5hIqzx3KTc+Zlt5Z0z5Bz23kldarNyEOQJFI=; b=jnDk8Ai7xEh6z1bPO/wVlPbGdKbX7qmdYuXdTmfqUBoJU7CJoknJoxxA79hmwxo1kO 3czn+RCVSSM54LCacuXRVSq9Agq+USIrrzpc7GMqQH6aXKjBSqYrLDrBEBkufYPJebkr 8G2vPAFjpRS1HOsqBTUKyaMI+ZzhPcCdsqyXzU7ccvEmfEsn5vCoyoy/+KaQQOD1AJxb E9rTa+10lrNkHZVhYM3NU3BIctEmqKG+OmiMoP7pgP7OB0x68LgmvL5TLoKH2gVTMMvw DyKwVpT+mZb0sAx15j21ikk+iT45eseubH+9tqxiKYGmkEyhpsSy624OplWoblQznF17 Yjsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IV8t1leq; 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 u6-20020a170906408600b0096f60761e94si660212ejj.843.2023.05.25.01.09.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 01:09:35 -0700 (PDT) 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=IV8t1leq; 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 B1E923885505 for ; Thu, 25 May 2023 08:07:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B1E923885505 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685002060; bh=HoooE8l5hIqzx3KTc+Zlt5Z0z5Bz23kldarNyEOQJFI=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=IV8t1leqv8s7k/MdelNkGp2FM+gz4JedLF3zR6AAL2Tzg5GCmnlhWgE5vQA53+xq9 fQvZIN7x1NSPd5H4IgIuCbzEp3FMPBcW71O+YcerKnOpHSJ/o8+2GuXrQBnw6Zkp78 iYZLuniV2264mkNDyK+nANg85pS+xy7Rm+BhUYCo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 108C73857711 for ; Thu, 25 May 2023 08:05:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 108C73857711 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3f6042d605dso1920795e9.2 for ; Thu, 25 May 2023 01:05:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685001928; x=1687593928; 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=HoooE8l5hIqzx3KTc+Zlt5Z0z5Bz23kldarNyEOQJFI=; b=OX1l7kDsTbAg4QoH95oyHBk1VdZucyh/epJJNqXVMTioMhdEFxNopzn78DlT27KOcQ m6AtkieRjCeIDWM25LYBmxpHkvA1ec/uWJcBMS25PmejVuZ/TauHUlAym9PcGTVNk6rp CLI/IQN8XbWlsx5EpPO/eNuNdTNKWlr4my0LM81PdCCyfG1L69oI1j6ZodaYdQabDIfd kaK6pfD/Pe40rJcl/nH8e6UHuhJg+zN068lbbEqIZkHnoZxDDSEep/2cSLUAelvJYHE/ Hlq8C1JHeMienft9inf042TrZ4Gq2+bdlUQGzDKggYL07YtzcWgclty44KhLdbFfsvIx nTUg== X-Gm-Message-State: AC+VfDzNTeY/8LrQU1TR2PcISUyb4+a4yZOKFqj5/y/2EDej2B736vpU fMJBEU8pUbfc1a2vQ/LWlMyIjjQTEcZkIQhD3Nq9Uw== X-Received: by 2002:a05:600c:ad2:b0:3f6:11cd:f525 with SMTP id c18-20020a05600c0ad200b003f611cdf525mr1942663wmr.19.1685001927905; Thu, 25 May 2023 01:05:27 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id v7-20020a05600c214700b003f4f89bc48dsm4918071wml.15.2023.05.25.01.05.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 01:05:27 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED] ada: Tune warning about assignment just before a raise statement Date: Thu, 25 May 2023 10:05:26 +0200 Message-Id: <20230525080526.1955679-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= 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?1766852841647949486?= X-GMAIL-MSGID: =?utf-8?q?1766852841647949486?= From: Piotr Trojanek Tune warning about a possibly ineffective assignment to a formal parameter that happens just before a raise statement. The warning is now emitted for parameters of all by-copy types and not just of scalar types (this gives more warnings), but is suppressed for aliased parameters (this removes some spurious warnings). gcc/ada/ * sem_ch11.adb (Analyze_Raise_Expression): Tune warning condition. * libgnat/g-dirope.ads (Open): Remove a potentially inaccurate comment. * libgnat/g-dirope.adb (Open): Remove a potentially useless assignment; the Dir output parameter should be assigned a null value anyway by the preceding call to Free. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/libgnat/g-dirope.adb | 1 - gcc/ada/libgnat/g-dirope.ads | 3 +-- gcc/ada/sem_ch11.adb | 7 ++++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/gcc/ada/libgnat/g-dirope.adb b/gcc/ada/libgnat/g-dirope.adb index 127f6ba8e80..3cebc9fe4a7 100644 --- a/gcc/ada/libgnat/g-dirope.adb +++ b/gcc/ada/libgnat/g-dirope.adb @@ -636,7 +636,6 @@ package body GNAT.Directory_Operations is if not Is_Open (Dir) then Free (Dir); - Dir := Null_Dir; raise Directory_Error; end if; end Open; diff --git a/gcc/ada/libgnat/g-dirope.ads b/gcc/ada/libgnat/g-dirope.ads index a3a8e4635f0..cdb99ff3267 100644 --- a/gcc/ada/libgnat/g-dirope.ads +++ b/gcc/ada/libgnat/g-dirope.ads @@ -210,8 +210,7 @@ package GNAT.Directory_Operations is procedure Open (Dir : out Dir_Type; Dir_Name : Dir_Name_Str); -- Opens the directory named by Dir_Name and returns a Dir_Type value -- that refers to this directory, and is positioned at the first entry. - -- Raises Directory_Error if Dir_Name cannot be accessed. In that case - -- Dir will be set to Null_Dir. + -- Raises Directory_Error if Dir_Name cannot be accessed. procedure Close (Dir : in out Dir_Type); -- Closes the directory stream referred to by Dir. After calling Close diff --git a/gcc/ada/sem_ch11.adb b/gcc/ada/sem_ch11.adb index 5471111d682..73eca7a603e 100644 --- a/gcc/ada/sem_ch11.adb +++ b/gcc/ada/sem_ch11.adb @@ -543,11 +543,12 @@ package body Sem_Ch11 is if Present (P) and then Nkind (P) = N_Assignment_Statement then L := Name (P); - -- Give warning for assignment to scalar formal + -- Give warning for assignment to by-copy formal - if Is_Scalar_Type (Etype (L)) - and then Is_Entity_Name (L) + if Is_Entity_Name (L) and then Is_Formal (Entity (L)) + and then Is_By_Copy_Type (Etype (L)) + and then not Is_Aliased (Entity (L)) -- Do this only for parameters to the current subprogram. -- This avoids some false positives for the nested case.