[LifetimeSafety] Support allocating/freeing functions annotated with `ownership_takes`/`ownership_returns`
Open
clang:temporal-safety
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
LifetimeSafety does not model allocating/freeing functions, only `new`/`delete` are handled. Calls with the ownership attributes are opaque, so use-after-free via custom allocators is not diagnosed.
```cpp
__attribute__((ownership_returns(malloc))) int *myalloc(void);
__attribute__((ownership_takes(malloc, 1))) void myfree(int *p);
int *bad() {
int *p = myalloc();
myfree(p);
*p = 1; // should warn
}
```
Expected: `myfree` invalidates the allocation like `delete`, producing `-Wlifetime-safety-use-after-free`.
https://godbolt.org/z/rGMha7Y67
Contributor guide
Assessment
This issue has not been assessed yet.