https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99229

            Bug ID: 99229
           Summary: missing -Wnonnull for null this pointer in a call to
                    inlined member function
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

This came up in the discussion of the patch for pr99074:
https://gcc.gnu.org/pipermail/gcc-patches/2021-February/565739.html

The invalid use of a null pointer in the program below is not diagnosed: GCC
should issue -Wnonnull for the use of the null this pointer in the call to
A::f() but the call is inlined before the null pointer is propagated.  By the
time -Wnonnull runs just after CCP2 there's no trace of the member function
call, and the invalid MEM_REF isn't diagnosed.

$ cat t.C && /build/gcc-master/gcc/xgcc -B /build/gcc-master/gcc -O2 -S -Wall
-fdump-tree-post_ipa_warn=/dev/stdout t.C
struct A { int i; void f () { i = 0; } };

A* g () { return 0; }

void h ()
{
  g ()->f ();
}

;; Function g (_Z1gv, funcdef_no=1, decl_uid=2353, cgraph_uid=2,
symbol_order=1)

struct A * g ()
{
  <bb 2> [local count: 1073741824]:
  return 0B;

}



;; Function h (_Z1hv, funcdef_no=2, decl_uid=2355, cgraph_uid=3,
symbol_order=2)

void h ()
{
  <bb 2> [local count: 1073741824]:
  MEM[(struct A *)0B].i = 0;
  return;

}

Reply via email to