https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114776
Bug ID: 114776 Summary: -Wuse-after-free analysis believes assert() but not g_assert_null() Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: alan.coopersmith at oracle dot com Target Milestone: --- Created attachment 57985 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57985&action=edit Test case When reviewing the -Wuse-after-free error reported in: https://gitlab.freedesktop.org/xorg/lib/libxmu/-/merge_requests/13 in which gcc gives a use-after-free warning for p in: p2 = Xmureallocarray(p, 2, ALLOC_LIMIT); g_assert_null(p2); [...] free(p); even though the realloc failed and returned NULL and did not free p. I found that the -Wuse-after-free warning went away if I changed g_assert_null(p2); to assert(p2 == NULL); so it appears something in the way g_assert_null from glib is defined does not convince gcc that p2 must be NULL the way the simple system assert does. I've made a cut down test case, and can reproduce the false alarm with gcc `pkg-config --cflags glib-2.0` -Wall -O2 -c realloc.c using gcc 13.2.0 on Solaris 11.4.66 on x86-64. (The original report came from a gentoo Linux user, and I reproduced on Debian Linux, so this isn't OS-specific.) Adding -DUSE_SYSTEM_ASSERT to the compiler command line makes the warning go away.