Spivoxity / obc-3

Oxford Oberon-2 compiler
38 stars 7 forks source link

Large global array of pointers #14

Closed Spivoxity closed 5 years ago

Spivoxity commented 5 years ago

The compiler crashes with a stack overflow when trying to declare a large global array of pointers.

MODULE tExp;

CONST MAXWORD = 500000;

TYPE
  Exp = POINTER TO ExpTree;
  ExpTree = RECORD value : INTEGER END;

VAR exp: ARRAY MAXWORD OF Exp;

END tExp.
Spivoxity commented 5 years ago

The problem lies in bit_item(gcmap.ml), where the compiler tries to reduce an immense range to a bitmap. It's going to fail, but if the array is large enough, just computing the range will lead to a stack overflow.

Workaround -- allocate the array dynamically:

MODULE tExp;

CONST MAXWORD = 500000;

TYPE
  Exp = POINTER TO ExpTree;
  ExpTree = RECORD value : INTEGER END;

VAR exp: POINTER TO ARRAY OF Exp;

BEGIN
  NEW(exp, MAXWORD)
END tExp.
Spivoxity commented 5 years ago

Fixed in 3.0.4