aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/synth/synth-vhdl_eval.adb16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/synth/synth-vhdl_eval.adb b/src/synth/synth-vhdl_eval.adb
index ca5f9169c..78003539e 100644
--- a/src/synth/synth-vhdl_eval.adb
+++ b/src/synth/synth-vhdl_eval.adb
@@ -1135,16 +1135,28 @@ package body Synth.Vhdl_Eval is
when Iir_Predefined_Integer_Mod =>
declare
Res : Int64;
+ Div : Int64;
begin
- Res := Read_Discrete (Param1) mod Read_Discrete (Param2);
+ Div := Read_Discrete (Param2);
+ if Div = 0 then
+ Error_Msg_Synth (Inst, Expr, "division by zero");
+ return Null_Memtyp;
+ end if;
+ Res := Read_Discrete (Param1) mod Div;
Check_Integer_Overflow (Inst, Res, Res_Typ, Expr);
return Create_Memory_Discrete (Res, Res_Typ);
end;
when Iir_Predefined_Integer_Rem =>
declare
Res : Int64;
+ Div : Int64;
begin
- Res := Read_Discrete (Param1) rem Read_Discrete (Param2);
+ Div := Read_Discrete (Param2);
+ if Div = 0 then
+ Error_Msg_Synth (Inst, Expr, "division by zero");
+ return Null_Memtyp;
+ end if;
+ Res := Read_Discrete (Param1) rem Div;
Check_Integer_Overflow (Inst, Res, Res_Typ, Expr);
return Create_Memory_Discrete (Res, Res_Typ);
end;