diff options
author | Tristan Gingold <tgingold@free.fr> | 2023-04-30 10:07:57 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2023-04-30 10:07:57 +0200 |
commit | 672c0b03504280056274b2a37e79bdd7aaf40144 (patch) | |
tree | 0dba54449f3639b40dce90b6624d3e3825a69265 /src/vhdl | |
parent | 9da0c085ef11c4096599202f911510600cb69dbe (diff) | |
download | ghdl-672c0b03504280056274b2a37e79bdd7aaf40144.tar.gz ghdl-672c0b03504280056274b2a37e79bdd7aaf40144.tar.bz2 ghdl-672c0b03504280056274b2a37e79bdd7aaf40144.zip |
translate: adjust bounds handling in procedure calls.
Part of #2417
Diffstat (limited to 'src/vhdl')
-rw-r--r-- | src/vhdl/translate/trans-chap7.adb | 3 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap7.ads | 7 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap8.adb | 57 |
3 files changed, 45 insertions, 22 deletions
diff --git a/src/vhdl/translate/trans-chap7.adb b/src/vhdl/translate/trans-chap7.adb index 1fe302fe4..25d458752 100644 --- a/src/vhdl/translate/trans-chap7.adb +++ b/src/vhdl/translate/trans-chap7.adb @@ -1304,8 +1304,7 @@ package body Trans.Chap7 is Expr_Type : Iir; Atype : Iir; Is_Sig : Object_Kind_Type; - Loc : Iir) - return O_Enode is + Loc : Iir) return O_Enode is begin -- Same type: nothing to do. if Atype = Expr_Type then diff --git a/src/vhdl/translate/trans-chap7.ads b/src/vhdl/translate/trans-chap7.ads index f361eb87f..defb61f21 100644 --- a/src/vhdl/translate/trans-chap7.ads +++ b/src/vhdl/translate/trans-chap7.ads @@ -75,8 +75,11 @@ package Trans.Chap7 is Expr_Type : Iir; Atype : Iir; Is_Sig : Object_Kind_Type; - Loc : Iir) - return O_Enode; + Loc : Iir) return O_Enode; + + -- Return true iff ATYPE is derived from PARENT_TYPE + -- (or to say the same, if PARENT_TYPE is a parent of ATYPE). + function Is_A_Derived_Type (Atype : Iir; Parent_Type : Iir) return Boolean; function Translate_Type_Conversion (Expr : O_Enode; Expr_Type : Iir; Res_Type : Iir; Loc : Iir) diff --git a/src/vhdl/translate/trans-chap8.adb b/src/vhdl/translate/trans-chap8.adb index da2658ac0..6cf88f793 100644 --- a/src/vhdl/translate/trans-chap8.adb +++ b/src/vhdl/translate/trans-chap8.adb @@ -2472,31 +2472,52 @@ package body Trans.Chap8 is Kind : Iir_Kind; begin if Is_Fully_Constrained_Type (Ftype) then + -- No bounds as the parameter is not a fat pointer. return False; end if; - if Act_Type /= Null_Iir - and then Get_Type_Staticness (Act_Type) = Locally - then - return False; - end if; - if Actual /= Null_Iir then - if Get_Expr_Staticness (Actual) = Locally then - return False; + if Act_Type /= Null_Iir then + if not Chap7.Is_A_Derived_Type (Act_Type, Ftype) then + -- But if an implicit subtype conversion is needed, + -- the bounds need to be saved. + return True; end if; - Kind := Get_Kind (Actual); - if (Kind = Iir_Kind_Function_Call - or else Kind in Iir_Kinds_Dyadic_Operator - or else Kind in Iir_Kinds_Monadic_Operator) - and then Is_Fully_Constrained_Type (Get_Type (Actual)) - then + if Get_Type_Staticness (Act_Type) = Locally then + -- Actual bounds are statically built. return False; end if; - if Is_Object_Name (Actual) - and then Kind /= Iir_Kind_Slice_Name - then - return False; + end if; + + if Actual = Null_Iir then + -- No actual, and default value is not locally static. + return True; + end if; + + if Get_Expr_Staticness (Actual) = Locally then + -- Actual is static (so are its bounds). + return False; + end if; + + Kind := Get_Kind (Actual); + if (Kind = Iir_Kind_Function_Call + or else Kind in Iir_Kinds_Dyadic_Operator + or else Kind in Iir_Kinds_Monadic_Operator) + and then Is_Fully_Constrained_Type (Get_Type (Actual)) + then + -- Actual is the result of an unconstrained function call. + -- The result bounds are already allocated on stack2. + return False; + end if; + + if Is_Object_Name (Actual) then + -- The life of an object name is longer than the life + -- of a call. + if Kind = Iir_Kind_Slice_Name then + -- Unless the name is a slice! + return True; end if; + return False; end if; + return True; end Need_Bounds_Field; |