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

            Bug ID: 110609
           Summary: Bogus -Wmismatched-dealloc when allocator defined &
                    used in same TU w/ -fPIC -fno-semantic-interposition
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andres at anarazel dot de
  Target Milestone: ---

Hi,

Whenever an allocator function annotated with attribute((malloc(freelike)) is
defined and used in the same translation unit and -fno-semantic-interposition
-fPIC are used, bogus mismatched alloc/free warnings ensue.

----
void somefree(int *);

__attribute__((__malloc__(somefree, 1)))
int *somealloc(void) {
  return 0;
}

void other(void) {
  int *v = somealloc();
  somefree(v);
}
---
gcc -Wmismatched-dealloc -fno-semantic-interposition -fPIC -o a.out -c fd.c.i

fd.c.i: In function ‘other’:
fd.c.i:10:3: warning: ‘somefree’ called on pointer returned from a mismatched
allocation function [-Wmismatched-dealloc]
   10 |   somefree(v);
      |   ^~~~~~~~~~~
fd.c.i:9:12: note: returned from ‘somealloc.localalias’
    9 |   int *v = somealloc();
      |            ^~~~~~~~~~~

This appears to happen with all versions supporting -Wmismatched-dealloc,
including today's git head at 3b007164b3e.

Regards,

Andres

Reply via email to