tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] VLAs broken on mob branch


From: Pip Cet
Subject: Re: [Tinycc-devel] VLAs broken on mob branch
Date: Thu, 30 Apr 2015 13:28:12 +0000

Hi,
You need to read the documentation for alloca(), it behaves
differently depending on whether there are VLAs in scope or not. We
MUST NOT handle alloca() like VLAs, that would break a lot of code.

On Thu, Apr 30, 2015 at 12:36 PM, Sergey Korshunoff <address@hidden> wrote:
>> while(1) {
>>    int *b = alloca(4);
>> }
>> will run out of memory eventually, while
> No, at the begining of block we will restore a stack if we handle
> alloca like VLA

That's why we must not do so :-)

> Can you point to the standard for the alloca()? And what happens when
> we leave a block?

Nothing, unless a VLA also goes out of scope, in which case behavior
is undefined.

You want to read

https://www.gnu.org/software/libc/manual/html_node/GNU-C-Variable_002dSize-Arrays.html#GNU-C-Variable_002dSize-Arrays
(and the rest of what that manual has to say about alloca()).

>> while(1) {
>>    int b[function_returning_1()];
>>    printf("%p\n", b);
>> }
>> mustn't run out of memory.
> Proof? What happens if function_returning_1() will return (unsigned
> long)(void *)-1 ?
>
> A test for your first example:
> int x = 4;
> while(1) {
>     int *b = alloca(4);
>     int vla[x];
> }
> A stack will be restored, alloca() will NOT run out of memory.
> Why a different semantic which depends on the context?

Because, again, that's the standard behaviour. That's why my example
did not include the VLA.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]