diff options
author | Tristan Gingold <tgingold@free.fr> | 2020-04-17 19:12:11 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2020-04-17 19:12:11 +0200 |
commit | 05c699a9d0c93a7e9bd15d8ac207ec62626867ec (patch) | |
tree | dc1a4ca5d69cea9f14c9497ae0e6499777a911a3 /src | |
parent | c2bb3d90014046dad616ac051e4938d0337184e9 (diff) | |
download | ghdl-05c699a9d0c93a7e9bd15d8ac207ec62626867ec.tar.gz ghdl-05c699a9d0c93a7e9bd15d8ac207ec62626867ec.tar.bz2 ghdl-05c699a9d0c93a7e9bd15d8ac207ec62626867ec.zip |
vhdl-evaluation: static out of bounds values are now a warning. For #1237
Also adjust 'Image attribute evaluation and translate for thin arrays.
Diffstat (limited to 'src')
-rw-r--r-- | src/vhdl/translate/trans-chap6.adb | 18 | ||||
-rw-r--r-- | src/vhdl/vhdl-evaluation.adb | 9 |
2 files changed, 17 insertions, 10 deletions
diff --git a/src/vhdl/translate/trans-chap6.adb b/src/vhdl/translate/trans-chap6.adb index 69ee04145..433669663 100644 --- a/src/vhdl/translate/trans-chap6.adb +++ b/src/vhdl/translate/trans-chap6.adb @@ -299,10 +299,8 @@ package body Trans.Chap6 is -- Translate index EXPR in dimension DIM of thin array into an -- offset. -- This checks bounds. - function Translate_Thin_Index_Offset (Index_Type : Iir; - Dim : Natural; - Expr : Iir) - return O_Enode + function Translate_Thin_Index_Offset + (Index_Type : Iir; Dim : Natural; Expr : Iir) return O_Enode is Index_Range : constant Iir := Get_Range_Constraint (Index_Type); Obound : O_Cnode; @@ -312,17 +310,23 @@ package body Trans.Chap6 is Index_Base_Type : Iir; V : Int64; B : Int64; + Expr1 : Iir; begin B := Eval_Pos (Get_Left_Limit (Index_Range)); if Get_Expr_Staticness (Expr) = Locally then - V := Eval_Pos (Eval_Static_Expr (Expr)); + Expr1 := Eval_Static_Expr (Expr); + if not Eval_Is_In_Bound (Expr1, Index_Type) then + Gen_Bound_Error (Expr1); + return New_Lit (New_Index_Lit (0)); + end if; + + V := Eval_Pos (Expr1); if Get_Direction (Index_Range) = Iir_To then B := V - B; else B := B - V; end if; - return New_Lit - (New_Unsigned_Literal (Ghdl_Index_Type, Unsigned_64 (B))); + return New_Lit (New_Index_Lit (Unsigned_64 (B))); else Index_Base_Type := Get_Base_Type (Index_Type); Index := Chap7.Translate_Expression (Expr, Index_Base_Type); diff --git a/src/vhdl/vhdl-evaluation.adb b/src/vhdl/vhdl-evaluation.adb index b20c64b52..80dfd774d 100644 --- a/src/vhdl/vhdl-evaluation.adb +++ b/src/vhdl/vhdl-evaluation.adb @@ -2850,11 +2850,13 @@ package body Vhdl.Evaluation is begin Param := Get_Parameter (Expr); Param := Eval_Static_Expr (Param); - Eval_Check_Bound (Param, Get_Type (Get_Prefix (Expr))); Set_Parameter (Expr, Param); -- Special case for overflow. - if Get_Kind (Param) = Iir_Kind_Overflow_Literal then + if Get_Kind (Param) = Iir_Kind_Overflow_Literal + or else not Eval_Is_In_Bound (Param, + Get_Type (Get_Prefix (Expr))) + then return Build_Overflow (Expr); end if; @@ -3507,7 +3509,8 @@ package body Vhdl.Evaluation is end if; if not Eval_Is_In_Bound (Expr, Sub_Type) then - Error_Msg_Sem (+Expr, "static expression violates bounds"); + Warning_Msg_Sem (Warnid_Runtime_Error, +Expr, + "static expression violates bounds"); end if; end Eval_Check_Bound; |