diff options
author | Tristan Gingold <tgingold@free.fr> | 2021-02-10 19:02:12 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2021-02-10 19:02:12 +0100 |
commit | 899eab63569411158d295fe9719ede038493ca34 (patch) | |
tree | 5f69c2dec4cb37373196a38ff7f4b72fd30b00fa /src/vhdl | |
parent | 27835ccebbd3248dac7ed683ff242fe2a3f62af8 (diff) | |
download | ghdl-899eab63569411158d295fe9719ede038493ca34.tar.gz ghdl-899eab63569411158d295fe9719ede038493ca34.tar.bz2 ghdl-899eab63569411158d295fe9719ede038493ca34.zip |
vhdl-sem_stmts: avoid overflow. Fix #1639
Diffstat (limited to 'src/vhdl')
-rw-r--r-- | src/vhdl/vhdl-sem_stmts.adb | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/vhdl/vhdl-sem_stmts.adb b/src/vhdl/vhdl-sem_stmts.adb index 70b302689..c7f734404 100644 --- a/src/vhdl/vhdl-sem_stmts.adb +++ b/src/vhdl/vhdl-sem_stmts.adb @@ -512,6 +512,7 @@ package body Vhdl.Sem_Stmts is Expr: Iir; We: Iir_Waveform_Element; Time, Last_Time : Int64; + Last_Unit, Unit : Iir; begin if Get_Kind (Waveform_Chain) = Iir_Kind_Unaffected_Waveform then -- Unaffected. @@ -520,6 +521,8 @@ package body Vhdl.Sem_Stmts is -- Start with -1 to allow after 0 ns. Last_Time := -1; + Last_Unit := Null_Iir; + We := Waveform_Chain; while We /= Null_Iir loop Expr := Get_We_Value (We); @@ -574,15 +577,22 @@ package body Vhdl.Sem_Stmts is Expr := Eval_Expr (Expr); Set_Time (We, Expr); Time := Get_Value (Expr); + Unit := Null_Iir; else -- The expression is a physical literal (common case). - -- Extract its value. - Time := Get_Physical_Value (Expr); + -- Do not try to extract the physical value to avoid + -- overflow, but check the integer value and compare + -- if the unit is the same (common case). + Time := Get_Value (Expr); + Unit := Get_Named_Entity (Get_Unit_Name (Expr)); + if Last_Unit = Null_Iir then + Last_Unit := Unit; + end if; end if; if Time < 0 then Error_Msg_Sem (+Expr, "waveform time expression must be >= 0"); - elsif Time <= Last_Time then + elsif Unit = Last_Unit and then Time <= Last_Time then Error_Msg_Sem (+Expr, "time must be greater than previous transaction"); |