This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Implement stack arrays even for unknown sizes
On Apr 12 2011, Michael Matz wrote:
On Mon, 11 Apr 2011, Steven Bosscher wrote:
Isn't there a way to put a maximum on the size of the arrays on stack,
e.g. -fstack-arrays-limit= or something like that?
Not without generating contorded code. The problem is that these arrays
are variable length, hence runtime tests would be required, branching to
malloc or stack_save/alloca, and also for the deallocation side, requiring
a flag for branching to free or stack_restore. And as we use the variable
length facilities this is actually not controllable in such a way, the
frontend doesn't generate alloca calls at all.
It would almost certainly be cleaner and simpler to use a secondary
stack than to have such dynamic testing. It is very similar (conceptually)
to the dynamic code that switches between inline and library code for
sizes of DO-loop or array on some specialist HPC compilers. And that gets
very messy, very fast.
Regards,
Nick Maclaren.