Re: What's wrong with alloca() ?

rankin@eql.caltech.edu (Pat Rankin)
Sun, 5 Jan 1992 02:55:00 GMT

          From comp.compilers

Related articles
[5 earlier articles]
Re: What's wrong with alloca() ? David.Chase@Eng.Sun.COM (1991-12-23)
Re: What's wrong with alloca() ? pcg@aber.ac.uk (1991-12-26)
Re: What's wrong with alloca() ? wicklund@intellistor.com (1991-12-30)
Re: What's wrong with alloca() ? wws@renaissance.cray.com (1991-12-30)
Re: What's wrong with alloca() ? jfc@athena.mit.edu (1991-12-31)
Re: What's wrong with alloca() ? GORMAN_B@prime1.lancashire-poly.ac.uk (Barry Gorman) (1992-01-03)
Re: What's wrong with alloca() ? rankin@eql.caltech.edu (1992-01-05)
Re: What's wrong with alloca() ? pcg@aber.ac.uk (1992-01-05)
Re: What's wrong with alloca() ? barmar@think.com (1992-01-06)
| List of all articles for this month |
Newsgroups: comp.compilers
From: rankin@eql.caltech.edu (Pat Rankin)
Summary: even when it's easy, alloca is unsafe
News-Software: VAX/VMS VNEWS 1.41
Keywords: storage, C
Organization: California Institute of Technology
References: 91-12-075 92-01-011
Date: Sun, 5 Jan 1992 02:55:00 GMT

In article 92-01-011, Barry Gorman <GORMAN_B@prime1.lancashire-poly.ac.uk> writes...
> Some time ago, I implemented alloca() for the Pr1me '50 series. This has
> been used in a variety of applications without any problems being found.
>[... description of stack frame manipulation omitted ...]


          It's pretty trivial to do the same thing on a VAX, at least when
the usual calling conventions are used. However, other systems don't
necessarily have nice clean stacks, so can pose difficulty.


> No compiler support is required; and nested
> function calls pose no problem.


          Your method breaks when used with VAX C (DEC's C compiler for VMS).
Local variables can be reached with either a positive offset from the
stack pointer or a negative offset from the frame pointer. The compiler
usually uses the latter, but it may choose to use the former if that
offset is smaller (byte vs word, or word vs longword), so manipulating
the stack pointer behind its back is definitely unsafe. In other words,
compiler support _is_ required even though anybody could code their own
alloca() implementation. Munging the stack in such a way may also require
additional debugger support too. Matching calls and returns can be tough
if some of the latter have been shortcircuited by jumps. ;-)


Pat Rankin, rankin@eql.caltech.edu


--


Post a followup to this message

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