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

            Bug ID: 110546
           Summary: Function clone not treated as valid allocator with
                    -Wmismatched-dealloc
           Product: gcc
           Version: 13.1.1
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fw at gcc dot gnu.org
            Blocks: 99715
  Target Milestone: ---

If compiled with -Wall -Werror -O3, the code below produces the following
diagnostic:

t.c: In function ‘f’:
t.c:16:3: error: ‘dealloc’ called on pointer returned from a mismatched
allocation function [-Werror=mismatched-dealloc]
   16 |   dealloc (alloc (1));
      |   ^~~~~~~~~~~~~~~~~~~
t.c:16:3: note: returned from ‘alloc.constprop’
   16 |   dealloc (alloc (1));
      |   ^~~~~~~~~~~~~~~~~~~


I believe this happens because the compiler does not recognize that
alloc.constprop is a valid allocation function for alloc because its internal
name is distinct from the expected name dealloc.


extern void *alloc0 (int n);

void dealloc (void *);

void *__attribute__ ((noinline, malloc (dealloc, 1)))
alloc (int n)
{
  if (n <= 0)
    __builtin_abort ();
  return alloc0 (n);
}

void
f (void)
{
  dealloc (alloc (1));
}


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99715
[Bug 99715] [meta-bug] bogus/missing Wmismatched-dealloc warnings

Reply via email to