tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] Avoid allocating a VLA of size zero


From: Petr Skočík
Subject: Re: [Tinycc-devel] Avoid allocating a VLA of size zero
Date: Wed, 12 Jun 2019 23:45:58 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1

Nice find, Pascal Cuoq.

I think it looks a bit better without the extra variable:

        char _onstack[nb_args?nb_args:1], *onstack = _onstack;

but then I have been told my overall style sucks.

Cheers,
Petr S.


On 6/12/19 10:39 PM, Pascal Cuoq wrote:
> Hello,
> 
> Arrays of size zero are not part of standard C, even when they are
> Variable Length Arrays
> (https://port70.net/~nsz/c/c11/n1570.html#6.7.6.2p5 ). GCC accepts
> arrays of size 0 as an extension, but since TCC's small size and being
> implemented in C in the first place may lead it to be compiled with any
> C compiler, you may consider it desirable to make sure it's written in
> portable C when reasonable. This is orthogonal to having TCC accepts GCC
> extensions, perhaps including this one. What I'm saying is, it can be
> considered better to have TCC being written in portable C for when it's
> not compiled with GCC or TCC.
> 
> 
> In non-TCC_TARGET_PE mode, the function gfunc_call in the file
> x86_64-gen.c creates a VLA of size 0 when it is called with nb_args == 0:
> 
> void gfunc_call(int nb_args)
> {
>     ...
>     char _onstack[nb_args], *onstack = _onstack;
> 
> Assuming you agree it would be preferable not to, this can be fixed in
> several ways. The change below, for which a patch is attached, may be
> the one with the least impact:
> 
> void gfunc_call(int nb_args)
> {
>     ....
>     int onstack_size = nb_args == 0 ? 1 : nb_args;
>     char _onstack[onstack_size], *onstack = _onstack;
> 
> Best regards,
> 
> Pascal
> 
> 
> _______________________________________________
> Tinycc-devel mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
> 




reply via email to

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