Waldek Hebisch wrote:
Frank Heckenbach wrote:
Waldek Hebisch wrote:
It looks that you are passing large arrays by value. Such arrays may cause problems at runtime due to limit on stack usage (by default 10Mb on Linux) -- arguments are passed by value and consume stack space. Unfortunatly, such array consume even more space in the compiler.
But only if they are initialized field by field or something like that, shouldn't they?
Am I missing something? AFAICS, Marten didn't show any actual code. The following program compiles fine for me (but crashes with stack overflow when trying to run it).
program Foo;
type a = array [1 .. 100000000] of Integer;
var v: a;
procedure p (v: a); begin end;
begin p (v) end.
Compiles fine with 3.2.3. Crashes with 3.3.3 and 3.4.0.
Not here:
frank@goedel:~/work# gpc3 --version gpc3 20040423, based on gcc-3.3.3 Copyright (C) 1987-2004 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
frank@goedel:~/work# gpc3 -O3 -g x.pas frank@goedel:~/work# ./a.out Segmentation fault frank@goedel:~/work#
With 20Gb stack limit compiles fine. The following compiles with 2.95.3 but crashes with 3.x:
program foo(output); type ta = string(20000000); var a, b : ta; procedure bar(v : ta); begin write(v) end; procedure baz(u, w : ta); begin write(u); bar(w) end; begin baz(a,b); writeln end .
Again, this compiles fine here, and crashes at runtime with a "small" stack limit.
OK, I did some more testing. On another machine the compiler crashes indeed. The difference seems to be `ACCUMULATE_OUTGOING_ARGS' which apparently is set there but not here (maybe because of different processors, if it's an optimization thing).
Anyway, I'd consider it at least an important flaw. On the one hand, one may say if the stack usage at compile time is of the same magnitude as run time, it doesn't matter, but on the other hand, the program may be intended to run on another machine with more memory. Also, I don't know exactly, but I suppose the backend does something with the allocated memory, which would slow down compilation (again)-: ...
BTW, is there an option to warn about large (value) parameter sizes, i.e. something like `-Wlarger-than-...', only for parameters?
Frank