From f96e48995e95d3f13c841a9c0970e747aa3352c7 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 18 Feb 2023 21:48:45 +0000 Subject: [PATCH] Ignore interpreter iteration limit when initialising a package --- src/jit/jit-interp.c | 15 +++++++++-- test/regress/link4.vhd | 55 +++++++++++++++++++++++++++++++++++++++ test/regress/testlist.txt | 1 + 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 test/regress/link4.vhd diff --git a/src/jit/jit-interp.c b/src/jit/jit-interp.c index a4cbcfd3..99a942d4 100644 --- a/src/jit/jit-interp.c +++ b/src/jit/jit-interp.c @@ -554,8 +554,19 @@ static void interp_branch_to(jit_interp_t *state, jit_value_t label) const int target = interp_get_value(state, label).integer; if (state->backedge > 0 && target < state->pc) { // Limit the number of loop iterations in bounded mode - if (--(state->backedge) == 0) - jit_msg(NULL, DIAG_FATAL, "maximum iteration limit reached"); + if (--(state->backedge) == 0) { + bool safe_to_abort = true; + for (jit_anchor_t *a = state->anchor; a; a = a->caller) { + if (a->func->privdata != MPTR_INVALID) { + // We might be in the middle of initialising a package so + // cannot abandon execution here + safe_to_abort = false; + } + } + + if (safe_to_abort) + jit_msg(NULL, DIAG_FATAL, "maximum iteration limit reached"); + } } state->pc = target; diff --git a/test/regress/link4.vhd b/test/regress/link4.vhd new file mode 100644 index 00000000..1013b536 --- /dev/null +++ b/test/regress/link4.vhd @@ -0,0 +1,55 @@ +package pack is + + type int_vec is array (natural range <>) of integer; + + type rec is record + data : int_vec(1 to 100); + end record; + + impure function make_rec return rec; + + constant r : rec := make_rec; + constant s : string := "hello"; + + function get_string return string; + +end package; + +package body pack is + + impure function make_rec return rec is + variable r : rec; + begin + for i in 1 to 100 loop + for j in 1 to 100 loop + r.data(j) := r.data(j) + 1; + end loop; + end loop; + return r; + end function; + + function get_string return string is + begin + return s; + end function; + +end package body; + +------------------------------------------------------------------------------- + +entity link4 is +end entity; + +use work.pack.all; + +architecture test of link4 is +begin + + p1: process is + begin + assert get_string = s; -- OK + assert get_string = s; -- OK (failed spuriously) + wait; + end process; + +end architecture; diff --git a/test/regress/testlist.txt b/test/regress/testlist.txt index 0d798e74..fbe256dd 100644 --- a/test/regress/testlist.txt +++ b/test/regress/testlist.txt @@ -714,3 +714,4 @@ issue603 normal issue609 normal issue618 normal,gA='1',gB='0' issue615 normal,gold,2008 +link4 normal -- 2.39.2