[Bug middle-end/99714] warn about alloca/dealloc mismatches based on calls with same object in different functions

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Mar 23 14:40:26 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99714

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|dmalcolm at gcc dot gnu.org        |unassigned at gcc dot gnu.org
          Component|analyzer                    |middle-end
           Keywords|documentation               |diagnostic

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
The C test case (corrected below) is meant to allocate and deallocate the the
member pointer, just like the C++ test case.

I also raise this as an enhancement for the -Wmismatched-dealloc and
Wmismatched-new-delete warnings (hence Changing component back to middle-end),
although I think it would be worthwhile improvement to the analyzer as well. 
I'm not sure what the best way is to track enhancements to both kinds of
warnings.  Clone one to the other?

struct A { int *p; };

void dealloc (void*);
__attribute__ ((malloc (dealloc))) void* alloc (int);

void init (struct A *p, int n) { p->p = alloc (n * sizeof *p); }
void fini (struct A *p)
{
  __builtin_free (p->p);  // missing -Wmismatched-dealloc
}

#endif


More information about the Gcc-bugs mailing list