[Bug analyzer/124672] New: deref-before-check confused by macro with call
aoliva at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sat Mar 28 06:46:37 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124672
Bug ID: 124672
Summary: deref-before-check confused by macro with call
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: analyzer
Assignee: dmalcolm at gcc dot gnu.org
Reporter: aoliva at gcc dot gnu.org
Target Milestone: ---
deref-before-check-2.c fails on vxworks x86, because stderr is #defined to a
function call, and that causes deref_before_check::emit to return after:
location_t check_loc = m_check_enode->get_point ().get_location ();
if (linemap_location_from_macro_definition_p (line_table, check_loc))
That's odd because stderr isn't even part of the check stmt, it's part of the
deref stmt.
The following variant of the testcase triggers the problem on other targets:
#include <stdio.h>
struct st
{
char *str;
int i;
};
extern FILE *get_stream (void);
#define stream (get_stream ())
int test_1 (struct st *p)
{
fprintf (stream, "str: %s\n", p->str); /* { dg-message "pointer 'p' is
dereferenced here" } */
if (!p) /* { dg-warning "check of 'p' for NULL after already dereferencing
it" } */
return -1;
return p->i;
}
Oddly, '#define stream stderr' does NOT trigger the problem.
I figure the presence of the unexpected unrelated call after the deref gimple
stmt gets things confused, but the fprintf call doesn't.
Assigning 'FILE *err = stream;' in the function and using err in the call is
enough to get the expected warning.
More information about the Gcc-bugs
mailing list