https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98664
Bug ID: 98664 Summary: inconsistent --Wfree-nonheap-object for inlined calls to system headers 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: --- -Wfree-nonheap-object (as well as -Wmismatched-new-delete and -Wmismatched-dealloc) should be issued for invalid calls to allocation and deallocation functions made in system headers and inlined into user code (see pr57111 comment 16). The test case below shows this doesn't work consistently. When the program is compiled without -g only one invalid call is diagnosed. But when it's compiled with -g both are. This bug captures the subset related to the -g inconsistency discussed in pr98465. Without -g: $ cat t.C && gcc -O2 -S -Wall -Wextra t.C # 1 "t.h" 1 3 struct S { void *p; void f0 (void *q) { p = q; } void f1 (void *q) { f0 (q); } void g0 (void) { __builtin_free (p); } void g1 (void) { g0 (); } }; # 1 "t.C" int x; __attribute__ ((noipa)) void f0 (struct S *p) { p->f0 (&x); p->g0 (); } __attribute__ ((noipa)) void f1 (struct S *p) { p->f1 (&x); p->g1 (); } In file included from t.C:1: In member function ‘void S::g0()’, inlined from ‘void f0(S*)’ at t.C:7:9: t.h:8:35: warning: ‘void __builtin_free(void*)’ called on unallocated object ‘x’ [-Wfree-nonheap-object] In file included from t.C:1: t.C: In function ‘void f0(S*)’: t.C:2:5: note: declared here 2 | | ^ With -g: $ gcc -O2 -S -Wall -Wextra -g t.C In file included from t.C:1: In member function ‘void S::g0()’, inlined from ‘void f0(S*)’ at t.C:7:9: t.h:8:35: warning: ‘void __builtin_free(void*)’ called on unallocated object ‘x’ [-Wfree-nonheap-object] In file included from t.C:1: t.C: In function ‘void f0(S*)’: t.C:2:5: note: declared here 2 | | ^ In file included from t.C:1: In member function ‘void S::g0()’, inlined from ‘void S::g1()’ at t.h:9:23, inlined from ‘void f1(S*)’ at t.C:13:9: t.h:8:35: warning: ‘void __builtin_free(void*)’ called on unallocated object ‘x’ [-Wfree-nonheap-object] In file included from t.C:1: t.C: In function ‘void f1(S*)’: t.C:2:5: note: declared here 2 | | ^