Skip to content

Commit

Permalink
Limit maximum size of stack allocations to 64kB
Browse files Browse the repository at this point in the history
Fixes #791
  • Loading branch information
nickg committed Nov 8, 2023
1 parent 35c87ad commit 3a3e45e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/jit/jit-irgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
typedef struct _irgen_label irgen_label_t;
typedef struct _patch_list patch_list_t;

#define PATCH_CHUNK_SZ 4
#define PATCH_CHUNK_SZ 4
#define MAX_STACK_ALLOC 65536

struct _patch_list {
patch_list_t *next;
Expand Down Expand Up @@ -3891,7 +3892,7 @@ static void irgen_locals(jit_irgen_t *g)
for (int i = 0; i < nvars; i++) {
vcode_type_t vtype = vcode_var_type(i);
const int sz = irgen_size_bytes(vtype);
if (vcode_var_flags(i) & VAR_HEAP)
if ((vcode_var_flags(i) & VAR_HEAP) || sz > MAX_STACK_ALLOC)
g->vars[i] = macro_lalloc(g, jit_value_from_int64(sz));
else
g->vars[i] = macro_salloc(g, sz);
Expand Down
25 changes: 25 additions & 0 deletions test/regress/issue791.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
entity issue791 is
end entity;

architecture beh of issue791 is

type t_slv_array is array (natural range <>) of bit_vector;

procedure read_mem is
-- This shouldn't be allocated on the stack
variable v_memory : t_slv_array(0 to (8 * 131072)-1)(7 downto 0) := (others => x"FF");
begin
wait for 1 ns;
v_memory(v_memory'right) := X"ab";
wait for 1 ns;
assert v_memory(v_memory'right) = X"ab";
end procedure;

begin

p_proc : process
begin
read_mem;
wait;
end process;
end architecture;
1 change: 1 addition & 0 deletions test/regress/testlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -898,3 +898,4 @@ cover20 cover,shell
issue787 normal
view6 normal,2019
issue790 normal
issue791 normal,2008

0 comments on commit 3a3e45e

Please sign in to comment.