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

    <tr>
        <th>Summary</th>
        <td>
            clang static analyzer checker core.NullDereference:  false positive about " *e = (0 == e);"
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          Geoffrey1014
      </td>
    </tr>
</table>

<pre>
    
I got a false positive error when compiling the following "minimal, complete and verifiable example (MCVE)" program:
# include <stdio.h>
```c
void a(int *e) {
//   printf("NPD_FLAG: %d\n", e[0]);
    *e = (0 == e);
}
int main() {
    int d[4];
    for (int c =0 ; c < 4; c++)
        ;
    a(d);
    return 0;
}
```

Compiling the above code with Clang (trunk) with `--analyze --analyzer-output text` in  https://godbolt.org/z/nfrbd4P5h results in : 
```bash
<source>:5:8: warning: Dereference of null pointer (loaded from variable 'e') [core.NullDereference]
    *e = (0 == e);
     ~ ^
<source>:5:11: note: Assuming 'e' is equal to null
    *e = (0 == e);
          ^~~~~~
<source>:5:8: note: Dereference of null pointer (loaded from variable 'e')
    *e = (0 == e);
     ~ ^
1 warning generated.
Compiler returned: 0
```

But the false positive error will disappear, if I change the "c < 4" to "c < 3" or comment lines 9-10 as the following two:
```c
# include <stdio.h>

void a(int *e) {
//   printf("NPD_FLAG: %d\n", e[0]);
    *e = (0 == e);
}
int main() {
    int d[4];
    for (int c =0 ; c < 3; c++)
        ;
    a(d);
    return 0;
}
```
```c
# include <stdio.h>

void a(int *e) {
//   printf("NPD_FLAG: %d\n", e[0]);
    *e = (0 == e);
}
int main() {
    int d[4];
    //for (int c =0 ; c < 4; c++)
    //    ;
    a(d);
    return 0;
}
```


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlVkuP2zgM_jX2hUhgy6_44EMe06LAbtHTXheyTcfaKlJWkpNOf_1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