[clang] [LifetimeSafety] Add multi-block support to buildOriginFlowChain (PR #204592)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 26 05:11:29 PDT 2026


usx95 wrote:

This is mostly the right direction. There is still a major flow here: The BFS needs a visited state set otherwise this is **exponential** as it traverses all paths!

```cpp
void exponential_paths(bool c) {
  int *s = nullptr;
  {
    int tgt = 42; // expected-note {{local variable 'tgt' is destroyed here}}
    int *p = &tgt;
    if (c) {} else {}
    if (c) {} else {} // ... N times
    s = p; // expected-note {{local variable 'p' aliases the storage of local variable 'tgt'}}
  }
  int val = *s; // expected-warning {{local variable 'tgt' does not live long enough}} \
                // expected-note {{later used here}}
}
```
This is `O(2^N)` where `N` is the number of `if` blocks here.

We would need a state to avoid revisiting. I _think_ a `std::pair<const CFGBlock *, OriginID>` should work fine.

https://github.com/llvm/llvm-project/pull/204592


More information about the cfe-commits mailing list