<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/90117>90117</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
-Wfree-nonheap-object doesn't warn when free() is used on a pointer to an array
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dzhigit1
</td>
</tr>
</table>
<pre>
```
$ clang-18 -v
Debian clang version 18.1.4 (1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/13
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/14
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/14
Candidate multilib: .;@m64
Selected multilib: .;@m64
$ cat test.c
#include <stdlib.h>
int
main(void)
{
char *a = "";
free(a);
return 0;
}
$ gcc -pipe -Wfree-nonheap-object -o test test.c
test.c: In function ‘main’:
test.c:7:3: warning: ‘free’ called on a pointer to an unallocated object ‘""’ [-Wfree-nonheap-object]
7 | free(a);
| ^~~~~~~
test.c:6:9: note: assigned here
6 | char *a = "";
| ^
$ clang-18 -pipe -Wfree-nonheap-object -o test test.c
$ ./test
free(): invalid pointer
Аварийный останов
```
...
```
$ cat test2.c
#include <stdlib.h>
int
main(void)
{
int *a, b[1];
a = b;
free(a);
return 0;
}
$ gcc -pipe -Wfree-nonheap-object -o test2 test2.c
test2.c: In function ‘main’:
test2.c:8:3: warning: ‘free’ called on unallocated object ‘b’ [-Wfree-nonheap-object]
8 | free(a);
| ^~~~~~~
test2.c:6:11: note: declared here
6 | int *a, b[1];
| ^
$ clang-18 -pipe -Wfree-nonheap-object -o test2 test2.c
$ ./test2
free(): invalid pointer
Аварийный останов
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVk-vozYQ_zTDZQQy5v-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