From: Arnaud Charlet Date: Tue, 23 Jun 2020 16:14:03 +0000 (-0400) Subject: [Ada] Wrong use of Scope_Depth_Value X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7e3f6147a7492b774194669f3f68b979fd847811;p=gcc.git [Ada] Wrong use of Scope_Depth_Value gcc/ada/ * einfo.ads, einfo.adb (Scope_Depth_Value, Set_Scope_Depth_Value): Add assertions on valid nodes and update documentation accordingly. (Write_Field22_Name): Sync with change in Scope_Depth_Value. * sem_ch8.adb (Find_Direct_Name): Fix call to Scope_Depth_Value. --- diff --git a/gcc/ada/einfo.adb b/gcc/ada/einfo.adb index bf839a5aac6..4e41a726fac 100644 --- a/gcc/ada/einfo.adb +++ b/gcc/ada/einfo.adb @@ -3311,6 +3311,13 @@ package body Einfo is function Scope_Depth_Value (Id : E) return U is begin + pragma Assert + (Ekind (Id) in + Concurrent_Kind | Entry_Kind | Generic_Unit_Kind | + E_Package | E_Package_Body | Subprogram_Kind | + E_Block | E_Subprogram_Body | + E_Private_Type .. E_Limited_Private_Subtype | + E_Void | E_Loop | E_Return_Statement); return Uint22 (Id); end Scope_Depth_Value; @@ -6582,7 +6589,13 @@ package body Einfo is procedure Set_Scope_Depth_Value (Id : E; V : U) is begin - pragma Assert (not Is_Record_Type (Id)); + pragma Assert + (Ekind (Id) in + Concurrent_Kind | Entry_Kind | Generic_Unit_Kind | + E_Package | E_Package_Body | Subprogram_Kind | + E_Block | E_Subprogram_Body | + E_Private_Type .. E_Limited_Private_Subtype | + E_Void | E_Loop | E_Return_Statement); Set_Uint22 (Id, V); end Set_Scope_Depth_Value; @@ -10873,21 +10886,18 @@ package body Einfo is when Formal_Kind => Write_Str ("Protected_Formal"); - when E_Block - | E_Entry - | E_Entry_Family - | E_Function - | E_Generic_Function - | E_Generic_Package - | E_Generic_Procedure - | E_Loop + when Concurrent_Kind + | Entry_Kind + | Generic_Unit_Kind | E_Package | E_Package_Body - | E_Procedure - | E_Protected_Type - | E_Return_Statement + | Subprogram_Kind + | E_Block | E_Subprogram_Body - | E_Task_Type + | E_Private_Type .. E_Limited_Private_Subtype + | E_Void + | E_Loop + | E_Return_Statement => Write_Str ("Scope_Depth_Value"); diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads index 7932c9270b4..765d0f40e4a 100644 --- a/gcc/ada/einfo.ads +++ b/gcc/ada/einfo.ads @@ -4280,14 +4280,16 @@ package Einfo is -- the Scope will be Standard. -- Scope_Depth (synthesized) --- Applies to program units, blocks, concurrent types and entries, and --- also to record types, i.e. to any entity that can appear on the scope --- stack. Yields the scope depth value, which for those entities other --- than records is simply the scope depth value, for record entities, it --- is the Scope_Depth of the record scope. +-- Applies to program units, blocks, loops, return statements, +-- concurrent types, private types and entries, and also to record types, +-- i.e. to any entity that can appear on the scope stack. Yields the +-- scope depth value, which for those entities other than records is +-- simply the scope depth value, for record entities, it is the +-- Scope_Depth of the record scope. -- Scope_Depth_Value (Uint22) --- Defined in program units, blocks, concurrent types, and entries. +-- Defined in program units, blocks, loops, return statements, +-- concurrent types, private types and entries. -- Indicates the number of scopes that statically enclose the declaration -- of the unit or type. Library units have a depth of zero. Note that -- record types can act as scopes but do NOT have this field set (see diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb index 3c10a9650c9..73f73c6864b 100644 --- a/gcc/ada/sem_ch8.adb +++ b/gcc/ada/sem_ch8.adb @@ -5752,7 +5752,7 @@ package body Sem_Ch8 is -- outside the instance. if From_Actual_Package (E) - and then Scope_Depth (E2) < Scope_Depth (Inst) + and then Scope_Depth (Scope (E2)) < Scope_Depth (Inst) then goto Found; else