<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/83719>83719</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
No warning reported when storing address of the local variable (Wdangling-pointer)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mushenoy
</td>
</tr>
</table>
<pre>
Clang seem to miss detecting the dangling pointer warning (Wdangling-pointer) found with GCC
Sample Program:
```
#include <stdio.h>
void test (int **p)
{
int x = 7;
*p = &x;
}
int main ()
{
int *xp = NULL;
test (&xp);
printf ("dereference of xp = %d\n", *xp);
return 0;
}
```
Compilation using clang:
No warnings reported
```
# clang -Wall -c dangling.c
#
```
Compilation using gcc:
```
# gcc -Wall -c dangling.c
dangling.c: In function test:
dangling.c:5:6: warning: storing the address of local variable x in *p [-Wdangling-pointer=]
5 | *p = &x;
| ~~~^~~~
dangling.c:4:7: note: x declared here
4 | int x = 7;
| ^
dangling.c:2:18: note: p declared here
2 | void test (int **p)
|
```
Compiler versions:
```
clang version 16.0.6
gcc (GCC) 13.2.1
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVMGO4ygQ_Rp8KcWyIdjxwYd00lmtNBqttFrNmZiKzQqDBbg7c-lvX2E77mz3ZEZjWUBRxXsF9UB4r1qDWBP-RPgxEWPorKv70Xdo7PfkbOX3-qCFacEj9hAs9Mp7kBiwCcq0EDoEKUyrozFYZQI6eBXORJvQ3bebc7M4Ca3gYkcj4VWFDv44HEh2JNl-bv8W_aAR_nK2daInbJkmRbb8s0mZMo0eJQJhBx-ksmlH2PPsfbFKQkAfIr8ysdsTuh8IrZbl5dM8AIjuKxB2hJKwdTZGT5OEFtd1npTHeRAX9UKZiP8IlND9dcb4-s-XL3fYt8Qi9JTSCr8EDE6ZcJlDqESHF3RoGgR7gestLS4JPxhCKaGHmeseCsBhGJ2B7HPyH49yag-2H5QWQVkDo4-la2LR1_P_am819eBwsC6gfFSZeSlsvgmtYdOs6kibNeS3Mmmb5ic6iO53rk9kdzbbw58GLqNpJvBYhxX3f2GcsH0Rw5ctx6EP1t3kLqR06H2sh7aN0PAinBJnjXCFSRRRPPxp81n67Ej48VYiAA6kPMAjucH0xYi3tzfCn2P7OdktYfsyZmhswNhfQWKjhUMJHTp8x9oubD-U_OyaCPnzD2goYft8d88zPOKhE9gvL-G6vV-KAR28oPPKGh-JP8Qv9iy6JQ7yIs3SYnFFhRC6iy8NrSBnKU3zn5AmsmayYpVIsM7LrNoWvCqzpKu3FypFXqJk7JzxbUZ3DaOy2Mp8l58LliWqphndZixjec4qlqWcFqXgXDJRFpJXZ7LNsBdKp1q_9Kl1baK8H7HesTKvEi3OqP30FFNq8BUmZ7zj_Ji4Oq7ZnMfWk22mlQ_-HSWooLF-v6TrHYXXDs0q3jvhRh1_EO-DxzoZna67EIZ4-ISeCD21KnTjOW1sT-gpJrF0m8HZf7EJhJ6m1D2hp2lr_wUAAP__1F_SPw">