diff options
author | Tristan Gingold <tgingold@free.fr> | 2022-09-12 07:27:22 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2022-09-12 07:27:22 +0200 |
commit | c4c21c2d74f24fefa9f34747dc0e9c85ada603b4 (patch) | |
tree | 7a04b7111a3a0e96a23a8f9d312a4a8032bbb485 /src | |
parent | 551a1519162dbc68fd03f8d435381b0693e1aaa1 (diff) | |
download | ghdl-c4c21c2d74f24fefa9f34747dc0e9c85ada603b4.tar.gz ghdl-c4c21c2d74f24fefa9f34747dc0e9c85ada603b4.tar.bz2 ghdl-c4c21c2d74f24fefa9f34747dc0e9c85ada603b4.zip |
synth: add bounds check for float-integer type conversion
Diffstat (limited to 'src')
-rw-r--r-- | src/synth/synth-vhdl_expr.adb | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/synth/synth-vhdl_expr.adb b/src/synth/synth-vhdl_expr.adb index 981dd5098..a252390e2 100644 --- a/src/synth/synth-vhdl_expr.adb +++ b/src/synth/synth-vhdl_expr.adb @@ -1405,8 +1405,26 @@ package body Synth.Vhdl_Expr is -- Int to int. return Val; elsif Val.Typ.Kind = Type_Float then - return Create_Value_Discrete - (Int64 (Read_Fp64 (Val)), Conv_Typ); + pragma Assert (Is_Static (Val.Val)); + declare + V : constant Fp64 := Read_Fp64 (Val); + Err : Boolean; + begin + case Conv_Typ.Drange.Dir is + when Dir_To => + Err := V < Fp64 (Conv_Typ.Drange.Left) + or V > Fp64 (Conv_Typ.Drange.Right); + when Dir_Downto => + Err := V < Fp64 (Conv_Typ.Drange.Right) + or V > Fp64 (Conv_Typ.Drange.Left); + end case; + if Err then + Error_Msg_Synth (+Expr, "value out of range"); + Elab.Debugger.Debug_Error (Syn_Inst, Expr); + return No_Valtyp; + end if; + return Create_Value_Discrete (Int64 (V), Conv_Typ); + end; else Error_Msg_Synth (+Conv, "unhandled type conversion (to int)"); return No_Valtyp; @@ -2324,6 +2342,7 @@ package body Synth.Vhdl_Expr is return Synth_Psl_Onehot0(Syn_Inst, Expr); when Iir_Kind_Overflow_Literal => Error_Msg_Synth (+Expr, "out of bound expression"); + Elab.Debugger.Debug_Error (Syn_Inst, Expr); return No_Valtyp; when Iir_Kind_Event_Attribute => if Hook_Event_Attribute /= null then |