Suppress warnings on our second compilation (for 64-bit).

Bug: 16031597
Bug: 17052573

Without this patch the 64-bit compilation path will print duplicate warning
diagnostics, since we call the frontend twice (for 32-bit, and then 64-bit).
The simplest fix is to not print warnings for the second compilation. A bug
(17052573) has been filed to track fixing this a better way (actually printing
out all warning diagnostics, but removing duplicates explicitly).

Change-Id: I78ac0ebd2b132713ec0c86c2cf234da2b620eecf
diff --git a/llvm-rs-cc.cpp b/llvm-rs-cc.cpp
index 72db214..0b42894 100644
--- a/llvm-rs-cc.cpp
+++ b/llvm-rs-cc.cpp
@@ -142,12 +142,14 @@
     std::set<std::string> *SavedStrings) {
   NamePairList DepFiles;
   std::string PathSuffix = "";
+  bool CompileSecondTimeFor64Bit = false;
 
   // In our mixed 32/64-bit path, we need to suffix our files differently for
   // both 32-bit and 64-bit versions.
   if (Opts.mEmit3264) {
     if (Opts.mBitWidth == 64) {
       PathSuffix = "bc64";
+      CompileSecondTimeFor64Bit = true;
     } else {
       PathSuffix = "bc32";
     }
@@ -182,7 +184,8 @@
   std::unique_ptr<slang::SlangRS> Compiler(new slang::SlangRS());
   Compiler->init(Opts.mBitWidth, DiagEngine, DiagClient);
   int CompileFailed = !Compiler->compile(*IOFiles, *IOFiles32, DepFiles, Opts);
-  Compiler->reset();
+  // We suppress warnings (via reset) if we are doing a second compilation.
+  Compiler->reset(CompileSecondTimeFor64Bit);
   return CompileFailed;
 }
 
diff --git a/slang.cpp b/slang.cpp
index 7810695..c3ab7e6 100644
--- a/slang.cpp
+++ b/slang.cpp
@@ -470,8 +470,17 @@
   CodeGenOpts.OptimizationLevel = OptimizationLevel;
 }
 
-void Slang::reset() {
-  llvm::errs() << mDiagClient->str();
+void Slang::reset(bool SuppressWarnings) {
+  // Always print diagnostics if we had an error occur, but don't print
+  // warnings if we suppressed them (i.e. we are doing the 64-bit compile after
+  // an existing 32-bit compile).
+  //
+  // TODO: This should really be removing duplicate identical warnings between
+  // the 32-bit and 64-bit compiles, but that is a more substantial feature.
+  // Bug: 17052573
+  if (!SuppressWarnings || mDiagEngine->hasErrorOccurred()) {
+    llvm::errs() << mDiagClient->str();
+  }
   mDiagEngine->Reset();
   mDiagClient->reset();
 }
diff --git a/slang.h b/slang.h
index 39cfb56..6483c44 100644
--- a/slang.h
+++ b/slang.h
@@ -235,7 +235,7 @@
 
   // Reset the slang compiler state such that it can be reused to compile
   // another file
-  virtual void reset();
+  virtual void reset(bool SuppressWarnings = false);
 
   virtual ~Slang();
 };
diff --git a/slang_rs.cpp b/slang_rs.cpp
index 6bb5798..e269e57 100644
--- a/slang_rs.cpp
+++ b/slang_rs.cpp
@@ -324,12 +324,15 @@
   // a single pass over the input file.
   bool SuppressAllWarnings = (Opts.mOutputType != Slang::OT_Dependency);
 
+  bool CompileSecondTimeFor64Bit = Opts.mEmit3264 && Opts.mBitWidth == 64;
+
   for (unsigned i = 0, e = IOFiles32.size(); i != e; i++) {
     InputFile = IOFile64Iter->first;
     Output64File = IOFile64Iter->second;
     Output32File = IOFile32Iter->second;
 
-    reset();
+    // We suppress warnings (via reset) if we are doing a second compilation.
+    reset(CompileSecondTimeFor64Bit);
 
     if (!setInputSource(InputFile))
       return false;
@@ -433,11 +436,11 @@
   return true;
 }
 
-void SlangRS::reset() {
+void SlangRS::reset(bool SuppressWarnings) {
   delete mRSContext;
   mRSContext = NULL;
   mGeneratedFileNames.clear();
-  Slang::reset();
+  Slang::reset(SuppressWarnings);
 }
 
 SlangRS::~SlangRS() {
diff --git a/slang_rs.h b/slang_rs.h
index 3a04444..828b656 100644
--- a/slang_rs.h
+++ b/slang_rs.h
@@ -112,7 +112,7 @@
                const std::list<std::pair<const char*, const char*> > &DepFiles,
                const RSCCOptions &Opts);
 
-  virtual void reset();
+  virtual void reset(bool SuppressWarnings = false);
 
   virtual ~SlangRS();