diff options
author | Tristan Gingold <tgingold@free.fr> | 2023-01-10 19:24:09 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2023-01-10 21:47:00 +0100 |
commit | e91b804e3fd98a1103f10a0fff4460095db161ec (patch) | |
tree | faad7a05217bb73101ce6f322be5633adf028c22 /src | |
parent | 308f761d76becbb71ac4d71ddcc992b809cafd83 (diff) | |
download | ghdl-e91b804e3fd98a1103f10a0fff4460095db161ec.tar.gz ghdl-e91b804e3fd98a1103f10a0fff4460095db161ec.tar.bz2 ghdl-e91b804e3fd98a1103f10a0fff4460095db161ec.zip |
synth: check rem/mod by 0
Diffstat (limited to 'src')
-rw-r--r-- | src/synth/synth-vhdl_eval.adb | 16 |
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; |