Re: stack overflow at compile time

Robert A Duff <bobduff@shell01.TheWorld.com>
29 Apr 2006 19:26:39 -0400

          From comp.compilers

Related articles
[3 earlier articles]
Re: stack overflow at compile time nitin@CoWare.com (Nitin Gupta) (2006-04-27)
Re: stack overflow at compile time henry@spsystems.net (2006-04-27)
Re: stack overflow at compile time gah@ugcs.caltech.edu (glen herrmannsfeldt) (2006-04-28)
Re: stack overflow at compile time jvorbrueggen@mediasec.de (=?ISO-8859-1?Q?Jan_Vorbr=FCggen?=) (2006-04-28)
Re: stack overflow at compile time jatin.bhateja@conexant.com (Jatin Bhateja) (2006-04-28)
Re: stack overflow at compile time emailamit@gmail.com (Amit Gupta) (2006-04-29)
Re: stack overflow at compile time bobduff@shell01.TheWorld.com (Robert A Duff) (2006-04-29)
Re: stack overflow at compile time emailamit@gmail.com (Amit Gupta) (2006-04-30)
Re: stack overflow at compile time henry@spsystems.net (2006-04-30)
Re: stack overflow at compile time henry@spsystems.net (2006-04-30)
Re: stack overflow at compile time bobduff@shell01.TheWorld.com (Robert A Duff) (2006-05-01)
Re: stack overflow at compile time gah@ugcs.caltech.edu (glen herrmannsfeldt) (2006-05-03)
| List of all articles for this month |

From: Robert A Duff <bobduff@shell01.TheWorld.com>
Newsgroups: comp.compilers
Date: 29 Apr 2006 19:26:39 -0400
Organization: The World Public Access UNIX, Brookline, MA
References: 06-04-157 06-04-161 06-04-166 06-04-177
Keywords: storage, theory
Posted-Date: 29 Apr 2006 19:26:39 EDT

"Amit Gupta" <emailamit@gmail.com> writes:


> [You can't even get an upper bound in the general case. Imagine a
> program that reads in a number and uses that as the number of times to
> call itself recursively. -John]


You can always get an upper bound. It just might not be useful in
some cases. The upper bound in the above program would be "the size
of the address space".


GNAT (the gcc Ada compiler) does static stack-size analysis. I'm not
sure of all the details, but I think you can get a conservative upper
bound, or a not-so-conservative estimate based on user-provided
information about recursion depth and so forth.


Ada also requires run-time stack overflow checks, in cases where it
can't be statically determined.


GNAT also allows you to find out the stack depth used for any given
run of a program.


In many embedded systems, a static worst case is quite good enough,
because such programs might not need to use recursion,
dynamically-sized stack variables, and indirect calls.


- Bob Duff
    AdaCore Technologies


[It's not even the size of the address space. If my frame size is,
say, a megabyte, and my recursion is a million, I'm going to need a
million megabytes. If the system doesn't have a million megabytes,
well, shucks, my program will fail. I entirely agree that in many
useful special cases you can do static stack size analysis and come up
with a result, but in the general case, it's hopeless. -John]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.