llvm / llvm/llvm-project

[LifetimeSafety] Support allocating/freeing functions annotated with `ownership_takes`/`ownership_returns`

Open
#213,435 1 comment 0 reactions 1 assignee Claimed by @NeKon69 View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.