[PATCH] D40024: Fix skipping of flags in getClangStripDependencyFileAdjuster
Dave Lee via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 17 08:28:11 PST 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318529: Fix skipping of flags in getClangStripDependencyFileAdjuster (authored by kastiglione).
Repository:
rL LLVM
https://reviews.llvm.org/D40024
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
@@ -58,14 +58,14 @@
StringRef Arg = Args[i];
// All dependency-file options begin with -M. These include -MM,
// -MF, -MG, -MP, -MT, -MQ, -MD, and -MMD.
- if (!Arg.startswith("-M"))
+ if (!Arg.startswith("-M")) {
AdjustedArgs.push_back(Args[i]);
+ continue;
+ }
- if ((Arg == "-MF") || (Arg == "-MT") || (Arg == "-MQ") ||
- (Arg == "-MD") || (Arg == "-MMD")) {
- // Output is specified as -MX foo. Skip the next argument also.
+ if (Arg == "-MF" || Arg == "-MT" || Arg == "-MQ")
+ // These flags take an argument: -MX foo. Skip the next argument also.
++i;
- }
}
return AdjustedArgs;
};
Index: cfe/trunk/unittests/Tooling/ToolingTest.cpp
===================================================================
--- cfe/trunk/unittests/Tooling/ToolingTest.cpp
+++ cfe/trunk/unittests/Tooling/ToolingTest.cpp
@@ -402,6 +402,37 @@
EXPECT_FALSE(Found);
}
+// Check getClangStripDependencyFileAdjuster doesn't strip args after -MD/-MMD.
+TEST(ClangToolTest, StripDependencyFileAdjuster) {
+ FixedCompilationDatabase Compilations("/", {"-MD", "-c", "-MMD", "-w"});
+
+ ClangTool Tool(Compilations, std::vector<std::string>(1, "/a.cc"));
+ Tool.mapVirtualFile("/a.cc", "void a() {}");
+
+ std::unique_ptr<FrontendActionFactory> Action(
+ newFrontendActionFactory<SyntaxOnlyAction>());
+
+ CommandLineArguments FinalArgs;
+ ArgumentsAdjuster CheckFlagsAdjuster =
+ [&FinalArgs](const CommandLineArguments &Args, StringRef /*unused*/) {
+ FinalArgs = Args;
+ return Args;
+ };
+ Tool.clearArgumentsAdjusters();
+ Tool.appendArgumentsAdjuster(getClangStripDependencyFileAdjuster());
+ Tool.appendArgumentsAdjuster(CheckFlagsAdjuster);
+ Tool.run(Action.get());
+
+ auto HasFlag = [&FinalArgs](const std::string &Flag) {
+ return std::find(FinalArgs.begin(), FinalArgs.end(), Flag) !=
+ FinalArgs.end();
+ };
+ EXPECT_FALSE(HasFlag("-MD"));
+ EXPECT_FALSE(HasFlag("-MMD"));
+ EXPECT_TRUE(HasFlag("-c"));
+ EXPECT_TRUE(HasFlag("-w"));
+}
+
namespace {
/// Find a target name such that looking for it in TargetRegistry by that name
/// returns the same target. We expect that there is at least one target
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40024.123350.patch
Type: text/x-patch
Size: 2478 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171117/d1bc6160/attachment.bin>
More information about the cfe-commits
mailing list