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

            Bug ID: 98831
           Summary: missing -Wfree-nonheap-object on a conditional
                    expression
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The -Wfree-nonheap-object warning newly enhanced in GCC 11 successfully
diagnoses the invalid calls to free in f() below but fails to do the same in
g():

$ cat b.c && gcc -S -Wall b.c
extern int a[], b[];

void f (int i)
{
  if (i)
    __builtin_free (a);         // -Wfree-nonheap-object (good)
  else
    __builtin_free (b);         // -Wfree-nonheap-object (good)
}

void g (int i)
{
  __builtin_free (i ? a : b);   // missing -Wfree-nonheap-object
}
b.c: In function ‘f’:
b.c:6:5: warning: ‘__builtin_free’ called on unallocated object ‘a’
[-Wfree-nonheap-object]
    6 |     __builtin_free (a);         // -Wfree-nonheap-object (good)
      |     ^~~~~~~~~~~~~~~~~~
b.c:1:12: note: declared here
    1 | extern int a[], b[];
      |            ^
b.c:8:5: warning: ‘__builtin_free’ called on unallocated object ‘b’
[-Wfree-nonheap-object]
    8 |     __builtin_free (b);         // -Wfree-nonheap-object (good)
      |     ^~~~~~~~~~~~~~~~~~
b.c:1:17: note: declared here
    1 | extern int a[], b[];
      |                 ^

Reply via email to