From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wr1-x435.google.com with SMTP id a14so7175541wru.5 for ; Fri, 04 Nov 2022 06:58:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=tzCwUOLnWfNeQehZ89LYtE/42xVemBlURU9Jrfitx6o=; b=S5IJ+0wc1HWVRKnJbcCeLS7F0MHLs4/PGxvM73Kt2GZCnOeJN/RTBK2X4zgAvkIZmb JIqvolsjxhuYZE8jnTaGlqwyKarbwocM7mdl7DBrrN7U+9XnV+fBvLcKWR7uUwm8NfAv LvP9z2SYAwPEArjQpRzyOQDjK8zKJCnqQI0inePsa+nl7SAYrDXSvd15uWEVASdmt2XA TV7HiVnK+wJTjirNvqp8w16eF38hPKAR6mGeLjTuRAu0WGY44UqWuFSpqmlyxWTcGm5V 4UKQOwMqy/R5NCT8mD/555APxVvUTH3V3Hbi6nQFOCF+iG4nAGTTOCuB0F1issLN9vm8 Re0A== 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-Google-Smtp-Source: AMsMyM6zMoszE5YiLgntBOybfRODk/yWO4bRo8GThW8ND5DMbPqD3HyE91m35uKNxfvrFMmIWv4cuA== 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) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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 -- -- 2.34.1