aboutsummaryrefslogtreecommitdiffstats
path: root/src/synth
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2023-01-10 21:54:42 +0100
committerTristan Gingold <tgingold@free.fr>2023-01-10 21:54:42 +0100
commit944405539cc4b79476b6ccf1a5726fb4505306b2 (patch)
tree900856ab94aa24a893a1d6080121f3da5ae70b9a /src/synth
parentd321ec7a8a3aae1463cf22d68d13ac9a1c951caf (diff)
downloadghdl-944405539cc4b79476b6ccf1a5726fb4505306b2.tar.gz
ghdl-944405539cc4b79476b6ccf1a5726fb4505306b2.tar.bz2
ghdl-944405539cc4b79476b6ccf1a5726fb4505306b2.zip
synth: fix memory allocation in predefined function calls
Diffstat (limited to 'src/synth')
-rw-r--r--src/synth/synth-vhdl_eval.adb2
-rw-r--r--src/synth/synth-vhdl_oper.adb3
-rw-r--r--src/synth/synth-vhdl_stmts.adb4
3 files changed, 8 insertions, 1 deletions
diff --git a/src/synth/synth-vhdl_eval.adb b/src/synth/synth-vhdl_eval.adb
index 78003539e..ddc9e7052 100644
--- a/src/synth/synth-vhdl_eval.adb
+++ b/src/synth/synth-vhdl_eval.adb
@@ -86,6 +86,8 @@ package body Synth.Vhdl_Eval is
return Prev;
end if;
+ -- TODO: should be directly allocated on the expr_pool to avoid
+ -- a copy.
return Create_Vec_Type_By_Length (Prev.W, Prev.Arr_El);
end Create_Res_Bound;
diff --git a/src/synth/synth-vhdl_oper.adb b/src/synth/synth-vhdl_oper.adb
index 22ef709aa..9063e84c4 100644
--- a/src/synth/synth-vhdl_oper.adb
+++ b/src/synth/synth-vhdl_oper.adb
@@ -2255,8 +2255,11 @@ package body Synth.Vhdl_Oper is
Mt := Eval_Static_Predefined_Function_Call
(Syn_Inst, Param1, Param2, Res_Typ, Expr);
+
if Mt /= Null_Memtyp then
Res := Create_Value_Memtyp (Mt);
+ -- Protect deallocation.
+ Res.Typ := Unshare_Type_Expr (Res.Typ, Res_Typ);
else
Res := No_Valtyp;
end if;
diff --git a/src/synth/synth-vhdl_stmts.adb b/src/synth/synth-vhdl_stmts.adb
index 1f2d308a4..6a9d0a348 100644
--- a/src/synth/synth-vhdl_stmts.adb
+++ b/src/synth/synth-vhdl_stmts.adb
@@ -2690,8 +2690,10 @@ package body Synth.Vhdl_Stmts is
Free_Instance (Sub_Inst);
if Res /= No_Valtyp then
- -- Protect return value from being deallocated
+ -- Protect return value from being deallocated.
+ -- The result can be a local variable.
Res := Unshare (Res, Expr_Pool'Access);
+ -- The type can have been created in the function.
Ret_Typ := Get_Subtype_Object (Syn_Inst, Get_Type (Imp));
Res.Typ := Unshare_Type_Expr (Res.Typ, Ret_Typ);
end if;