================
@@ -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;
----------------
isuckatcs wrote:

Are these `if` statements supposed to be nested? If so you could try to merge 
the conditions, or surround the outer if with `{}` to make it more reabable.

https://github.com/llvm/llvm-project/pull/213779
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to