From 25c4c993f385efc6477b2771bd12b4d70f8bcc2f Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Thu, 15 Dec 2022 10:49:44 -0800 Subject: [PATCH] [Refactoring] Fix stack-use-after-scope in ContextFinder Storing `llvm::function_ref` as a member field is not safe. Just use std::function instead. rdar://103369305 --- lib/Refactoring/Refactoring.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Refactoring/Refactoring.cpp b/lib/Refactoring/Refactoring.cpp index a6dcd39c94aae..e7b2f7ad3eced 100644 --- a/lib/Refactoring/Refactoring.cpp +++ b/lib/Refactoring/Refactoring.cpp @@ -49,7 +49,7 @@ class ContextFinder : public SourceEntityWalker { ASTContext &Ctx; SourceManager &SM; SourceRange Target; - function_ref IsContext; + std::function IsContext; SmallVector AllContexts; bool contains(ASTNode Enclosing) { auto Result = SM.rangeContains(Enclosing.getSourceRange(), Target); @@ -59,12 +59,12 @@ class ContextFinder : public SourceEntityWalker { } public: ContextFinder(SourceFile &SF, ASTNode TargetNode, - function_ref IsContext = + std::function IsContext = [](ASTNode N) { return true; }) : SF(SF), Ctx(SF.getASTContext()), SM(Ctx.SourceMgr), Target(TargetNode.getSourceRange()), IsContext(IsContext) {} ContextFinder(SourceFile &SF, SourceLoc TargetLoc, - function_ref IsContext = + std::function IsContext = [](ASTNode N) { return true; }) : SF(SF), Ctx(SF.getASTContext()), SM(Ctx.SourceMgr), Target(TargetLoc), IsContext(IsContext) {