diff options
author | Tristan Gingold <tgingold@free.fr> | 2022-06-01 07:55:52 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2022-06-01 07:55:52 +0200 |
commit | 1e5ada114810890ea80223ee07713876eecfa289 (patch) | |
tree | dd16d885d5cae1ad18f96419fe734284807aa807 | |
parent | 193c7bf67404219480d85ddd64773776aabc6310 (diff) | |
download | ghdl-1e5ada114810890ea80223ee07713876eecfa289.tar.gz ghdl-1e5ada114810890ea80223ee07713876eecfa289.tar.bz2 ghdl-1e5ada114810890ea80223ee07713876eecfa289.zip |
vhdl-evaluation.adb: avoid a crash on overflow. For #2070
-rw-r--r-- | src/vhdl/vhdl-evaluation.adb | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/vhdl/vhdl-evaluation.adb b/src/vhdl/vhdl-evaluation.adb index 9409266c1..b85342b8b 100644 --- a/src/vhdl/vhdl-evaluation.adb +++ b/src/vhdl/vhdl-evaluation.adb @@ -4061,23 +4061,24 @@ package body Vhdl.Evaluation is end if; end Eval_Expr_Check_If_Static; - function Eval_Int_In_Range (Val : Int64; Bound : Iir) return Boolean is + function Eval_Int_In_Range (Val : Int64; Bound : Iir) return Boolean + is + L, R : Iir; begin case Get_Kind (Bound) is when Iir_Kind_Range_Expression => + L := Get_Left_Limit (Bound); + R := Get_Right_Limit (Bound); + if Get_Kind (L) = Iir_Kind_Overflow_Literal + or else Get_Kind (R) = Iir_Kind_Overflow_Literal + then + return True; + end if; case Get_Direction (Bound) is when Dir_To => - if Val < Eval_Pos (Get_Left_Limit (Bound)) - or else Val > Eval_Pos (Get_Right_Limit (Bound)) - then - return False; - end if; + return Val >= Eval_Pos (L) and then Val <= Eval_Pos (R); when Dir_Downto => - if Val > Eval_Pos (Get_Left_Limit (Bound)) - or else Val < Eval_Pos (Get_Right_Limit (Bound)) - then - return False; - end if; + return Val <= Eval_Pos (L) and then Val >= Eval_Pos (R); end case; when others => Error_Kind ("eval_int_in_range", Bound); |