Issue |
83719
|
Summary |
No warning reported when storing address of the local variable (Wdangling-pointer)
|
Labels |
new issue
|
Assignees |
|
Reporter |
mushenoy
|
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
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs