From: Kadir Cetinkaya Date: Thu, 4 Jul 2019 12:24:17 +0000 (+0000) Subject: [clangd] Fix a lifetime bug in QueryDriver X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5bec85a34c27c8b49ca780b8cdb9b2140a96f8cc;p=platform%2Fupstream%2Fllvm.git [clangd] Fix a lifetime bug in QueryDriver llvm-svn: 365134 --- diff --git a/clang-tools-extra/clangd/QueryDriverDatabase.cpp b/clang-tools-extra/clangd/QueryDriverDatabase.cpp index c68596d..4a413c4 100644 --- a/clang-tools-extra/clangd/QueryDriverDatabase.cpp +++ b/clang-tools-extra/clangd/QueryDriverDatabase.cpp @@ -48,6 +48,7 @@ #include "llvm/Support/Regex.h" #include "llvm/Support/ScopedPrinter.h" #include +#include #include #include @@ -221,16 +222,19 @@ public: llvm::SmallString<128> Driver(Cmd->CommandLine.front()); llvm::sys::fs::make_absolute(Cmd->Directory, Driver); + llvm::StringRef Ext = llvm::sys::path::extension(File).trim('.'); + auto Key = std::make_pair(Driver.str(), Ext); - llvm::ArrayRef SystemIncludes; + std::vector SystemIncludes; { std::lock_guard Lock(Mu); - llvm::StringRef Ext = llvm::sys::path::extension(File).trim('.'); - auto It = DriverToIncludesCache.try_emplace({Driver, Ext}); - if (It.second) - It.first->second = extractSystemIncludes(Driver, Ext, QueryDriverRegex); - SystemIncludes = It.first->second; + auto It = DriverToIncludesCache.find(Key); + if (It != DriverToIncludesCache.end()) + SystemIncludes = It->second; + else + DriverToIncludesCache[Key] = SystemIncludes = + extractSystemIncludes(Key.first, Key.second, QueryDriverRegex); } return addSystemIncludes(*Cmd, SystemIncludes); @@ -239,8 +243,8 @@ public: private: mutable std::mutex Mu; // Caches includes extracted from a driver. - mutable llvm::DenseMap, - std::vector> + mutable std::map, + std::vector> DriverToIncludesCache; mutable llvm::Regex QueryDriverRegex;