[PATCH] D64489: [clangd][QueryDriver] Use language from underlying database if possible

Kadir Cetinkaya via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 11 06:49:45 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL365776: [clangd][QueryDriver] Use language from underlying database if possible (authored by kadircet, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64489?vs=208949&id=209209#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64489/new/

https://reviews.llvm.org/D64489

Files:
  clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp


Index: clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
@@ -83,11 +83,11 @@
 }
 
 std::vector<std::string> extractSystemIncludes(PathRef Driver,
-                                               llvm::StringRef Ext,
+                                               llvm::StringRef Lang,
                                                llvm::Regex &QueryDriverRegex) {
   trace::Span Tracer("Extract system includes");
   SPAN_ATTACH(Tracer, "driver", Driver);
-  SPAN_ATTACH(Tracer, "ext", Ext);
+  SPAN_ATTACH(Tracer, "lang", Lang);
 
   if (!QueryDriverRegex.match(Driver)) {
     vlog("System include extraction: not whitelisted driver {0}", Driver);
@@ -117,14 +117,8 @@
   llvm::Optional<llvm::StringRef> Redirects[] = {
       {""}, {""}, llvm::StringRef(StdErrPath)};
 
-  auto Type = driver::types::lookupTypeForExtension(Ext);
-  if (Type == driver::types::TY_INVALID) {
-    elog("System include extraction: invalid file type for {0}", Ext);
-    return {};
-  }
   // Should we also preserve flags like "-sysroot", "-nostdinc" ?
-  const llvm::StringRef Args[] = {
-      Driver, "-E", "-x", driver::types::getTypeName(Type), "-", "-v"};
+  const llvm::StringRef Args[] = {Driver, "-E", "-x", Lang, "-", "-v"};
 
   if (int RC = llvm::sys::ExecuteAndWait(Driver, Args, /*Env=*/llvm::None,
                                          Redirects)) {
@@ -220,10 +214,27 @@
     if (!Cmd || Cmd->CommandLine.empty())
       return Cmd;
 
+    llvm::StringRef Lang;
+    for (size_t I = 0, E = Cmd->CommandLine.size(); I < E; ++I) {
+      llvm::StringRef Arg = Cmd->CommandLine[I];
+      if (Arg == "-x" && I + 1 < E)
+        Lang = Cmd->CommandLine[I + 1];
+      else if (Arg.startswith("-x"))
+        Lang = Arg.drop_front(2).trim();
+    }
+    if (Lang.empty()) {
+      llvm::StringRef Ext = llvm::sys::path::extension(File).trim('.');
+      auto Type = driver::types::lookupTypeForExtension(Ext);
+      if (Type == driver::types::TY_INVALID) {
+        elog("System include extraction: invalid file type for {0}", Ext);
+        return {};
+      }
+      Lang = driver::types::getTypeName(Type);
+    }
+
     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);
+    auto Key = std::make_pair(Driver.str(), Lang);
 
     std::vector<std::string> SystemIncludes;
     {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64489.209209.patch
Type: text/x-patch
Size: 2661 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190711/5e29403c/attachment.bin>


More information about the llvm-commits mailing list