[PATCH] D56841: [clangd] Filter out plugin related flags.
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 17 05:42:54 PST 2019
kadircet updated this revision to Diff 182260.
kadircet marked an inline comment as done.
kadircet added a comment.
- Address comments
Repository:
rCTE Clang Tools Extra
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D56841/new/
https://reviews.llvm.org/D56841
Files:
clangd/ClangdUnit.cpp
unittests/clangd/ClangdTests.cpp
Index: unittests/clangd/ClangdTests.cpp
===================================================================
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -1037,6 +1037,27 @@
}
#endif
+TEST_F(ClangdVFSTest, FlagsWithPlugins) {
+ MockFSProvider FS;
+ ErrorCheckingDiagConsumer DiagConsumer;
+ MockCompilationDatabase CDB;
+ CDB.ExtraClangFlags = {
+ "-Xclang",
+ "-add-plugin",
+ "-Xclang",
+ "random-plugin",
+ };
+ ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
+
+ auto FooCpp = testPath("foo.cpp");
+ const auto SourceContents = "int main() { return 0; }";
+ FS.Files[FooCpp] = FooCpp;
+ Server.addDocument(FooCpp, SourceContents);
+ auto Result = dumpASTWithoutMemoryLocs(Server, FooCpp);
+ EXPECT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for diagnostics";
+ EXPECT_NE(Result, "<no-ast>");
+}
+
} // namespace
} // namespace clangd
} // namespace clang
Index: clangd/ClangdUnit.cpp
===================================================================
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -425,8 +425,24 @@
std::unique_ptr<CompilerInvocation>
buildCompilerInvocation(const ParseInputs &Inputs) {
std::vector<const char *> ArgStrs;
- for (const auto &S : Inputs.CompileCommand.CommandLine)
- ArgStrs.push_back(S.c_str());
+ const auto &CommandLine = Inputs.CompileCommand.CommandLine;
+ for (size_t I = 0, E = CommandLine.size(); I != E; I++) {
+ // Skip plugin related command line arguments. Clangd does not support
+ // plugins currently. Therefore it breaks if compiler tries to load plugins.
+ // According to https://clang.llvm.org/docs/ClangPlugins.html plugin
+ // arguments are in the form:
+ // -Xclang {-load, -plugin, -plugin-arg-<plugin-name>, -add-plugin} -Xclang
+ // <arbitrary-argument>
+ if (I + 4 < E && CommandLine[I] == "-Xclang" &&
+ (CommandLine[I + 1] == "-load" || CommandLine[I + 1] == "-plugin" ||
+ llvm::StringRef(CommandLine[I + 1]).startswith("-plugin-arg-") ||
+ CommandLine[I + 1] == "-add-plugin") &&
+ CommandLine[I + 2] == "-Xclang") {
+ I += 3;
+ continue;
+ }
+ ArgStrs.push_back(CommandLine[I].c_str());
+ }
if (Inputs.FS->setCurrentWorkingDirectory(Inputs.CompileCommand.Directory)) {
log("Couldn't set working directory when creating compiler invocation.");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56841.182260.patch
Type: text/x-patch
Size: 2411 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190117/a4f9febe/attachment-0001.bin>
More information about the cfe-commits
mailing list