From: David Goldman Date: Tue, 15 Nov 2022 18:50:25 +0000 (-0800) Subject: Fix use of dangling stack allocated string in IncludeFixer X-Git-Tag: upstream/17.0.6~27452 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2d5c4b8f6e040eef33d4f49820868a81c4c9f1e9;p=platform%2Fupstream%2Fllvm.git 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 --- 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);