[Driver] Don't warn -Wunused-command-line-argument for --coverage -ftest-coverage...
authorFangrui Song <maskray@google.com>
Fri, 8 May 2020 23:14:41 +0000 (16:14 -0700)
committerFangrui Song <maskray@google.com>
Fri, 8 May 2020 23:31:15 +0000 (16:31 -0700)
clang/lib/Driver/ToolChain.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/coverage.c

index a6bc953..c8f6207 100644 (file)
@@ -512,9 +512,9 @@ bool ToolChain::needsProfileRT(const ArgList &Args) {
 }
 
 bool ToolChain::needsGCovInstrumentation(const llvm::opt::ArgList &Args) {
-  return Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs,
-                      false) ||
-         Args.hasArg(options::OPT_coverage);
+  return Args.hasArg(options::OPT_coverage) ||
+         Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs,
+                      false);
 }
 
 Tool *ToolChain::SelectTool(const JobAction &JA) const {
index 04c05a8..7d52d7f 100644 (file)
@@ -863,9 +863,7 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
 
   bool EmitCovNotes = Args.hasArg(options::OPT_ftest_coverage) ||
                       Args.hasArg(options::OPT_coverage);
-  bool EmitCovData = Args.hasFlag(options::OPT_fprofile_arcs,
-                                  options::OPT_fno_profile_arcs, false) ||
-                     Args.hasArg(options::OPT_coverage);
+  bool EmitCovData = TC.needsGCovInstrumentation(Args);
   if (EmitCovNotes)
     CmdArgs.push_back("-femit-coverage-notes");
   if (EmitCovData)
index 24e8ac9..4e1b49b 100644 (file)
@@ -12,6 +12,9 @@
 // GCNO-LOCATION: "-coverage-notes-file" "{{.*}}/foo/bar.gcno"
 // GCNO-LOCATION-REL: "-coverage-notes-file" "{{.*}}{{/|\\\\}}foo/bar.gcno"
 
+/// Don't warn -Wunused-command-line-argument.
+// RUN: %clang -E -Werror --coverage -ftest-coverage -fprofile-arcs %s
+
 /// Test -fprofile-dir=
 // RUN: not %clang -S -Werror -fprofile-dir=abc %s
 // RUN: not %clang -S -Werror -ftest-coverage -fprofile-dir=abc %s