diff options
author | Tristan Gingold <tgingold@free.fr> | 2022-12-26 17:33:14 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2022-12-26 17:33:39 +0100 |
commit | 07b6da32b4c47519cfe6f02146a3fc099fbcdcbe (patch) | |
tree | 93db82184b343ad2f6b52827fcdb0a7884fdfcdc /src | |
parent | 0784c5351937b948d914238f570305d34e35e9ae (diff) | |
download | ghdl-07b6da32b4c47519cfe6f02146a3fc099fbcdcbe.tar.gz ghdl-07b6da32b4c47519cfe6f02146a3fc099fbcdcbe.tar.bz2 ghdl-07b6da32b4c47519cfe6f02146a3fc099fbcdcbe.zip |
synth: check bounds for pos and val attributes
Diffstat (limited to 'src')
-rw-r--r-- | src/synth/synth-vhdl_expr.adb | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/synth/synth-vhdl_expr.adb b/src/synth/synth-vhdl_expr.adb index af66fb874..6e397aa1a 100644 --- a/src/synth/synth-vhdl_expr.adb +++ b/src/synth/synth-vhdl_expr.adb @@ -2317,6 +2317,7 @@ package body Synth.Vhdl_Expr is declare Param : constant Node := Get_Parameter (Expr); V : Valtyp; + Vi : Int64; Dtype : Type_Acc; begin Dtype := Get_Subtype_Object (Syn_Inst, Get_Type (Expr)); @@ -2324,10 +2325,16 @@ package body Synth.Vhdl_Expr is -- FIXME: to be generalized. Not always as simple as a -- subtype conversion. if Is_Static (V.Val) then - V := Create_Value_Discrete (Read_Discrete (V), Dtype); + Vi := Read_Discrete (V); + if not In_Range (Dtype.Drange, Vi) then + Error_Msg_Synth (Syn_Inst, Expr, "value out of range"); + return No_Valtyp; + end if; + return Create_Value_Discrete (Vi, Dtype); + else + return Synth_Subtype_Conversion + (Syn_Inst, V, Dtype, False, Expr); end if; - return Synth_Subtype_Conversion - (Syn_Inst, V, Dtype, False, Expr); end; when Iir_Kind_Low_Type_Attribute => return Synth_Low_High_Type_Attribute (Syn_Inst, Expr, Dir_To); |