Author: David Goldman Date: 2022-11-16T11:09:06-08:00 New Revision: 2d5c4b8f6e040eef33d4f49820868a81c4c9f1e9
URL: https://github.com/llvm/llvm-project/commit/2d5c4b8f6e040eef33d4f49820868a81c4c9f1e9 DIFF: https://github.com/llvm/llvm-project/commit/2d5c4b8f6e040eef33d4f49820868a81c4c9f1e9.diff LOG: 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 Added: Modified: clang-tools-extra/clangd/ParsedAST.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/ParsedAST.cpp b/clang-tools-extra/clangd/ParsedAST.cpp index 50923c862c583..870a22cd7b1ef 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<std::unique_ptr<tidy::ClangTidyCheck>> CTChecks; ast_matchers::MatchFinder CTFinder; llvm::Optional<tidy::ClangTidyContext> CTContext; + // Must outlive FixIncludes. + auto BuildDir = VFS->getCurrentWorkingDirectory(); llvm::Optional<IncludeFixer> FixIncludes; llvm::DenseMap<diag::kind, DiagnosticsEngine::Level> 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); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits