Lower VLA representation to pointers
Joseph S. Myers
jsm@polyomino.org.uk
Wed Aug 11 15:09:00 GMT 2004
On Wed, 11 Aug 2004, Jason Merrill wrote:
> Hmm, what happens if xyzzy is in a loop? Previously we would properly
> release its memory when it went out of scope. If we're converting to
> alloca, I suspect that's broken.
The following (execution) test works; the memory is deallocated on leaving
the block:
void *volatile p;
int
main (void)
{
int n;
for (n = 0; n < 1000000; n++) {
int x[n % 1000 + 1];
x[0] = 1;
x[n % 1000] = 2;
p = x;
}
return 0;
}
The following test fails, but also fails in all prior releases that
support the syntax (3.0.x on), I don't know about old 3.5 CVS:
void *volatile p;
int
main (void)
{
int n = 0;
lab:;
int x[n % 1000 + 1];
x[0] = 1;
x[n % 1000] = 2;
p = x;
n++;
if (n < 1000000)
goto lab;
return 0;
}
Note that the VLA goes out of scope and should be deallocated when you
jump to a point before the declaration, unlike non-variable-length objects
with automatic storage duration which have a constant address as long as
you stay within their block, on which jumping to a point before the
declaration has no special effect although the execution of the
declaration initializes the value of the object or makes it indeterminate
according to whether there is an initializer.
(C99 6.2.4#5-6 and footnote 27.)
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)
More information about the Gcc-patches
mailing list