diff options
author | Tristan Gingold <tgingold@free.fr> | 2021-02-11 07:42:27 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2021-02-11 18:55:29 +0100 |
commit | 8e832e1b538f60f4bec8d67e59699a8a9c439b04 (patch) | |
tree | 6e1923a523c20e5ce2db724750d514798813dd4a /src | |
parent | 28f1d0a0517b74b6950403dc3394f2f712f5366c (diff) | |
download | ghdl-8e832e1b538f60f4bec8d67e59699a8a9c439b04.tar.gz ghdl-8e832e1b538f60f4bec8d67e59699a8a9c439b04.tar.bz2 ghdl-8e832e1b538f60f4bec8d67e59699a8a9c439b04.zip |
eval_is_range_in_bound: avoid crash in case of overflow. Fix #1640
Diffstat (limited to 'src')
-rw-r--r-- | src/vhdl/vhdl-evaluation.adb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/vhdl/vhdl-evaluation.adb b/src/vhdl/vhdl-evaluation.adb index cd597462c..c3067487e 100644 --- a/src/vhdl/vhdl-evaluation.adb +++ b/src/vhdl/vhdl-evaluation.adb @@ -42,6 +42,11 @@ package body Vhdl.Evaluation is function Eval_Scalar_Compare (Left, Right : Iir) return Compare_Type; + function Is_Overflow (Expr : Iir) return Boolean is + begin + return Get_Kind (Expr) = Iir_Kind_Overflow_Literal; + end Is_Overflow; + function Get_Physical_Value (Expr : Iir) return Int64 is pragma Unsuppress (Overflow_Check); @@ -3696,11 +3701,16 @@ package body Vhdl.Evaluation is | Iir_Kind_Enumeration_Subtype_Definition | Iir_Kind_Enumeration_Type_Definition => declare + L_Expr : constant Iir := Get_Left_Limit (Range_Constraint); + R_Expr : constant Iir := Get_Right_Limit (Range_Constraint); L, R : Int64; begin + if Is_Overflow (L_Expr) or else Is_Overflow (R_Expr) then + return False; + end if; -- Check for null range. - L := Eval_Pos (Get_Left_Limit (Range_Constraint)); - R := Eval_Pos (Get_Right_Limit (Range_Constraint)); + L := Eval_Pos (L_Expr); + R := Eval_Pos (R_Expr); case Get_Direction (Range_Constraint) is when Dir_To => if L > R then |