On 01/11/2018 01:27 AM, Richard Biener wrote: > On Thu, 11 Jan 2018, Marc Glisse wrote: > >> On Tue, 9 Jan 2018, Prathamesh Kulkarni wrote: >> >>> As Jakub pointed out for the case: >>> void *f() >>> { >>> return __builtin_malloc (0); >>> } >>> >>> The malloc propagation would set f() to malloc. >>> However AFAIU, malloc(0) returns NULL (?) and the function shouldn't >>> be marked as malloc ? >> >> Why not? Even for >> void*f(){return 0;} >> are any of the properties of the malloc attribute violated? It seems to >> me that if you reject malloc(0), then even the standard malloc function >> should be rejected as well... > > The constraint for the malloc attribute is that it returns a > unique pointer for each invocation that cannot alias with any > other pointer in the program, or NULL. So yes, { return 0; } > qualifies as 'malloc' (but I wouldn't mark that on its own ;)). It'd certainly be strange to see something like that marked as malloc. At some point the result of an allocation has to feed into the return value.
> > Also > > int x; > > void *f(size_t n) > { > if (x) > return malloc (n); > return 0; > } > > does. The only constraint is really that the value feeding > the return statement is either literal zero or produced > by a call with the malloc attribute. So even Right. > > void *__attribute__((malloc)) bar(); > > void *f(size_t n) > { > if (n == 2) > return bar (); > return malloc (n); > } > > is malloc. Also agreed. jeff