diff options
author | Kadir Cetinkaya <kadircet@google.com> | 2019-11-13 13:44:40 +0100 |
---|---|---|
committer | Kadir Cetinkaya <kadircet@google.com> | 2019-11-13 15:03:30 +0100 |
commit | 16bdcc809c72c639a2888b6b859dca88453e3c28 (patch) | |
tree | 40e196204baf74a7502833432105fce17f3b7f69 /clang/unittests/Tooling/ToolingTest.cpp | |
parent | 33e882d5ada0b42323be3277816b0817b8e6baa2 (diff) | |
download | bcm5719-llvm-16bdcc809c72c639a2888b6b859dca88453e3c28.tar.gz bcm5719-llvm-16bdcc809c72c639a2888b6b859dca88453e3c28.zip |
[clang][Tooling] Filter flags that generate output in SyntaxOnlyAdjuster
Summary:
Flags that generate output could result in failures when creating
syntax only actions. This patch introduces initial logic for filtering out
those. The first such flag is "save-temps", which saves intermediate
files(bitcode, assembly, etc.) into a specified directory.
Fixes https://github.com/clangd/clangd/issues/191
Reviewers: hokein
Subscribers: ilya-biryukov, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D70173
Diffstat (limited to 'clang/unittests/Tooling/ToolingTest.cpp')
-rw-r--r-- | clang/unittests/Tooling/ToolingTest.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/clang/unittests/Tooling/ToolingTest.cpp b/clang/unittests/Tooling/ToolingTest.cpp index c22d0bdca48..13581342fc1 100644 --- a/clang/unittests/Tooling/ToolingTest.cpp +++ b/clang/unittests/Tooling/ToolingTest.cpp @@ -13,15 +13,18 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendAction.h" #include "clang/Frontend/FrontendActions.h" +#include "clang/Tooling/ArgumentsAdjusters.h" #include "clang/Tooling/CompilationDatabase.h" #include "clang/Tooling/Tooling.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/Path.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include "gtest/gtest.h" #include <algorithm> #include <string> +#include <vector> namespace clang { namespace tooling { @@ -429,6 +432,37 @@ TEST(ClangToolTest, NoDoubleSyntaxOnly) { EXPECT_EQ(SyntaxOnlyCount, 1U); } +TEST(ClangToolTest, NoOutputCommands) { + FixedCompilationDatabase Compilations("/", {"-save-temps", "-save-temps=cwd", + "--save-temps", + "--save-temps=somedir"}); + + ClangTool Tool(Compilations, std::vector<std::string>(1, "/a.cc")); + Tool.mapVirtualFile("/a.cc", "void a() {}"); + + std::unique_ptr<FrontendActionFactory> Action( + newFrontendActionFactory<SyntaxOnlyAction>()); + + const std::vector<llvm::StringRef> OutputCommands = {"-save-temps"}; + bool Ran = false; + ArgumentsAdjuster CheckSyntaxOnlyAdjuster = + [&OutputCommands, &Ran](const CommandLineArguments &Args, + StringRef /*unused*/) { + for (llvm::StringRef Arg : Args) { + for (llvm::StringRef OutputCommand : OutputCommands) + EXPECT_FALSE(Arg.contains(OutputCommand)); + } + Ran = true; + return Args; + }; + + Tool.clearArgumentsAdjusters(); + Tool.appendArgumentsAdjuster(getClangSyntaxOnlyAdjuster()); + Tool.appendArgumentsAdjuster(CheckSyntaxOnlyAdjuster); + Tool.run(Action.get()); + EXPECT_TRUE(Ran); +} + TEST(ClangToolTest, BaseVirtualFileSystemUsage) { FixedCompilationDatabase Compilations("/", std::vector<std::string>()); llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem( |