From e91b804e3fd98a1103f10a0fff4460095db161ec Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Tue, 10 Jan 2023 19:24:09 +0100 Subject: synth: check rem/mod by 0 --- src/synth/synth-vhdl_eval.adb | 16 ++++++++++++++-- 1 file 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; -- cgit v1.2.3