On 11/20/16 00:43, Martin Sebor wrote:
> As best I can tell the result isn't actually used (the code that
> uses the result gets branched over). GCC just doesn't see it.
> I verified this by changing the XALLOCAVEC macro to
>
> #define XALLOCAVEC(T, N) (N ? alloca (sizeof (T) * N) : 0)
>
> and bootstrapping and running the regression test suite with
> no apparent regressions.
>
I would like this solution with braces around N better than
allocating one element when actually zero were requested.
The disadvantage of N+1 or N+!N is that it will hide true
programming errors from the sanitizer.
>> you should also include glibc and busybox, to be sure.
>
> Thanks for the suggestion. I've done that and found no instances
> of any of these warnings in either Busybox 1.25.1 or Glibc trunk.
>
Good. I see many alloca calls all over, but mostly in the runtime
libraries, that don't use -Werror.
Have you done a bootstrap with all languages?
Were there warnings in the target libraries (note they don't use
-Werror, so you have to grep)?
I am a bit worried about that suggestion in libiberty/alloca.c:
"It is a good idea to use alloca(0) in
your main control loop, etc. to force garbage collection."
Because:
#include <stdio.h>
#include <alloca.h>
int main()
{
void* p;
int i;
for (i=0 ; i<100 ; i++)
{
p = alloca(0);
printf("%p\n", p);
}
}
... is fine, and allocates no memory.
But if I change that to alloca(1) the stack will blow up.
Maybe it would be better to have a different warning option
for malloc/realloc with zero and for alloca with zero?
Bernd.