[PATCH] Do not warn with warn_unused_result for alloca(0).

Martin Sebor msebor@gmail.com
Thu Jun 13 19:37:00 GMT 2019

On 6/13/19 10:46 AM, Tom Tromey wrote:
>>>>>> "Jeff" == Jeff Law <law@redhat.com> writes:
> Jeff> I'd like to move C-alloca support to the ash heap of history.  But I'm
> Jeff> not sure we can realistically do that.
> Are there still platforms or compilers in use where it's needed?
> For gdb I was planning to just remove these calls.

The only implementation I know about is Doug Gwyn's alloca.
A Google search returns a pointer to QNX CAR that documents it
with the following note:

  *  By default, alloca() is implemented as __builtin_alloca().
     If you compile with the -fno-builtin option, you'll use
     the libc version of alloca(), which is a cover for malloc()
     and behaves in a slightly different manner:
     -  It keeps track of all blocks allocated with alloca() and
        reclaims any that are found to be deeper in the stack than
        the current invocation. It therefore doesn't reclaim storage
        as soon as it becomes invalid, but it will do so eventually.
     -  As a special case, alloca(0) reclaims storage without
        allocating any. You can use this feature to force garbage

The implementation details aren't important.  What matters is
that to call the library implementation one has to prevent GCC
from treating alloca as a built-in and eliminating the zero size

When the function is not treated as a built-in no warnings for
calls to it are issued and so no problem for us to solve.



More information about the Gcc-patches mailing list