llvm / llvm/llvm-project

[LifetimeSafety] Support C compound literals

Open
#206,347 2 comments 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 fully model C compound literals yet.

Minimal repro:

```c
int *bad(void) {
int *p = &(int){12};
return p; // should warn
}
```

https://godbolt.org/z/6oPvfr9bn

In C, compound literal has automatic storage duration, so this should behave roughly like returning the address of an unnamed local variable.

Expected: warn that the returned pointer refers to storage that does not live long enough.

This should remain OK however:

```c
int ok(void) {
int *p = &(int){12};
*p = 100;
return *p;
}
```

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.