https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95554
Bug ID: 95554 Summary: spurious -Wnonnull on a conditional call Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- The C test case below was reduced from gcc/var-tracking.c which triggers the -Wnonnull (in C++) when the this pointer in member functions is considered implicitly declared nonnull (or, alternatively, when vec::is_empty() is declared with attribute nonnull): In file included from /ssd/test/src/gcc/86568/gcc/var-tracking.c:89: /ssd/test/src/gcc/86568/gcc/var-tracking.c: In function ‘void loc_exp_dep_alloc(variable*, int)’: /ssd/test/src/gcc/86568/gcc/var-tracking.c:8109:46: error: ‘this’ pointer null [-Werror=nonnull] 8109 | || VAR_LOC_DEP_VEC (var)->is_empty ()); | ^ /ssd/test/src/gcc/86568/gcc/system.h:748:14: note: in definition of macro ‘gcc_assert’ 748 | ((void)(!(EXPR) ? fancy_abort (__FILE__, __LINE__, __FUNCTION__), 0 : 0)) | ^~~~ /ssd/test/src/gcc/86568/gcc/var-tracking.c:8107:3: note: in expansion of macro ‘gcc_checking_assert’ 8107 | gcc_checking_assert (!count | ^~~~~~~~~~~~~~~~~~~ In the test case the P macro corresponds to the VAR_LOC_DEP_VEC() macro defined in the file, function g() to loc_exp_dep_alloc (), and the return statement to the gcc_checking_assert. $ cat q.c && gcc -O2 -S -Wall -fdump-tree-original=/dev/stdout q.c __attribute__ ((nonnull)) int f (void*); struct A { int i; }; struct B { struct A *p; }; #define P(p) (p->p ? &p->p : 0) int g (struct B *p) { return P (p) == 0 || f (P (p)); } q.c: In function ‘g’: q.c:17:24: warning: null argument where non-null required (argument 1) [-Wnonnull] 17 | return P (p) == 0 || f (P (p)); | ^ ;; Function g (null) ;; enabled by -tree-original { return (p->p == 0B || &p->p == 0B) || f (p->p != 0B ? (void *) &p->p : 0B) != 0; }