From: Dennis Ritchie <email@example.com>
Subject: Re: !alloca (was: Re: How's this: Where do I get a C99 compiler?)
Date: Mon, 31 Jan 2000 19:08:12 +0000
As a point of history, alloca was first done
by Ken Thompson between the 6th and 7th edition
PDP-11 systems. Because of the stack layout,
this was trivial and robust against most of
the obvious failures (not f(a, alloca(10), b)
When we started doing the Interdata port,
alloca looked quite hard to do and much less
robust. So I extirpated it; none of our
distributions had it.
Somehow, however, it had escaped, perhaps
in a PWB distribution. Or perhaps it
From: Linus Torvalds <firstname.lastname@example.org>
Subject: Re: Sparse warning: bitmap.h: bad constant expression
Date: Tue, 2 Sep 2003 17:06:17 GMT
Mikael Pettersson wrote:
> If data is a local variable then this is perfectly valid example of a
> C99 variable-length array (VLA). This works at least with gcc-2.95.3
> and newer, and gcc handles it by itself w/o calling alloca().
"alloca()" is not a function. It's a compiler intrisic, and Jörn is correct:
a variable-length array is _exactly_ the same as the historic "alloca()"
thing, and will generate the same code (modulo syntactic changes due to the
fact that one generates a pointer and the other generates an array).
And yes, it is legal in C99. However, it's not supposed to be legal in the
kernel, because it makes it impossible to check certain trivial things
about stack usage automatially. In particular, it totally breaks the
"objdump + grep" approach for finding bad stack users.
Also, trivial bugs (like not checking ranges etc) cause total stack
corruption with the feature, which means that such a kernel bug gets really
hard to track down.
So I consider the sparse warning to be appropriate.
That said, I do want to have a code-generation back-end for sparse some day,
if only because it's the only practical way to validate the front-end (ie
seeing if the back-end generates code that actually works - performance
doesn't matter). So I'd like to eventually extend sparse to handle variable
arrays, but I'd still want to have a flag to warn about them.