Skip to content

Commit

Permalink
[clang][ArgumentAdjusters] Do not add fsyntax-only if already exists
Browse files Browse the repository at this point in the history
Reviewers: hokein

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64063

llvm-svn: 364904
  • Loading branch information
kadircet committed Jul 2, 2019
1 parent 2915b39 commit 7d719b7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion clang/lib/Tooling/ArgumentsAdjusters.cpp
Expand Up @@ -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;
};
}
Expand Down
27 changes: 27 additions & 0 deletions clang/unittests/Tooling/ToolingTest.cpp
Expand Up @@ -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(
Expand Down

0 comments on commit 7d719b7

Please sign in to comment.