[cfe-commits] r63394 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGen/sizeof-vla.c

Eli Friedman eli.friedman at gmail.com
Fri Jan 30 19:29:03 PST 2009


On Fri, Jan 30, 2009 at 7:02 PM, Anders Carlsson <andersca at mac.com> wrote:
> Hmm, yeah - we could probably add an implicit cast to the size_t type for
> the VLA size expr.

I don't think we want to add a cast to the AST; in terms of the
semantics, there is no such cast.  I think we should leave the
expression as the declared type in the AST, and cast it to size_t when
we compute the array size.

> Not sure what something like
>
> int a[(unsigned long long)f()]
>
> would do in 32-bit, but given that the alloca instruction only takes a
> 32-bit constant that isn't an issue anyway :)
> What do you think?

If the returned value from f() is too large to allocate, the behavior
is undefined.  Otherwise, it works exactly the way you'd expect it to.
 Adding an implicit cast to the AST would imply that the behavior is
defined in cases where there is no such guarantee from the standard.

-Eli



More information about the cfe-commits mailing list