aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2016-10-13 05:01:48 +0200
committerTristan Gingold <tgingold@free.fr>2016-10-13 05:01:48 +0200
commite247deb3b2c78050702f96a98bd1c4f755334447 (patch)
tree0b25effd72ad4d49e2b6c902d995d1095c4e878a
parenta83288e572ef07e1bfb8c478c8798d87726b89b8 (diff)
downloadghdl-e247deb3b2c78050702f96a98bd1c4f755334447.tar.gz
ghdl-e247deb3b2c78050702f96a98bd1c4f755334447.tar.bz2
ghdl-e247deb3b2c78050702f96a98bd1c4f755334447.zip
eval_type_conversion: free unused intermediate result in case of overflow.
-rw-r--r--src/vhdl/evaluation.adb26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/vhdl/evaluation.adb b/src/vhdl/evaluation.adb
index 7a664ca5a..69d0a6dc8 100644
--- a/src/vhdl/evaluation.adb
+++ b/src/vhdl/evaluation.adb
@@ -1919,51 +1919,53 @@ package body Evaluation is
end if;
end Eval_Array_Type_Conversion;
- function Eval_Type_Conversion (Expr : Iir) return Iir
+ function Eval_Type_Conversion (Conv : Iir) return Iir
is
+ Expr : constant Iir := Get_Expression (Conv);
Val : Iir;
Val_Type : Iir;
Conv_Type : Iir;
Res : Iir;
begin
- Val := Eval_Static_Expr (Get_Expression (Expr));
+ Val := Eval_Static_Expr (Expr);
Val_Type := Get_Base_Type (Get_Type (Val));
- Conv_Type := Get_Base_Type (Get_Type (Expr));
+ Conv_Type := Get_Base_Type (Get_Type (Conv));
if Conv_Type = Val_Type then
- Res := Build_Constant (Val, Expr);
+ Res := Build_Constant (Val, Conv);
else
case Get_Kind (Conv_Type) is
when Iir_Kind_Integer_Type_Definition =>
case Get_Kind (Val_Type) is
when Iir_Kind_Integer_Type_Definition =>
- Res := Build_Integer (Get_Value (Val), Expr);
+ Res := Build_Integer (Get_Value (Val), Conv);
when Iir_Kind_Floating_Type_Definition =>
Res := Build_Integer
- (Iir_Int64 (Get_Fp_Value (Val)), Expr);
+ (Iir_Int64 (Get_Fp_Value (Val)), Conv);
when others =>
Error_Kind ("eval_type_conversion(1)", Val_Type);
end case;
when Iir_Kind_Floating_Type_Definition =>
case Get_Kind (Val_Type) is
when Iir_Kind_Integer_Type_Definition =>
- Res := Build_Floating (Iir_Fp64 (Get_Value (Val)), Expr);
+ Res := Build_Floating (Iir_Fp64 (Get_Value (Val)), Conv);
when Iir_Kind_Floating_Type_Definition =>
- Res := Build_Floating (Get_Fp_Value (Val), Expr);
+ Res := Build_Floating (Get_Fp_Value (Val), Conv);
when others =>
Error_Kind ("eval_type_conversion(2)", Val_Type);
end case;
when Iir_Kind_Array_Type_Definition =>
-- Not a scalar, do not check bounds.
- return Eval_Array_Type_Conversion (Expr, Val);
+ return Eval_Array_Type_Conversion (Conv, Val);
when others =>
Error_Kind ("eval_type_conversion(3)", Conv_Type);
end case;
end if;
- if not Eval_Is_In_Bound (Res, Get_Type (Expr)) then
+ if not Eval_Is_In_Bound (Res, Get_Type (Conv)) then
if Get_Kind (Res) /= Iir_Kind_Overflow_Literal then
- Warning_Msg_Sem (Warnid_Runtime_Error, +Expr,
+ Warning_Msg_Sem (Warnid_Runtime_Error, +Conv,
"result of conversion out of bounds");
- Res := Build_Overflow (Expr);
+ Free_Eval_Static_Expr (Res, Conv);
+ Res := Build_Overflow (Conv);
end if;
end if;
return Res;