[clang] Diagnose misuse of the cleanup attribute (PR #80040)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 6 08:15:33 PST 2024


erichkeane wrote:

> ```
> extern void free(void *);
> extern void *malloc(size_t size);
> void t8(void) {
>   void *p __attribute__((cleanup(free))) = malloc(10); // expected-warning{{attempt to call free on non-heap object 'p'}}
> }
> ```
> 
> I added this, but I am getting this error: (Sorry if its a silly doubt)
> 
> ```
> error: 'expected-warning' diagnostics expected but not seen: 
>   File /home/happy/LLVM/llvm-project/clang/test/Sema/attr-cleanup.c Line 55: attempt to call free on non-heap object 'p'
> error: 'expected-warning' diagnostics seen but not expected: 
>   (frontend): attempt to call free on non-heap object 'p'
> 2 errors generated.
> ```

That looks like you got the source-location wrong on your diagnostic.

https://github.com/llvm/llvm-project/pull/80040


More information about the cfe-commits mailing list