[Bug tree-optimization/126378] [13/14/15/16/17 Regression] spurious -Wnonnull "'this' pointer is null" at -O2 for pointer guarded by preceding null checks (regression from 10.x)

"pinskia at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126378

Drea Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic,
                   |                            |missed-optimization
   Target Milestone|---                         |13.5
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2026-07-23
            Summary|spurious -Wnonnull "'this'  |[13/14/15/16/17 Regression]
                   |pointer is null" at -O2 for |spurious -Wnonnull "'this'
                   |pointer guarded by          |pointer is null" at -O2 for
                   |preceding null checks       |pointer guarded by
                   |(regression from 10.x)      |preceding null checks
                   |                            |(regression from 10.x)

--- Comment #1 from Drea Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. Looks like we are warning right after inlining which means we get
something like:
```
  <bb 2> [local count: 1073741824]:
  _6 = q_2(D) == 0B;
  if (_6 != 0)
    goto <bb 6>; [34.00%]
  else
    goto <bb 3>; [66.00%]

  <bb 3> [local count: 708669600]:
  if (q_2(D) != 0B)
    goto <bb 4>; [82.57%]
  else
    goto <bb 5>; [17.43%]
```

Which then gets optimized away and the call to `p->get()` is removed
afterwards.


But really the issue is before inlining we don't change this to the reasonible
IR:
```
  <bb 2> :
  _1 = p_6(D) == 0B;
  _2 = q_7(D) == 0B;
  _3 = _1 & _2;
  if (_3 != 0)
    goto <bb 3>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 3> :
  // predicted unlikely by early return (on trees) predictor.
  goto <bb 7>; [INV]

  <bb 4> :
  if (q_7(D) != 0B)
    goto <bb 5>; [INV]
  else
    goto <bb 6>; [INV]
```
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.