aboutsummaryrefslogtreecommitdiffstats
path: root/src/vhdl/translate/trans-chap6.adb
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2020-04-17 19:12:11 +0200
committerTristan Gingold <tgingold@free.fr>2020-04-17 19:12:11 +0200
commit05c699a9d0c93a7e9bd15d8ac207ec62626867ec (patch)
treedc1a4ca5d69cea9f14c9497ae0e6499777a911a3 /src/vhdl/translate/trans-chap6.adb
parentc2bb3d90014046dad616ac051e4938d0337184e9 (diff)
downloadghdl-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/vhdl/translate/trans-chap6.adb')
-rw-r--r--src/vhdl/translate/trans-chap6.adb18
1 files changed, 11 insertions, 7 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);