[LifetimeSafety] Fix use-after-scope from #198784#199455
Conversation
This fixes a use-after-scope introduced by llvm#198784 (reported in llvm#198784 (comment)), 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.
|
cc @NeKon69 |
|
@llvm/pr-subscribers-clang-temporal-safety @llvm/pr-subscribers-clang Author: Thurston Dang (thurstond) ChangesThis fixes a use-after-scope introduced by #198784 (reported in #198784 (comment)), 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:
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;
|
|
@llvm/pr-subscribers-clang-analysis Author: Thurston Dang (thurstond) ChangesThis fixes a use-after-scope introduced by #198784 (reported in #198784 (comment)), 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:
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;
|
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/143/builds/15407 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/127/builds/7379 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/4/builds/12240 Here is the relevant piece of the build log for the reference |
|
Thanks you so much! Sorry I couldn't fix this myself. |
This fixes a use-after-scope introduced by #198784 (reported in #198784 (comment)), 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)