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

Attachment: nb_args_zero.patch
Description: nb_args_zero.patch

_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to