https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104761
Bug ID: 104761 Summary: [12 Regression] False positive -Wdangling-pointer warning on NetworkManager since r12-6606 Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: jakub at gcc dot gnu.org Target Milestone: --- With -O0 -Wdangling-pointer or -O2 -Wall (the latter is a regression) the following testcase emits 2 false positive warnings: nm-shared-utils.i: In function ‘test’: nm-shared-utils.i:21:40: warning: dangling pointer to ‘error’ may be used [-Wdangling-pointer=] 21 | corge (qux (addrbin.s), error->t); | ^~ nm-shared-utils.i:18:45: note: ‘error’ declared here 18 | __attribute__((__cleanup__ (bar))) T *error = (T *) 0; | ^~~~~ nm-shared-utils.i:21:11: warning: dangling pointer to ‘addrbin’ may be used [-Wdangling-pointer=] 21 | corge (qux (addrbin.s), error->t); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ nm-shared-utils.i:13:5: note: ‘addrbin’ declared here 13 | S addrbin; | ^~~~~~~ Commenting out the endless loop makes it go away. Started with the addition of -Wdangling-pointer in r12-6606-g9d6a0f388eb048f8d87f. typedef struct { unsigned int s; } S; int foo (S *); typedef struct { char *t; } T; void garply (T *); static inline void bar (T **v) { if (*v) garply (*v); } int baz (T **); const char *qux (unsigned); void corge (const char *, const char *); int test (int x) { S addrbin; if (foo (&addrbin) != 1) return 0; if (x == 2) { __attribute__((__cleanup__ (bar))) T *error = (T *) 0; if (!baz (&error)) { corge (qux (addrbin.s), error->t); for (;;) ; } } return 1; }