llvm / llvm/llvm-project

[LifetimeSafety] False negative on assignment from Owner to Pointer

Open
#198,605 3 comments 0 reactions 0 assignees View on GitHub
clang:temporal-safety
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The analysis misses this GSL Pointer assignment case:
```cpp
struct [[gsl::Owner]] Owner {
Owner();
};
struct [[gsl::Pointer]] View {
View();
View &operator=(const Owner &o [[clang::lifetimebound]]);
void use() const;
};
void f() {
View v;
{
Owner o;
v = o;
} // o is destroyed here!
v.use(); // no warning
}
```
Expected: warn that o does not live long enough.

https://godbolt.org/z/EMT4WWrnc

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the GSL Owner-to-Pointer assignment example in the linked Godbolt case and inspect Clang's LifetimeSafety analysis for lifetimebound assignment handling. The work is done when this case diagnoses that o does not live long enough before v.use(), while the analysis remains correct for related assignments.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.