From d986b9af22f4e927e887f1bd6f9ff5174dde4aca Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Mon, 12 Jun 2017 05:37:49 +0200 Subject: Fix crash of implicit conversion in instantiation. Fix #301 --- src/vhdl/translate/trans-chap5.adb | 16 ++++++++++++++-- src/vhdl/translate/trans.adb | 5 +++++ src/vhdl/translate/trans.ads | 3 +++ 3 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/vhdl/translate/trans-chap5.adb b/src/vhdl/translate/trans-chap5.adb index f4efc4103..dbccd5ac4 100644 --- a/src/vhdl/translate/trans-chap5.adb +++ b/src/vhdl/translate/trans-chap5.adb @@ -36,12 +36,23 @@ package body Trans.Chap5 is Scope => Scope_Ptr.all); end Save_Map_Env; - procedure Set_Map_Env (Env : Map_Env) + procedure Restore_Map_Env (Env : Map_Env) is -- Avoid potential compiler bug with discriminant check. pragma Suppress (Discriminant_Check); begin Env.Scope_Ptr.all := Env.Scope; + end Restore_Map_Env; + + procedure Set_Map_Env (Env : Map_Env) is + begin + -- In some cases, the previous environment is still needed (for example + -- an implicit array conversion accesses to both the formal and the + -- actual type). Set ENV only if it is not null, in order not to erase + -- the previous env. + if not Is_Null (Env.Scope) then + Restore_Map_Env (Env); + end if; end Set_Map_Env; procedure Translate_Attribute_Specification @@ -742,7 +753,7 @@ package body Trans.Chap5 is end; Next_Association_Interface (Assoc, Inter); end loop; - Set_Map_Env (Actual_Env); + Restore_Map_Env (Actual_Env); end Elab_Port_Map_Aspect; procedure Elab_Generic_Map_Aspect @@ -855,6 +866,7 @@ package body Trans.Chap5 is Close_Temp; Next_Association_Interface (Assoc, Inter); end loop; + Restore_Map_Env (Actual_Env); end Elab_Generic_Map_Aspect; procedure Elab_Map_Aspect diff --git a/src/vhdl/translate/trans.adb b/src/vhdl/translate/trans.adb index 1f9d177a4..6c8bc048e 100644 --- a/src/vhdl/translate/trans.adb +++ b/src/vhdl/translate/trans.adb @@ -432,6 +432,11 @@ package body Trans is Scope := (Scope_Type => Scope.Scope_Type, Kind => Var_Scope_None); end Clear_Scope; + function Is_Null (Scope : Var_Scope_Type) return Boolean is + begin + return Scope.Kind = Var_Scope_None; + end Is_Null; + function Create_Global_Var (Name : O_Ident; Vtype : O_Tnode; Storage : O_Storage) return Var_Type diff --git a/src/vhdl/translate/trans.ads b/src/vhdl/translate/trans.ads index adc4a4712..cc74d46b5 100644 --- a/src/vhdl/translate/trans.ads +++ b/src/vhdl/translate/trans.ads @@ -324,6 +324,9 @@ package Trans is -- before being set. procedure Clear_Scope (Scope : in out Var_Scope_Type); + -- True if SCOPE is a null-scope (eg. was cleared). + function Is_Null (Scope : Var_Scope_Type) return Boolean; + -- Reset the identifier. type Id_Mark_Type is limited private; type Local_Identifier_Type is private; -- cgit v1.2.3