[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
This commit is contained in:
Rintaro Ishizaki
2022-12-15 10:49:44 -08:00
parent 10d131d386
commit 25c4c993f3

View File

@@ -49,7 +49,7 @@ class ContextFinder : public SourceEntityWalker {
ASTContext &Ctx;
SourceManager &SM;
SourceRange Target;
function_ref<bool(ASTNode)> IsContext;
std::function<bool(ASTNode)> IsContext;
SmallVector<ASTNode, 4> 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<bool(ASTNode)> IsContext =
std::function<bool(ASTNode)> 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<bool(ASTNode)> IsContext =
std::function<bool(ASTNode)> IsContext =
[](ASTNode N) { return true; }) :
SF(SF), Ctx(SF.getASTContext()), SM(Ctx.SourceMgr),
Target(TargetLoc), IsContext(IsContext) {