[PATCH] D126274: [clangd] Handle '--' in QueryDriverDatabase

2022-05-24 Thread Nathan Ridge via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG175833ed6f62: [clangd] Handle '--' in 
QueryDriverDatabase (authored by nridge).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126274

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


Index: clang-tools-extra/clangd/QueryDriverDatabase.cpp
===
--- clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -50,6 +50,7 @@
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -238,10 +239,17 @@
 tooling::CompileCommand &
 addSystemIncludes(tooling::CompileCommand &Cmd,
   llvm::ArrayRef SystemIncludes) {
+  std::vector ToAppend;
   for (llvm::StringRef Include : SystemIncludes) {
 // FIXME(kadircet): This doesn't work when we have "--driver-mode=cl"
-Cmd.CommandLine.push_back("-isystem");
-Cmd.CommandLine.push_back(Include.str());
+ToAppend.push_back("-isystem");
+ToAppend.push_back(Include.str());
+  }
+  if (!ToAppend.empty()) {
+// Just append when `--` isn't present.
+auto InsertAt = llvm::find(Cmd.CommandLine, "--");
+Cmd.CommandLine.insert(InsertAt, std::make_move_iterator(ToAppend.begin()),
+   std::make_move_iterator(ToAppend.end()));
   }
   return Cmd;
 }
@@ -254,7 +262,9 @@
   if (Arg == "-target" || Arg.startswith("--target="))
 return Cmd;
 }
-Cmd.CommandLine.push_back("--target=" + Target);
+// Just append when `--` isn't present.
+auto InsertAt = llvm::find(Cmd.CommandLine, "--");
+Cmd.CommandLine.insert(InsertAt, "--target=" + Target);
   }
   return Cmd;
 }


Index: clang-tools-extra/clangd/QueryDriverDatabase.cpp
===
--- clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -50,6 +50,7 @@
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -238,10 +239,17 @@
 tooling::CompileCommand &
 addSystemIncludes(tooling::CompileCommand &Cmd,
   llvm::ArrayRef SystemIncludes) {
+  std::vector ToAppend;
   for (llvm::StringRef Include : SystemIncludes) {
 // FIXME(kadircet): This doesn't work when we have "--driver-mode=cl"
-Cmd.CommandLine.push_back("-isystem");
-Cmd.CommandLine.push_back(Include.str());
+ToAppend.push_back("-isystem");
+ToAppend.push_back(Include.str());
+  }
+  if (!ToAppend.empty()) {
+// Just append when `--` isn't present.
+auto InsertAt = llvm::find(Cmd.CommandLine, "--");
+Cmd.CommandLine.insert(InsertAt, std::make_move_iterator(ToAppend.begin()),
+   std::make_move_iterator(ToAppend.end()));
   }
   return Cmd;
 }
@@ -254,7 +262,9 @@
   if (Arg == "-target" || Arg.startswith("--target="))
 return Cmd;
 }
-Cmd.CommandLine.push_back("--target=" + Target);
+// Just append when `--` isn't present.
+auto InsertAt = llvm::find(Cmd.CommandLine, "--");
+Cmd.CommandLine.insert(InsertAt, "--target=" + Target);
   }
   return Cmd;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126274: [clangd] Handle '--' in QueryDriverDatabase

2022-05-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Thanks so much for tracking this down!
The number of times we've had this bug :-( I wish we were using something a 
little more structured than array-of-strings.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126274

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126274: [clangd] Handle '--' in QueryDriverDatabase

2022-05-23 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
nridge added reviewers: sammccall, kadircet.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
nridge requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Fixes https://github.com/clangd/clangd/issues/1100,
a regression from D116721 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126274

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


Index: clang-tools-extra/clangd/QueryDriverDatabase.cpp
===
--- clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -50,6 +50,7 @@
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -238,10 +239,17 @@
 tooling::CompileCommand &
 addSystemIncludes(tooling::CompileCommand &Cmd,
   llvm::ArrayRef SystemIncludes) {
+  std::vector ToAppend;
   for (llvm::StringRef Include : SystemIncludes) {
 // FIXME(kadircet): This doesn't work when we have "--driver-mode=cl"
-Cmd.CommandLine.push_back("-isystem");
-Cmd.CommandLine.push_back(Include.str());
+ToAppend.push_back("-isystem");
+ToAppend.push_back(Include.str());
+  }
+  if (!ToAppend.empty()) {
+// Just append when `--` isn't present.
+auto InsertAt = llvm::find(Cmd.CommandLine, "--");
+Cmd.CommandLine.insert(InsertAt, std::make_move_iterator(ToAppend.begin()),
+   std::make_move_iterator(ToAppend.end()));
   }
   return Cmd;
 }
@@ -254,7 +262,9 @@
   if (Arg == "-target" || Arg.startswith("--target="))
 return Cmd;
 }
-Cmd.CommandLine.push_back("--target=" + Target);
+// Just append when `--` isn't present.
+auto InsertAt = llvm::find(Cmd.CommandLine, "--");
+Cmd.CommandLine.insert(InsertAt, "--target=" + Target);
   }
   return Cmd;
 }


Index: clang-tools-extra/clangd/QueryDriverDatabase.cpp
===
--- clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -50,6 +50,7 @@
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -238,10 +239,17 @@
 tooling::CompileCommand &
 addSystemIncludes(tooling::CompileCommand &Cmd,
   llvm::ArrayRef SystemIncludes) {
+  std::vector ToAppend;
   for (llvm::StringRef Include : SystemIncludes) {
 // FIXME(kadircet): This doesn't work when we have "--driver-mode=cl"
-Cmd.CommandLine.push_back("-isystem");
-Cmd.CommandLine.push_back(Include.str());
+ToAppend.push_back("-isystem");
+ToAppend.push_back(Include.str());
+  }
+  if (!ToAppend.empty()) {
+// Just append when `--` isn't present.
+auto InsertAt = llvm::find(Cmd.CommandLine, "--");
+Cmd.CommandLine.insert(InsertAt, std::make_move_iterator(ToAppend.begin()),
+   std::make_move_iterator(ToAppend.end()));
   }
   return Cmd;
 }
@@ -254,7 +262,9 @@
   if (Arg == "-target" || Arg.startswith("--target="))
 return Cmd;
 }
-Cmd.CommandLine.push_back("--target=" + Target);
+// Just append when `--` isn't present.
+auto InsertAt = llvm::find(Cmd.CommandLine, "--");
+Cmd.CommandLine.insert(InsertAt, "--target=" + Target);
   }
   return Cmd;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits