diff options
| -rw-r--r-- | clang/lib/Tooling/ArgumentsAdjusters.cpp | 6 | ||||
| -rw-r--r-- | clang/unittests/Tooling/ToolingTest.cpp | 27 |
2 files changed, 32 insertions, 1 deletions
diff --git a/clang/lib/Tooling/ArgumentsAdjusters.cpp b/clang/lib/Tooling/ArgumentsAdjusters.cpp index 002c587d6bb..942b35df453 100644 --- a/clang/lib/Tooling/ArgumentsAdjusters.cpp +++ b/clang/lib/Tooling/ArgumentsAdjusters.cpp @@ -23,14 +23,18 @@ namespace tooling { 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; }; } diff --git a/clang/unittests/Tooling/ToolingTest.cpp b/clang/unittests/Tooling/ToolingTest.cpp index 34f68a6aeb6..f9f4de3d9a1 100644 --- a/clang/unittests/Tooling/ToolingTest.cpp +++ b/clang/unittests/Tooling/ToolingTest.cpp @@ -400,6 +400,33 @@ TEST(ClangToolTest, ArgumentAdjusters) { 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( |

