<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/79443>79443</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Diagnose misuse of the cleanup attribute
</td>
</tr>
<tr>
<th>Labels</th>
<td>
enhancement,
quality-of-implementation,
clang:diagnostics
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
AaronBallman
</td>
</tr>
</table>
<pre>
The cleanup attribute is written on a variable declaration, and the address of the declared variable is passed to the specified function in the attribute. This has some subtle issues we should diagnose on. Consider:
```
__attribute__((cleanup(free))) void *p = malloc(10);
```
This will pass `&p` to `free`, which is going to do the wrong thing. GCC diagnoses this kind of misuse (`warning: 'free' called on unallocated object 'p' [-Wfree-nonheap-object]`) and it would be good if we did the same: https://godbolt.org/z/nhqh9EazM
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsU02PozgQ_TXmUkpkDCHhwCEfmz3traU9RgYXuGaMTWPTUfevH9nQ3dLMSEioPlxV770q6T0NFrFhhws73DK5BO3m5ixnZy_SmFHarHXqvXnRCJ1BaZcJZAgztUtAIA_PmUJAC86ChDc5k2wNgsLOyFkGcpaJK0irIGgEqdSM3oPrk7lmofp-Rx4m6T0qCC6l-Ak76gkV9IvtYj0gu9b6nGIPL5o8aOnBuxHBL21IpfyCHp4IXrvFKFAkB-s8grN7uDrrSeHMijPjN8bPrOLbl8zH46v-48HEiYnTBp-JUz8jMlGvH7w5UsDEeQJW3GCUxriOiVPOY7y4_LV8mvhJxiS4EP2imljFI25W8dQhOq_w1NTpSMzgyA4xrlZqnrOLtiY77OHf6_ULoI9ODz_Jqsj0SH7xCBFExZ9ytmQHVpyBieMK5AidNAZV1HCxaX4Zotn-wC7EvCkmscNl9398sbPOapTTbk1gh1satU4yU4BnortFGJxTQH3UQNG6AV6OGJvrECYfyRd3Ju6DU60zYe_mgYn7BxN3q191_Y_8-C9TTaHqopYZNvmRV_npVPJDppu-q8uWiwrrkvenojse664UVVsUnPdHWWTUCC5KnotDXuRFXu2LvCpLLPu-RsRe5azkOEoye2Pextg7SzvTHOuyLDIjWzQ-HYYQaLW0HY5oAxOCiSsT4nWRhsL7zvU7GieTgtvGbxmdkYnqTZhAnY-xwy2bm9hz1y6DZyU35IP_niJQMNjcPtd102-7mT-OMFtm0_xGJwW9tPvOjUzcY9ntt5tmlxQT9_U6mLgnsL8CAAD__31fUDQ">