Re: Sparse warning: bitmap.h: bad constant expression

From: Linus Torvalds
Date: Tue Sep 02 2003 - 12:12:10 EST


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.

Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/