[cfe-dev] Stack space consumption query

Dallman, John john.dallman at siemens.com
Fri Jan 20 03:58:02 PST 2012

> Any suggestions welcomed - this appears to be a neglected area.

Well, I isolated some of the test cases that have stack overflows, and
found they were all making significant numbers - 25 or so - recursive
calls to the same fairly large function.

So measuring stack space consumed by the function seemed worth trying,
which one can easily approximate as the distance between the address
of a variable in successive recursive calls. The results were quite

VS.2008sp1 on Windows: 2560 bytes 32-bit and 3520 bytes 64-bit. This
compiler has always been very frugal with stack space.

GCC 4.2 on Mac OS X 10.6: 5424 bytes 32-bit and 5664 bytes 64-bit.

Clang 2.1 on GCC 10.7: 43,504 bytes 32-bit and 44,224 bytes 64-bit.
Yes, this really is the same code; there's no platform-specific code
in that function. Those measurements were taken with optimisation of
-O2; at -O1, the figures are 12,288 bytes 32-bit and 12,480 bytes

So yes, Clang 2.1 really does seem to have a problem with stack space
usage. This may force us to move up to a later version.

John Dallman

More information about the cfe-dev mailing list