<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/72054>72054</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang static analyzer] false positive related to core.NullDereference
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          hallo-mars
      </td>
    </tr>
</table>

<pre>
    Hi,
in this case, `k` and `ptr` have an alias relationship. Initially, `ptr` is assigned the value `(void *)0`. After the assignment `*k = &g`, `ptr` should point to `&g`. However, the analyzer reports an NPD warning for the statement `if (*ptr)`.

```c
int main() {
    int arr[1] = {};
    int *ptr = &arr[0];
    for (int i = 0; i < 3; i++);
    for (int g = 2; g; g--)
        if (*ptr) {
            int **k = &ptr;
            for (int j = 0; j <= 0; j++);
            ptr = (void *)0; *k = &g;
 }
}
```

args: `--analyze --analyzer-output text -Xanalyzer -analyzer-checker=core.NullDereference -Xclang -analyzer-config -Xclang widen-loops=true -Xclang -analyzer-stats -Xclang -analyzer-checker=core,debug.ExprInspection`

See it live: https://godbolt.org/z/7hvxavE8h

Thank you for taking the time to review this case. Many thanks!
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VMuuozgQ_ZrKpgQCEwgsWCSho-7FtEaaWfTWQAXccWxkG-5Nf_3IkOdVJkKkjM-pdxW3VnSKqIR0B2m14qPrtSl7LqUOztzYVa3bS_ldANtDVEG0FQpdLyw23BKwPUIWnSCLkKvWy4Mz_tTziZAr5FJwi4Ykd0Ir24shxB9KOMGlvFzpV4qwePWmRdcTTlyO5O-B5ZMWLQLbAisiyKIQt0dHZoYtnDMpt2C3J4SkQmBZN5-fTdhej7LFQQvl0OmFMONC_K4_aCLjCbNaxeXlDxk0NGjjrA_m598VfnCjhOrwqBfz1nFHN-viiMByYFtvjxVe75K06zuLlqe5pdLhmQs1cwqEzW75jojo77gxkO5iSKslpM0ONhUkX1CLuVvQCyeC9BXo3QWWe7yYoREku1ncYzKLwHbzU_wfr5t5zIO7-RUEHn2Hzv68JuA1pDtocfq5VB6evIE-mf_9cNuL-8fpvee33yM3r12U7PC1We5kn-SlXnfhVrjnanLTWUi2vu5BcG0XvEsm0KMbRoeOPh0Gv-799AA0PTUnMpBUjTYU_hylrMjQkQyphjD41UiuumeCVkfR3S8-REsqkFoPFpLKmfEdx_enfafrxTiwfUv12IXfPgfzQ9mBGj-vXyL-hwiFQykm8oH3znnLW2AHYIdOt7WWLtSmA3b4A-yw6adPPn3L-2cd__ZcnfCix2WC-MkPkx8kJ87kZ9LQJOjjsWNC_IurCzrPs8DiVVsmbZEUfEVlnBVFHsXrnK36Mso2aZpRnR7Tlm-KOt7kaVxQXMQNsTXFK1GyiCVxHLM4jdZrFrZZ26b1Os0znvNmc4R1RGcuZCjldPaBrIS1I5UbFqXrleQ1STsvSsbmdAJjfmea0uODeuwsrCMprLMPDU44OW_XpQC-HKK5bxc_2kcuLeGgrXBiomVX-hWo8V1brEYjyy-ZF64f67DRZ2AHb_j6FwxG_6bGATvMcVhfEx_KfwEAAP__h37A1Q">