[PATCH] D64063: [clang][ArgumentAdjusters] Do not add fsyntax-only if already exists

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 2 03:45:49 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL364904: [clang][ArgumentAdjusters] Do not add fsyntax-only if already exists (authored by kadircet, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64063?vs=207491&id=207507#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64063

Files:
  cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
  cfe/trunk/unittests/Tooling/ToolingTest.cpp


Index: cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
===================================================================
--- cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
+++ cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
@@ -23,14 +23,18 @@
 ArgumentsAdjuster getClangSyntaxOnlyAdjuster() {
   return [](const CommandLineArguments &Args, StringRef /*unused*/) {
     CommandLineArguments AdjustedArgs;
+    bool HasSyntaxOnly = false;
     for (size_t i = 0, e = Args.size(); i < e; ++i) {
       StringRef Arg = Args[i];
       // FIXME: Remove options that generate output.
       if (!Arg.startswith("-fcolor-diagnostics") &&
           !Arg.startswith("-fdiagnostics-color"))
         AdjustedArgs.push_back(Args[i]);
+      if (Arg == "-fsyntax-only")
+        HasSyntaxOnly = true;
     }
-    AdjustedArgs.push_back("-fsyntax-only");
+    if (!HasSyntaxOnly)
+      AdjustedArgs.push_back("-fsyntax-only");
     return AdjustedArgs;
   };
 }
Index: cfe/trunk/unittests/Tooling/ToolingTest.cpp
===================================================================
--- cfe/trunk/unittests/Tooling/ToolingTest.cpp
+++ cfe/trunk/unittests/Tooling/ToolingTest.cpp
@@ -400,6 +400,33 @@
   EXPECT_FALSE(Found);
 }
 
+TEST(ClangToolTest, NoDoubleSyntaxOnly) {
+  FixedCompilationDatabase Compilations("/", {"-fsyntax-only"});
+
+  ClangTool Tool(Compilations, std::vector<std::string>(1, "/a.cc"));
+  Tool.mapVirtualFile("/a.cc", "void a() {}");
+
+  std::unique_ptr<FrontendActionFactory> Action(
+      newFrontendActionFactory<SyntaxOnlyAction>());
+
+  size_t SyntaxOnlyCount = 0;
+  ArgumentsAdjuster CheckSyntaxOnlyAdjuster =
+      [&SyntaxOnlyCount](const CommandLineArguments &Args,
+                         StringRef /*unused*/) {
+        for (llvm::StringRef Arg : Args) {
+          if (Arg == "-fsyntax-only")
+            ++SyntaxOnlyCount;
+        }
+        return Args;
+      };
+
+  Tool.clearArgumentsAdjusters();
+  Tool.appendArgumentsAdjuster(getClangSyntaxOnlyAdjuster());
+  Tool.appendArgumentsAdjuster(CheckSyntaxOnlyAdjuster);
+  Tool.run(Action.get());
+  EXPECT_EQ(SyntaxOnlyCount, 1U);
+}
+
 TEST(ClangToolTest, BaseVirtualFileSystemUsage) {
   FixedCompilationDatabase Compilations("/", std::vector<std::string>());
   llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64063.207507.patch
Type: text/x-patch
Size: 2323 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190702/70027eb4/attachment.bin>


More information about the cfe-commits mailing list