diff options
author | Tristan Gingold <tgingold@free.fr> | 2021-02-11 20:48:17 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2021-02-11 20:48:17 +0100 |
commit | 0badf589e0b937c49eff2ac9374fc97ee47a0dbb (patch) | |
tree | 48ce6d796ea1b07db9c9be78617af2e29dc4c92c /src/vhdl | |
parent | bb7b9bd01bc0ec05da45d96de04a2feba2c6a58f (diff) | |
download | ghdl-0badf589e0b937c49eff2ac9374fc97ee47a0dbb.tar.gz ghdl-0badf589e0b937c49eff2ac9374fc97ee47a0dbb.tar.bz2 ghdl-0badf589e0b937c49eff2ac9374fc97ee47a0dbb.zip |
vhdl-evaluation.adb: use is_overflow_literal.
Avoid crash in Eval_Discrete_Range_Length on overflow.
Diffstat (limited to 'src/vhdl')
-rw-r--r-- | src/vhdl/translate/trans-chap3.adb | 3 | ||||
-rw-r--r-- | src/vhdl/vhdl-evaluation.adb | 31 |
2 files changed, 21 insertions, 13 deletions
diff --git a/src/vhdl/translate/trans-chap3.adb b/src/vhdl/translate/trans-chap3.adb index 7e7cefb24..f1928ae2e 100644 --- a/src/vhdl/translate/trans-chap3.adb +++ b/src/vhdl/translate/trans-chap3.adb @@ -1047,6 +1047,9 @@ package body Trans.Chap3 is return -1; end if; Idx_Len := Eval_Discrete_Type_Length (Index); + if Idx_Len < 0 then + return -1; + end if; -- Do not consider very large arrays as static, to avoid overflow at -- compile time. diff --git a/src/vhdl/vhdl-evaluation.adb b/src/vhdl/vhdl-evaluation.adb index 41d18a07c..6a714a330 100644 --- a/src/vhdl/vhdl-evaluation.adb +++ b/src/vhdl/vhdl-evaluation.adb @@ -42,11 +42,6 @@ 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); @@ -622,7 +617,7 @@ package body Vhdl.Evaluation is Func : Iir_Predefined_Functions; begin - if Is_Overflow (Operand) then + if Is_Overflow_Literal (Operand) then -- Propagate overflow. return Build_Overflow (Orig); end if; @@ -1080,7 +1075,7 @@ package body Vhdl.Evaluation is El := Get_Right (Op); end if; Ops_Val (I) := Eval_Static_Expr (El); - if Is_Overflow (Ops_Val (I)) then + if Is_Overflow_Literal (Ops_Val (I)) then Err_Orig := El; else case Iir_Predefined_Concat_Functions (Def) is @@ -1103,7 +1098,7 @@ package body Vhdl.Evaluation is Left_Op := Get_Left (Op); end if; Left_Val := Eval_Static_Expr (Left_Op); - if Is_Overflow (Left_Val) then + if Is_Overflow_Literal (Left_Val) then Err_Orig := Left_Op; else Left_Def := Def; @@ -1575,7 +1570,7 @@ package body Vhdl.Evaluation is Func : constant Iir_Predefined_Functions := Get_Implicit_Definition (Imp); begin - if Is_Overflow (Left) or else Is_Overflow (Right) then + if Is_Overflow_Literal (Left) or else Is_Overflow_Literal (Right) then return Build_Overflow (Orig); end if; @@ -2546,7 +2541,7 @@ package body Vhdl.Evaluation is begin Prefix := Get_Prefix (Expr); Prefix := Eval_Static_Expr (Prefix); - if Is_Overflow (Prefix) then + if Is_Overflow_Literal (Prefix) then return Build_Overflow (Expr, Get_Type (Expr)); end if; @@ -3703,7 +3698,9 @@ package body Vhdl.Evaluation is 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 + if Is_Overflow_Literal (L_Expr) + or else Is_Overflow_Literal (R_Expr) + then return False; end if; -- Check for null range. @@ -3765,11 +3762,19 @@ package body Vhdl.Evaluation is is -- We don't want to deal with very large ranges here. pragma Suppress (Overflow_Check); + Left_Expr : constant Iir := Get_Left_Limit (Constraint); + Right_Expr : constant Iir := Get_Right_Limit (Constraint); Res : Int64; Left, Right : Int64; begin - Left := Eval_Pos (Get_Left_Limit (Constraint)); - Right := Eval_Pos (Get_Right_Limit (Constraint)); + if Is_Overflow_Literal (Left_Expr) + or else Is_Overflow_Literal (Right_Expr) + then + return -1; + end if; + + Left := Eval_Pos (Left_Expr); + Right := Eval_Pos (Right_Expr); case Get_Direction (Constraint) is when Dir_To => if Right < Left then |