[clang] 38a8cd7 - [LifetimeSafety] Fix use-after-scope from #198784 (#199455)
via cfe-commits
cfe-commits at lists.llvm.org
Sun May 24 16:14:50 PDT 2026
Author: Thurston Dang
Date: 2026-05-24T16:14:45-07:00
New Revision: 38a8cd7cf6a1c45919a8c272c151de0dcc32571c
URL: https://github.com/llvm/llvm-project/commit/38a8cd7cf6a1c45919a8c272c151de0dcc32571c
DIFF: https://github.com/llvm/llvm-project/commit/38a8cd7cf6a1c45919a8c272c151de0dcc32571c.diff
LOG: [LifetimeSafety] Fix use-after-scope from #198784 (#199455)
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.
AFAIK clang is built using C++17 [*], hence C++23 P2718R0's lifetime
extension in range-based for loops does not apply.
[*] "Unless otherwise documented, LLVM subprojects are written using
standard C++17 code"
(https://llvm.org/docs/CodingStandards.html#c-standard-versions)
Added:
Modified:
clang/lib/Analysis/LifetimeSafety/Checker.cpp
Removed:
################################################################################
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;
More information about the cfe-commits
mailing list