https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108115
Bug ID: 108115 Summary: spurious pointer used after realloc warning Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: t...@develop-help.com Target Milestone: --- Created attachment 54097 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54097&action=edit Code that demonstrates the warning gcc 12.0.1 produces a spurious warning when an access to an integer copy of a pointer is accessed within an unrelated runtime conditional. With the attachment: $ /opt/gcc-12.1.0/bin/gcc -c -std=c99 -O2 -Wall -Wextra gcc-20507-simple.c gcc-20507-simple.c: In function ‘my_realloc’: gcc-20507-simple.c:13:15: warning: pointer ‘p’ may be used after ‘realloc’ [-Wuse-after-free] 13 | uintptr_t u = (uintptr_t)p; | ^ gcc-20507-simple.c:15:18: note: call to ‘realloc’ here 15 | void *newp = realloc(p, newsz); | ^~~~~~~~~~~~~~~~~ $ /opt/gcc-12.1.0/bin/gcc -c -std=c99 -O2 -Wall -Wextra -DDEBUG=1 gcc-20507-simple.c (no diagnostics) Note that p is not used after the realloc() in either case.