<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60813>60813</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang Static Analyzer misses invalidation of a variable pointed to by a pointee of a global pointer (i.e. ptr-to-ptr, `int**`)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
arseniy-sonar
</td>
</tr>
</table>
<pre>
Invalidation of a local variable through a global pointer works only on 1 level of indirection:
```C++
void opaque();
int* globPtr = nullptr;
int f1(int p) {
p = 1;
globPtr = &p;
opaque(); // p escapes here
if (p != 0) return 0;
return 1/p;
//nonnull(p); //expected-warning{{nonnull}}
}
```
If `p` is reachable through a pointer-to-pointer, it is no longer invalidated. The following example differs only in 2 lines, and while `p` still escapes, the bug is no longer detected.
```C++
void opaque();
int** globPtr = nullptr; // This is now a second-order pointer
int f1(int p) {
p = 1;
*globPtr = &p; // This assignment had to change
opaque(); // p escapes here
if (p != 0) return 0;
return 1/p;
//nonnull(p); //expected-warning{{nonnull}}
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcVM2uqzYQfpphM0qEDSHJgkXOOYp0d5V6X2DAA7h1bGqb5KZPXxkS7s1Ruzq7SpYw9udv_r4ZCkH3lrmG3RvsPjKa4uB8TT6w1fdNcJZ81jh1r7_ZKxmtKGpn0XVIaFxLBq_kNTWGMQ7eTf2AhL1xDRkcnbaRPd6c_zOgs-aOzqJAw1c2iUJbpT23iRGKE-QfkJ-gypf1DvItrfn06rRCN9JfE4M8gDxC8bjRNoI8zSZ_ix6h-EA7GTNGv0JWIHYC5CFtRpBHhP0DgDjOD8WnJ_hCC7IaVwB-9gZBnkGecUQOLY0ccGDPr2y6Q5CHEUGKRJgnJzzHyVvMf2F-HAmQ518NLgassym-xPNimH-M3EZWmxt5q22fgtu_PdH7j7QWZ9bNM9PL77cOocpHqHLUAT1TO3wq66Oem-g2jy3Id9Qx4a1D42zPHvVTJ6y2-H1g7Jwx7qZtj_yDLqNhVLrr2D8koS1KNNpySGxkFd4GbXh1JkRtzDOpCRIHxmbqX60qjnP426-o6L-F9Kzu90GHxfANCQO3zqqN84r9MztflRzI07-I7sX-0rMXthEHUhgdtgPZnv9_ysxUXahjcaSMa1Htq93uWOaHbKiLgpQ6iF2zlx1xtxdUKjoIUTKJUu3LTNcyl0UuRSXKXVUetqzynShaLhSLqqQWypwvpM3WmOtl63yf6RAmrqv8IIrMUMMmzENRSss3nC9ByjQjfZ3ebJqpD1DmRocYfrJEHQ3X74Zsj79HirrFkyVz_5s9XnQIHH52yDpJ1xm6iGiuaXNfW44X1KexmnS15S2OcWnJOLcjVPkq5pREecwmb-ohxjGkITuXpNdxmJpt6y4gz8n1x2czevcHtxHkeQ44gDzPCfknAAD__6o61i4">