From patchwork Fri Nov 4 13:58:31 2022 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: 15562 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp427263wru; Fri, 4 Nov 2022 07:12:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM59g3Fg0OHhMhvy7f6HRH0+CDWfklScY/NNT+TCuX/Qj2JgVAjgjsv0ovI+Upeha4meHWV6 X-Received: by 2002:a17:906:195b:b0:7ae:108:9729 with SMTP id b27-20020a170906195b00b007ae01089729mr14335551eje.604.1667571128941; Fri, 04 Nov 2022 07:12:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667571128; cv=none; d=google.com; s=arc-20160816; b=tZ1WTgIu+HJbkhybEJexhey90W7pCXrsqBV4v7U1gj54PuNdbuJ4sio4Mb4Djly5jO wXjTuEeXX3fUnH8EVXwrikX32Pi9pXiSFdnBsojUQqUEyAdu+s2mzlrkKdL/nCq+fkGe dz69cvGPFUkI/+0BwUn6yNK64zpIGAZ3WTh2h9Cbkw5NK+6IAsPTD9qFiMGM51EfdU5l AxHuHMz1WH1igkChS6JlwPDxOWLuOrgJr+BtcrtTW8onmgZI+HPhyV9NVNWZFol5jxnq ASIg139BnXFtJa3A96fD09OoMa8iWJD89XJYhEI1cQFTjjK333yw+QfvCRyb4d/Imzrr 522Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=tzCwUOLnWfNeQehZ89LYtE/42xVemBlURU9Jrfitx6o=; b=KqIPnWgyIooGPTZ2Ez7zmFxtRP8pFr1CEa2Qckjtte+q5dU666a30etancQRiQKCio Kaqm7MsmOdQEEWqd+5ZGj97qEtPqcqOGcUkEQ+MtVtDdjGsaTZBN7cEhGw9ehB/6iKM1 RUIl/24aBzH2nRCZO8BY3Xl0g6dN2+s8M1zIhJ/a+k1XmuycIZK3dSfkwoFU6B+LADVB ITknBJn0OqxDjurikQ4HRxCKpz768hcCQuiL69CflwPNLdpvVz3ZQFdoQg/kUPdie5Z8 GHxHRGsPQrKZCT+WhzdXeLiajciobAxqpv5R0fRktmBqU5slWOE6nu7Jt8y37pNViDb2 d4BQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="s328/cgp"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id dr22-20020a170907721600b0078d8bd255d4si5415048ejc.949.2022.11.04.07.12.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 07:12:08 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="s328/cgp"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 416DF3829BC2 for ; Fri, 4 Nov 2022 14:04:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 416DF3829BC2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667570684; bh=tzCwUOLnWfNeQehZ89LYtE/42xVemBlURU9Jrfitx6o=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=s328/cgppEnY/L7ZdyTPXISuudqlUW0S5wGg24oMu5B1gg6Q5jLUKtwcl8ofSsE/y 2WkbaadSxK2XjmjZxIjEl+ab8QWyjdpgjOoyv4eqFKPaO3uZ+nQzw7K6cgBozpqmoJ BSWyKF5vQT3dFl1kmP9TcbG1cbxx45jPJd+eUjIE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 1378E385141D for ; Fri, 4 Nov 2022 13:58:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1378E385141D Received: by mail-wr1-x435.google.com with SMTP id a14so7175541wru.5 for ; Fri, 04 Nov 2022 06:58:36 -0700 (PDT) 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=tzCwUOLnWfNeQehZ89LYtE/42xVemBlURU9Jrfitx6o=; b=hyM2I9TeBYDpEfZNOm4h5AN79Xgdt/Qa10pRILfMmc/yQrbpauzj30IlnycsHPngoH BE/2jEfYfAnYV3rAIdCnWBFa4Iy2IDrYqazfRMbx8f+9ViXO5DLF5/0RFslPaKlUGFYn 5rXp0HKSl78WQmjMVyUNqcoUUHP2tSiu4D5YRtmAQt+xrvEC9Mn/pNJIfUvutYQ8MUNe nZbrgnUNtjYLRWt8geXJmWv9UZDaBclz/HaBW6kBQy9ZEHc5tX7uxooFMv9o1CYu/8XR VC/4mK83bjpV4kRJ8kHkHKQmAikEBbg98mtWZpgDm5xeCjXHJTHY5RMoseRxxCoaCxrI BKdA== X-Gm-Message-State: ACrzQf22EWfYCY39BUia3PKVAWlbEteg3snlC1AuKP4TPlsFZUmu+mqE t7Uq3tq808N63u0CB4rdOIE+auQ37JmlPg== X-Received: by 2002:adf:e992:0:b0:236:70ad:3bd9 with SMTP id h18-20020adfe992000000b0023670ad3bd9mr22526494wrm.136.1667570315606; Fri, 04 Nov 2022 06:58:35 -0700 (PDT) Received: from localhost.localdomain (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id s16-20020a5d69d0000000b0022ca921dc67sm3391578wrw.88.2022.11.04.06.58.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 06:58:35 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [COMMITTED] ada: Cleanup code for warnings about unset references Date: Fri, 4 Nov 2022 14:58:31 +0100 Message-Id: <20221104135831.86995-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 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 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?= Cc: Piotr Trojanek 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?1748575064287184517?= X-GMAIL-MSGID: =?utf-8?q?1748575064287184517?= From: Piotr Trojanek Cleanup related to new checks for unset references. gcc/ada/ * sem_util.adb (In_Pragma_Expression): Add standard guard against searching too far. (In_Quantified_Expression): Likewise. * sem_warn.adb (May_Need_Initialized_Actual): Remove redundant parens. (Check_References): Remove guard that duplicates a condition from the enclosing if-statement; only assign E1T variable when necessary. (Within_Postcondition): Fix layout. (No_Warn_On_In_Out): Balance parens in comment. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_util.adb | 13 +++++++++++++ gcc/ada/sem_warn.adb | 18 ++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 80d07eb0023..5c495761df1 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -14794,8 +14794,15 @@ package body Sem_Util is loop if No (P) then return False; + + -- Prevent the search from going too far + + elsif Is_Body_Or_Package_Declaration (P) then + return False; + elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then return True; + else P := Parent (P); end if; @@ -14871,6 +14878,12 @@ package body Sem_Util is loop if No (P) then return False; + + -- Prevent the search from going too far + + elsif Is_Body_Or_Package_Declaration (P) then + return False; + elsif Nkind (P) = N_Quantified_Expression then return True; else diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb index 509efa50af3..423754f5df8 100644 --- a/gcc/ada/sem_warn.adb +++ b/gcc/ada/sem_warn.adb @@ -928,7 +928,7 @@ package body Sem_Warn is if not Is_Generic_Type (T) then null; - elsif (Nkind (Par)) = N_Private_Extension_Declaration then + elsif Nkind (Par) = N_Private_Extension_Declaration then -- We only indicate the first such variable in the generic. @@ -936,7 +936,7 @@ package body Sem_Warn is Set_Uninitialized_Variable (Par, Ent); end if; - elsif (Nkind (Par)) = N_Formal_Type_Declaration + elsif Nkind (Par) = N_Formal_Type_Declaration and then Nkind (Formal_Type_Definition (Par)) = N_Formal_Private_Type_Definition then @@ -1151,8 +1151,6 @@ package body Sem_Warn is E1 := First_Entity (E); while Present (E1) loop - E1T := Etype (E1); - -- We are only interested in source entities. We also don't issue -- warnings within instances, since the proper place for such -- warnings is on the template when it is compiled, and we don't @@ -1161,6 +1159,8 @@ package body Sem_Warn is if Comes_From_Source (E1) and then Instantiation_Location (Sloc (E1)) = No_Location then + E1T := Etype (E1); + -- We are interested in variables and out/in-out parameters, but -- we exclude protected types, too complicated to worry about. @@ -1648,11 +1648,6 @@ package body Sem_Warn is not Is_Package_Or_Generic_Package (Cunit_Entity (Current_Sem_Unit)))) - -- Exclude instantiations, since there is no reason why every - -- entity in an instantiation should be referenced. - - and then Instantiation_Location (Sloc (E1)) = No_Location - -- Exclude formal parameters from bodies if the corresponding -- spec entity has been referenced in the case where there is -- a separate spec. @@ -2001,8 +1996,7 @@ package body Sem_Warn is P := Parent (Nod); if Nkind (P) = N_Pragma - and then Pragma_Name (P) = - Name_Test_Case + and then Pragma_Name (P) = Name_Test_Case and then Nod = Test_Case_Arg (P, Name_Ensures) then return True; @@ -3028,7 +3022,7 @@ package body Sem_Warn is -- if we have seen the address of the subprogram being taken, or if the -- subprogram is used as a generic actual (in the latter cases the -- context may force use of IN OUT, even if the parameter is not - -- modified for this particular case. + -- modified for this particular case). ----------------------- -- No_Warn_On_In_Out --