From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7871) id 1D7973858006; Fri, 4 Nov 2022 13:55:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D7973858006 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667570119; bh=7rrvvOxeOXcstZPapoXzlHBmsLhWERhJr4kMIDYpJoE=; h=From:To:Subject:Date:From; b=apNVgPcFRAEKMwUKAgOdN3dZ6OJgY/+20WARmIhMiYqgRP9ZwR+DKjZ5cgawsLhvX Acg/pb8e08TDy7/wOJGGvusnHGlFDSLIlQ2CHjyfTVGNRkQnoAeDDULdR8JubqWKwR cWr8+Cwkr0KxGZ7PQ/xAsES3WbSWKQ1qbEjKfDoY= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marc Poulhi?s To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3678] ada: Cleanup code for warnings about unset references X-Act-Checkin: gcc X-Git-Author: Piotr Trojanek X-Git-Refname: refs/heads/master X-Git-Oldrev: 7e1fe87899932e2c265fd0a13b2ac552b0865e0f X-Git-Newrev: 72baa4e2b7f8dfdb2c49950e12a397ef00d3bc16 Message-Id: <20221104135519.1D7973858006@sourceware.org> Date: Fri, 4 Nov 2022 13:55:19 +0000 (GMT) List-Id: https://gcc.gnu.org/g:72baa4e2b7f8dfdb2c49950e12a397ef00d3bc16 commit r13-3678-g72baa4e2b7f8dfdb2c49950e12a397ef00d3bc16 Author: Piotr Trojanek Date: Tue Aug 23 12:57:35 2022 +0200 ada: Cleanup code for warnings about unset references 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. Diff: --- 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 --