On 01/10/2018 04:20 PM, Jeff Law wrote:
On 01/09/2018 05:57 AM, 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 ?
This seems like a pretty significant concern.   Given:


 return  n ? 0 : __builtin_malloc (n);

Is the function malloc-like enough to allow it to be marked?

A call to malloc(0) is specified to return either NULL or
a pointer to a distinct object of zero size.  As useless as
it is, the function above satisfies the requirement.  That
said, suggesting to mark it as such wouldn't be terribly
helpful (a different warning pointing out that it's useless
and so probably buggy might be).


If not, then ISTM we have to be very conservative in what we mark.

foo (n, m)
{
  return n ? 0 : __builtin_malloc (m);
}

Is that malloc-like enough to mark?

I think it would be strictly correct as well but again probably
not very useful.

In fact, even

  void* f (size_t n) { return 0; }

is malloc-like, but having -Wsuggest-attribute point out that
it be decorated with the malloc attribute probably wouldn't
make the option very popular ;)

Martin

Reply via email to