[libFuzzer] make the fork mode less verbose

git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/fuzzer@353794 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/FuzzerMerge.cpp b/FuzzerMerge.cpp
index c61169a..9a86512 100644
--- a/FuzzerMerge.cpp
+++ b/FuzzerMerge.cpp
@@ -255,42 +255,43 @@
 
 // Outer process. Does not call the target code and thus should not fail.
 void CrashResistantMerge(const Vector<std::string> &Args,
-                    const Vector<SizedFile> &OldCorpus,
-                    const Vector<SizedFile> &NewCorpus,
-                    Vector<std::string> *NewFiles,
-                    const Set<uint32_t> &InitialFeatures,
-                    Set<uint32_t> *NewFeatures,
-                    const std::string &CFPath) {
+                         const Vector<SizedFile> &OldCorpus,
+                         const Vector<SizedFile> &NewCorpus,
+                         Vector<std::string> *NewFiles,
+                         const Set<uint32_t> &InitialFeatures,
+                         Set<uint32_t> *NewFeatures, const std::string &CFPath,
+                         bool V /*Verbose*/) {
   size_t NumAttempts = 0;
   if (FileSize(CFPath)) {
-    Printf("MERGE-OUTER: non-empty control file provided: '%s'\n",
+    VPrintf(V, "MERGE-OUTER: non-empty control file provided: '%s'\n",
            CFPath.c_str());
     Merger M;
     std::ifstream IF(CFPath);
     if (M.Parse(IF, /*ParseCoverage=*/false)) {
-      Printf("MERGE-OUTER: control file ok, %zd files total,"
+      VPrintf(V, "MERGE-OUTER: control file ok, %zd files total,"
              " first not processed file %zd\n",
              M.Files.size(), M.FirstNotProcessedFile);
       if (!M.LastFailure.empty())
-        Printf("MERGE-OUTER: '%s' will be skipped as unlucky "
+        VPrintf(V, "MERGE-OUTER: '%s' will be skipped as unlucky "
                "(merge has stumbled on it the last time)\n",
                M.LastFailure.c_str());
       if (M.FirstNotProcessedFile >= M.Files.size()) {
-        Printf("MERGE-OUTER: nothing to do, merge has been completed before\n");
+        VPrintf(
+            V, "MERGE-OUTER: nothing to do, merge has been completed before\n");
         exit(0);
       }
 
       NumAttempts = M.Files.size() - M.FirstNotProcessedFile;
     } else {
-      Printf("MERGE-OUTER: bad control file, will overwrite it\n");
+      VPrintf(V, "MERGE-OUTER: bad control file, will overwrite it\n");
     }
   }
 
   if (!NumAttempts) {
     // The supplied control file is empty or bad, create a fresh one.
     NumAttempts = OldCorpus.size() + NewCorpus.size();
-    Printf("MERGE-OUTER: %zd files, %zd in the initial corpus\n", NumAttempts,
-           OldCorpus.size());
+    VPrintf(V, "MERGE-OUTER: %zd files, %zd in the initial corpus\n",
+            NumAttempts, OldCorpus.size());
     WriteNewControlFile(CFPath, OldCorpus, NewCorpus);
   }
 
@@ -301,13 +302,17 @@
   BaseCmd.removeFlag("fork");
   for (size_t Attempt = 1; Attempt <= NumAttempts; Attempt++) {
     Fuzzer::MaybeExitGracefully();
-    Printf("MERGE-OUTER: attempt %zd\n", Attempt);
+    VPrintf(V, "MERGE-OUTER: attempt %zd\n", Attempt);
     Command Cmd(BaseCmd);
     Cmd.addFlag("merge_control_file", CFPath);
     Cmd.addFlag("merge_inner", "1");
+    if (!V) {
+      Cmd.setOutputFile("/dev/null");  // TODO: need to handle this on Windows?
+      Cmd.combineOutAndErr();
+    }
     auto ExitCode = ExecuteCommand(Cmd);
     if (!ExitCode) {
-      Printf("MERGE-OUTER: succesfull in %zd attempt(s)\n", Attempt);
+      VPrintf(V, "MERGE-OUTER: succesfull in %zd attempt(s)\n", Attempt);
       break;
     }
   }
@@ -315,14 +320,16 @@
   Merger M;
   std::ifstream IF(CFPath);
   IF.seekg(0, IF.end);
-  Printf("MERGE-OUTER: the control file has %zd bytes\n", (size_t)IF.tellg());
+  VPrintf(V, "MERGE-OUTER: the control file has %zd bytes\n",
+          (size_t)IF.tellg());
   IF.seekg(0, IF.beg);
   M.ParseOrExit(IF, true);
   IF.close();
-  Printf("MERGE-OUTER: consumed %zdMb (%zdMb rss) to parse the control file\n",
-         M.ApproximateMemoryConsumption() >> 20, GetPeakRSSMb());
+  VPrintf(V,
+          "MERGE-OUTER: consumed %zdMb (%zdMb rss) to parse the control file\n",
+          M.ApproximateMemoryConsumption() >> 20, GetPeakRSSMb());
   size_t NumNewFeatures = M.Merge(InitialFeatures, NewFeatures, NewFiles);
-  Printf("MERGE-OUTER: %zd new files with %zd new features added\n",
+  VPrintf(V, "MERGE-OUTER: %zd new files with %zd new features added\n",
          NewFiles->size(), NumNewFeatures);
 }