From 2d5c4b8f6e040eef33d4f49820868a81c4c9f1e9 Mon Sep 17 00:00:00 2001 From: David Goldman Date: Tue, 15 Nov 2022 10:50:25 -0800 Subject: [PATCH] Fix use of dangling stack allocated string in IncludeFixer IncludeFixer uses this BuildDir string later on if given relative paths. Differential Revision: https://reviews.llvm.org/D138047 --- clang-tools-extra/clangd/ParsedAST.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/ParsedAST.cpp b/clang-tools-extra/clangd/ParsedAST.cpp index 50923c8..870a22c 100644 --- a/clang-tools-extra/clangd/ParsedAST.cpp +++ b/clang-tools-extra/clangd/ParsedAST.cpp @@ -465,6 +465,8 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs, std::vector> CTChecks; ast_matchers::MatchFinder CTFinder; llvm::Optional CTContext; + // Must outlive FixIncludes. + auto BuildDir = VFS->getCurrentWorkingDirectory(); llvm::Optional FixIncludes; llvm::DenseMap OverriddenSeverity; // No need to run clang-tidy or IncludeFixerif we are not going to surface @@ -551,7 +553,6 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs, // Add IncludeFixer which can recover diagnostics caused by missing includes // (e.g. incomplete type) and attach include insertion fixes to diagnostics. - auto BuildDir = VFS->getCurrentWorkingDirectory(); if (Inputs.Index && !BuildDir.getError()) { auto Style = getFormatStyleForFile(Filename, Inputs.Contents, *Inputs.TFS); -- 2.7.4