[LifetimeSafety] Detect use-after-scope in infinite loops
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
https://godbolt.org/z/foa4qnh6G
```cpp
#include
#include
void foo(bool cond) {
while (true) {
int* ptr;
if (cond) {
std::unique_ptr local;
ptr = local.get();
}
std::cout << *ptr;
}
}
```
Switching the `while(true)` to `while(cond)` makes it work. https://godbolt.org/z/rsf6r3s1b
Adding a return also works: https://godbolt.org/z/jfThq9vxG
Likely to do something with the CFG.
Contributor guide
Research direction
Start with the two Godbolt reproductions and inspect the LifetimeSafety analysis around the CFG for the while(true) loop. Compare its handling with while(cond) and the version containing a return. Done means the infinite-loop example is diagnosed as use-after-scope without regressing the cases that already work.
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
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 64/100