http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52923

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-04-10
     Ever Confirmed|0                           |1

--- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-04-10 
12:33:38 UTC ---
We lack a must points-to analysis pass.  But it's questionable to warn for

void* test_alloc_struct_ptr_to_stack_mem(void)
{
  int a[100];
  struct test* t = (struct test*)malloc(sizeof(struct test));
  // GIVE WARNING?
  // "function returns with reference to local variable?"
  t->ptr = a;
  return t;
}

as you have no idea whether t is actually dereferenced in the caller.

void* test_alloc_struct_on_stack_mem(void)
{
  struct test* t = (struct test*)alloca(sizeof(struct test));
  t->ptr = NULL;
  // GIVE WARNING?
  // "function returns allocation from stack memory?"
  return t;
}

for this I'd say yes, warn.  Similar for returning a pointer that was free()d.

Reply via email to