From 8e832e1b538f60f4bec8d67e59699a8a9c439b04 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Thu, 11 Feb 2021 07:42:27 +0100 Subject: eval_is_range_in_bound: avoid crash in case of overflow. Fix #1640 --- src/vhdl/vhdl-evaluation.adb | 14 ++++++++++++-- 1 file 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 -- cgit v1.2.3