From faef2db5bbe258f9ac4f9e357f8db878903ca528 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Tue, 21 Apr 2020 07:41:09 +0200 Subject: synth-stmts: add a limit to the number of iterations. Fix #1242 --- src/synth/synth-flags.ads | 3 +++ src/synth/synth-stmts.adb | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/synth/synth-flags.ads b/src/synth/synth-flags.ads index 4f9badd1d..3fc9303c5 100644 --- a/src/synth/synth-flags.ads +++ b/src/synth/synth-flags.ads @@ -57,4 +57,7 @@ package Synth.Flags is -- True to start debugger on error. Flag_Debug_Enable : Boolean := True; + + -- Maximum number of iterations for (while)/loop. 0 means unlimited. + Flag_Max_Loop : Natural := 1000; end Synth.Flags; diff --git a/src/synth/synth-stmts.adb b/src/synth/synth-stmts.adb index efece924c..61833ab58 100644 --- a/src/synth/synth-stmts.adb +++ b/src/synth/synth-stmts.adb @@ -2328,6 +2328,7 @@ package body Synth.Stmts is Cond : constant Node := Get_Condition (Stmt); Val : Valtyp; Lc : aliased Loop_Context (Mode_Dynamic); + Iter_Nbr : Natural; begin Lc := (Mode => Mode_Dynamic, Prev_Loop => C.Cur_Loop, @@ -2339,6 +2340,8 @@ package body Synth.Stmts is Wire_Mark => No_Wire_Id); C.Cur_Loop := Lc'Unrestricted_Access; + Iter_Nbr := 0; + Loop_Control_Init (C, Stmt); loop @@ -2371,6 +2374,14 @@ package body Synth.Stmts is then exit; end if; + + Iter_Nbr := Iter_Nbr + 1; + if Iter_Nbr > Flags.Flag_Max_Loop and Flags.Flag_Max_Loop /= 0 then + Error_Msg_Synth + (+Stmt, "maximum number of iterations (%v) reached", + +Uns32 (Flags.Flag_Max_Loop)); + exit; + end if; end loop; Loop_Control_Finish (C); -- cgit v1.2.3