[clang] [LifetimeSafety] Fix use-after-scope from #198784 (PR #199455)
via cfe-commits
cfe-commits at lists.llvm.org
Sun May 24 15:29:26 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Thurston Dang (thurstond)
<details>
<summary>Changes</summary>
This fixes a use-after-scope introduced by #<!-- -->198784 (reported in https://github.com/llvm/llvm-project/pull/198784#issuecomment-4530043621), by manually extending the lifetime.
Note that clang is built using C++17, hence C++23 P2718R0's lifetime extension in range-based for loops does not apply.
---
Full diff: https://github.com/llvm/llvm-project/pull/199455.diff
1 Files Affected:
- (modified) clang/lib/Analysis/LifetimeSafety/Checker.cpp (+5-2)
``````````diff
diff --git a/clang/lib/Analysis/LifetimeSafety/Checker.cpp b/clang/lib/Analysis/LifetimeSafety/Checker.cpp
index 53899251b9643..7eb948373152b 100644
--- a/clang/lib/Analysis/LifetimeSafety/Checker.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/Checker.cpp
@@ -356,8 +356,11 @@ class LifetimeChecker {
// We iterate in reverse order (from most recent to oldest) to find
// the first declaration in each file.
- for (const FunctionDecl *Redecl :
- llvm::reverse(llvm::to_vector(FDef->redecls())))
+
+ // Store in temporary variable to manually extend lifetime
+ auto redecls = llvm::to_vector(FDef->redecls());
+
+ for (const FunctionDecl *Redecl : llvm::reverse(redecls))
AddCrossTUDecl(Redecl);
return Targets;
``````````
</details>
https://github.com/llvm/llvm-project/pull/199455
More information about the cfe-commits
mailing list