[clang] [analyzer] Discard non-live source frames from the current stack (PR #213779)
Benedek Kaibas via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 5 04:49:09 PDT 2026
================
@@ -52,9 +52,15 @@ static bool isDanglingStackSource(const MemRegion *Source,
})) {
return false;
}
-
- if (SF == CurrentSF || !SF->isParentOf(CurrentSF))
- return true;
+ // Only a source whose frame is still live on the current stack can
+ // dangle. If that frame is not on the stack then the source outlives
+ // the returned value. The source is still alive when the returned value
+ // is used, so it does not dangle.
+ if (llvm::any_of(C.stackframes(),
+ [&](const StackFrame &Frame) { return &Frame == SF; }))
+
+ if (SF == CurrentSF || !SF->isParentOf(CurrentSF))
+ return true;
----------------
benedekaibas wrote:
Thank you for pointing to `is_contained` and `make_pointer_range`. I have checked in `iterator.h` how the `make_pointer_range` works and it indeed works well for this case. I have added it here: [ae0ea6c](https://github.com/llvm/llvm-project/pull/213779/commits/ae0ea6cd125c440162cd3089e63fbc640e54aafe)
Switching to this eliminated the nested if statements.
https://github.com/llvm/llvm-project/pull/213779
More information about the cfe-commits
mailing list