From: Piotr Trojanek Date: Tue, 23 Aug 2022 10:57:35 +0000 (+0200) Subject: ada: Cleanup code for warnings about unset references X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=72baa4e2b7f8dfdb2c49950e12a397ef00d3bc16;p=platform%2Fupstream%2Fgcc.git 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 --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 80d07eb..5c49576 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 509efa5..423754f 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 --