Fix subzero translator to use new API for reporting errors.

The error handling in LLVM for errors has been updated so that errors in
the bitcode stream no longer cause (assertion crashes). This CL applies
the appropriate changes to subzero.

See CL https://codereview.chromium.org/932953002 for changes to error
handling for LLVM.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4002
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/916313004
diff --git a/src/PNaClTranslator.cpp b/src/PNaClTranslator.cpp
index d4bcd8e..d0b099d 100644
--- a/src/PNaClTranslator.cpp
+++ b/src/PNaClTranslator.cpp
@@ -162,9 +162,9 @@
 public:
   typedef std::vector<Ice::FunctionDeclaration *> FunctionDeclarationListType;
 
-  TopLevelParser(Ice::Translator &Translator, NaClBitcodeHeader &Header,
-                 NaClBitstreamCursor &Cursor, Ice::ErrorCode &ErrorStatus)
-      : NaClBitcodeParser(Cursor), Translator(Translator), Header(Header),
+  TopLevelParser(Ice::Translator &Translator, NaClBitstreamCursor &Cursor,
+                 Ice::ErrorCode &ErrorStatus)
+      : NaClBitcodeParser(Cursor), Translator(Translator),
         ErrorStatus(ErrorStatus), NumErrors(0), NextDefiningFunctionID(0),
         VariableDeclarations(new Ice::VariableDeclarationList()),
         BlockParser(nullptr), StubbedConstCallValue(nullptr) {}
@@ -177,19 +177,17 @@
     BlockParser = NewBlockParser;
   }
 
-  // Generates error with given Message. Always returns true.
-  bool Error(const std::string &Message) override;
+  /// Generates error with given Message, occurring at BitPosition
+  /// within the bitcode file. Always returns true.
+  bool ErrorAt(uint64_t BitPosition, const std::string &Message) final;
 
-  // Generates error message with respect to the current block parser.
+  /// Generates error message with respect to the current block parser.
   bool BlockError(const std::string &Message);
 
   /// Returns the number of errors found while parsing the bitcode
   /// file.
   unsigned getNumErrors() const { return NumErrors; }
 
-  /// Returns the number of bytes in the bitcode header.
-  size_t getHeaderSize() const { return Header.getHeaderSize(); }
-
   /// Changes the size of the type list to the given size.
   void resizeTypeIDValues(unsigned NewSize) { TypeIDValues.resize(NewSize); }
 
@@ -243,8 +241,7 @@
            FunctionDeclarationList[NextDefiningFunctionID]->isProto())
       ++NextDefiningFunctionID;
     if (NextDefiningFunctionID >= NumDeclaredFunctions)
-      report_fatal_error(
-          "More function blocks than defined function addresses");
+      Fatal("More function blocks than defined function addresses");
     return NextDefiningFunctionID++;
   }
 
@@ -361,8 +358,6 @@
 private:
   // The translator associated with the parser.
   Ice::Translator &Translator;
-  // The bitcode header.
-  NaClBitcodeHeader &Header;
   // The exit status that should be set to true if an error occurs.
   Ice::ErrorCode &ErrorStatus;
   // The number of errors reported.
@@ -505,16 +500,16 @@
   Ice::Type convertToIceTypeError(Type *LLVMTy);
 };
 
-bool TopLevelParser::Error(const std::string &Message) {
+bool TopLevelParser::ErrorAt(uint64_t Bit, const std::string &Message) {
   ErrorStatus.assign(Ice::EC_Bitcode);
   ++NumErrors;
   Ice::GlobalContext *Context = Translator.getContext();
   Ice::OstreamLocker L(Context);
   raw_ostream &OldErrStream = setErrStream(Context->getStrDump());
-  NaClBitcodeParser::Error(Message);
+  NaClBitcodeParser::ErrorAt(Bit, Message);
   setErrStream(OldErrStream);
   if (!Translator.getFlags().getAllowErrorRecovery())
-    report_fatal_error("Unable to continue");
+    Fatal();
   return true;
 }
 
@@ -541,7 +536,7 @@
   // TODO(kschimpf) Remove error recovery once implementation complete.
   if (!FunctionDeclarationList.empty())
     return FunctionDeclarationList[0];
-  report_fatal_error("Unable to continue");
+  Fatal();
 }
 
 Ice::VariableDeclaration *
@@ -555,7 +550,7 @@
   // TODO(kschimpf) Remove error recovery once implementation complete.
   if (!VariableDeclarations->empty())
     return VariableDeclarations->at(0);
-  report_fatal_error("Unable to continue");
+  Fatal();
 }
 
 Ice::Type TopLevelParser::convertToIceTypeError(Type *LLVMTy) {
@@ -590,8 +585,8 @@
     return "unknown";
   }
 
-  // Generates an error Message with the bit address prefixed to it.
-  bool Error(const std::string &Message) override;
+  // Generates an error Message with the Bit address prefixed to it.
+  bool ErrorAt(uint64_t Bit, const std::string &Message) final;
 
 protected:
   // The context parser that contains the decoded state.
@@ -678,12 +673,9 @@
 }
 
 // Generates an error Message with the bit address prefixed to it.
-bool BlockParserBaseClass::Error(const std::string &Message) {
-  uint64_t Bit = Record.GetStartBit() + Context->getHeaderSize() * 8;
+bool BlockParserBaseClass::ErrorAt(uint64_t Bit, const std::string &Message) {
   std::string Buffer;
   raw_string_ostream StrBuf(Buffer);
-  StrBuf << "(" << format("%" PRIu64 ":%u", (Bit / 8),
-                          static_cast<unsigned>(Bit % 8)) << ") ";
   // Note: If dump routines have been turned off, the error messages
   // will not be readable. Hence, replace with simple error. We also
   // use the simple form for unit tests.
@@ -696,7 +688,7 @@
   } else {
     StrBuf << Message;
   }
-  return Context->Error(StrBuf.str());
+  return Context->ErrorAt(Bit, StrBuf.str());
 }
 
 void BlockParserBaseClass::ReportRecordSizeError(unsigned ExpectedSize,
@@ -1235,8 +1227,7 @@
       std::string Buffer;
       raw_string_ostream StrBuf(Buffer);
       StrBuf << "Value index " << Index << " not defined!";
-      Error(StrBuf.str());
-      report_fatal_error("Unable to continue");
+      Fatal(StrBuf.str());
     }
     Ice::Operand *Op = LocalOperands[LocalIndex];
     if (Op == nullptr) {
@@ -1245,8 +1236,7 @@
       std::string Buffer;
       raw_string_ostream StrBuf(Buffer);
       StrBuf << "Value index " << Index << " not defined!";
-      Error(StrBuf.str());
-      report_fatal_error("Unable to continue");
+      Fatal(StrBuf.str());
     }
     return Op;
   }
@@ -3025,21 +3015,23 @@
   }
 
   const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart();
+  const unsigned char *HeaderPtr = BufPtr;
   const unsigned char *EndBufPtr = BufPtr + MemBuf->getBufferSize();
 
   // Read header and verify it is good.
   NaClBitcodeHeader Header;
-  if (Header.Read(BufPtr, EndBufPtr) || !Header.IsSupported()) {
+  if (Header.Read(HeaderPtr, EndBufPtr) || !Header.IsSupported()) {
     errs() << "Invalid PNaCl bitcode header.\n";
     ErrorStatus.assign(EC_Bitcode);
     return;
   }
 
   // Create a bitstream reader to read the bitcode file.
-  NaClBitstreamReader InputStreamFile(BufPtr, EndBufPtr);
+  NaClBitstreamReader InputStreamFile(BufPtr, EndBufPtr,
+                                      Header.getHeaderSize());
   NaClBitstreamCursor InputStream(InputStreamFile);
 
-  TopLevelParser Parser(*this, Header, InputStream, ErrorStatus);
+  TopLevelParser Parser(*this, InputStream, ErrorStatus);
   int TopLevelBlocks = 0;
   while (!InputStream.AtEndOfStream()) {
     if (Parser.Parse()) {
diff --git a/tests_lit/parse_errs/insertextract-err.ll b/tests_lit/parse_errs/insertextract-err.ll
index 206067a..560446a 100644
--- a/tests_lit/parse_errs/insertextract-err.ll
+++ b/tests_lit/parse_errs/insertextract-err.ll
@@ -14,183 +14,183 @@
 
 define void @ExtractV4xi1(<4 x i1> %v, i32 %i) {
   %e0 = extractelement <4 x i1> %v, i32 %i
-; CHECK: Error: {{.*}} not {{.*}} constant
-; MIN: Error: {{.*}} Invalid function record: <6 4 3>
+; CHECK: Error{{.*}} not {{.*}} constant
+; MIN: Error{{.*}} Invalid function record: <6 4 3>
   %e1 = extractelement <4 x i1> %v, i32 4
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <6 5 3>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <6 5 3>
   %e2 = extractelement <4 x i1> %v, i32 9
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record:  <6 6 3>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record:  <6 6 3>
   ret void
 }
 
 define void @ExtractV8xi1(<8 x i1> %v, i32 %i) {
   %e0 = extractelement <8 x i1> %v, i32 %i
-; CHECK: Error: {{.*}} not {{.*}} constant
-; MIN: Error: {{.*}} Invalid function record: <6 4 3>
+; CHECK: Error{{.*}} not {{.*}} constant
+; MIN: Error{{.*}} Invalid function record: <6 4 3>
   %e1 = extractelement <8 x i1> %v, i32 8;
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <6 5 3>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <6 5 3>
   %e2 = extractelement <8 x i1> %v, i32 9;
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <6 6 3>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <6 6 3>
   ret void
 }
 
 define void @ExtractV16xi1(<16 x i1> %v, i32 %i) {
   %e0 = extractelement <16 x i1> %v, i32 %i
-; CHECK: Error: {{.*}} not {{.*}} constant
-; MIN: Error: {{.*}} Invalid function record: <6 4 3>
+; CHECK: Error{{.*}} not {{.*}} constant
+; MIN: Error{{.*}} Invalid function record: <6 4 3>
   %e1 = extractelement <16 x i1> %v, i32 16
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <6 5 3>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <6 5 3>
   %e2 = extractelement <16 x i1> %v, i32 24
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <6 6 3>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <6 6 3>
   ret void
 }
 
 define void @ExtractV16xi8(<16 x i8> %v, i32 %i) {
   %e0 = extractelement <16 x i8> %v, i32 %i
-; CHECK: Error: {{.*}} not {{.*}} constant
-; MIN: Error: {{.*}} Invalid function record: <6 4 3>
+; CHECK: Error{{.*}} not {{.*}} constant
+; MIN: Error{{.*}} Invalid function record: <6 4 3>
   %e1 = extractelement <16 x i8> %v, i32 16
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <6 5 3>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <6 5 3>
   %e2 = extractelement <16 x i8> %v, i32 71
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <6 6 3>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <6 6 3>
   ret void
 }
 
 define void @ExtractV8xi16(<8 x i16> %v, i32 %i) {
   %e0 = extractelement <8 x i16> %v, i32 %i
-; CHECK: Error: {{.*}} not {{.*}} constant
-; MIN: Error: {{.*}} Invalid function record: <6 4 3>
+; CHECK: Error{{.*}} not {{.*}} constant
+; MIN: Error{{.*}} Invalid function record: <6 4 3>
   %e1 = extractelement <8 x i16> %v, i32 8
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <6 5 3>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <6 5 3>
   %e2 = extractelement <8 x i16> %v, i32 15
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <6 6 3>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <6 6 3>
   ret void
 }
 
 define i32 @ExtractV4xi32(<4 x i32> %v, i32 %i) {
   %e0 = extractelement <4 x i32> %v, i32 %i
-; CHECK: Error: {{.*}} not {{.*}} constant
-; MIN: Error: {{.*}} Invalid function record: <6 4 3>
+; CHECK: Error{{.*}} not {{.*}} constant
+; MIN: Error{{.*}} Invalid function record: <6 4 3>
   %e1 = extractelement <4 x i32> %v, i32 4
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <6 5 3>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <6 5 3>
   %e2 = extractelement <4 x i32> %v, i32 17
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <6 6 3>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <6 6 3>
   ret i32 %e0
 }
 
 define float @ExtractV4xfloat(<4 x float> %v, i32 %i) {
   %e0 = extractelement <4 x float> %v, i32 %i
-; CHECK: Error: {{.*}} not {{.*}} constant
-; MIN: Error: {{.*}} Invalid function record: <6 3 2>
+; CHECK: Error{{.*}} not {{.*}} constant
+; MIN: Error{{.*}} Invalid function record: <6 3 2>
   %e1 = extractelement <4 x float> %v, i32 4
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <6 4 2>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <6 4 2>
   %e2 = extractelement <4 x float> %v, i32 4
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <6 5 3>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <6 5 3>
   ret float %e2
 }
 
 define <4 x i1> @InsertV4xi1(<4 x i1> %v, i32 %i) {
   %r0 = insertelement <4 x i1> %v, i1 1, i32 %i
-; CHECK: Error: {{.*}} not {{.*}} constant
-; MIN: Error: {{.*}} Invalid function record: <7 5 1 4>
+; CHECK: Error{{.*}} not {{.*}} constant
+; MIN: Error{{.*}} Invalid function record: <7 5 1 4>
   %r1 = insertelement <4 x i1> %v, i1 1, i32 4
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <7 6 2 4>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <7 6 2 4>
   %r2 = insertelement <4 x i1> %v, i1 1, i32 7
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <7 7 3 4>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <7 7 3 4>
   ret <4 x i1> %r2
 }
 
 define <8 x i1> @InsertV8xi1(<8 x i1> %v, i32 %i) {
   %r0 = insertelement <8 x i1> %v, i1 0, i32 %i
-; CHECK: Error: {{.*}} not {{.*}} constant
-; MIN: Error: {{.*}} Invalid function record: <7 5 1 4>
+; CHECK: Error{{.*}} not {{.*}} constant
+; MIN: Error{{.*}} Invalid function record: <7 5 1 4>
   %r1 = insertelement <8 x i1> %v, i1 0, i32 8
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <7 6 2 4>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <7 6 2 4>
   %r2 = insertelement <8 x i1> %v, i1 0, i32 88
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <7 7 3 4>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <7 7 3 4>
   ret <8 x i1> %r2
 }
 
 define <16 x i1> @InsertV16xi1(<16 x i1> %v, i32 %i) {
   %r = insertelement <16 x i1> %v, i1 1, i32 %i
-; CHECK: Error: {{.*}} not {{.*}} constant
-; MIN: Error: {{.*}} Invalid function record: <7 5 1 4>
+; CHECK: Error{{.*}} not {{.*}} constant
+; MIN: Error{{.*}} Invalid function record: <7 5 1 4>
   ret <16 x i1> %r
   %r1 = insertelement <16 x i1> %v, i1 1, i32 16
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <7 6 2 4>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <7 6 2 4>
   %r2 = insertelement <16 x i1> %v, i1 1, i32 31
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <7 7 3 4>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <7 7 3 4>
   ret <16 x i1> %r2
 }
 
 define <16 x i8> @InsertV16xi8(<16 x i8> %v, i32 %i) {
   %r0 = insertelement <16 x i8> %v, i8 34, i32 %i
-; CHECK: Error: {{.*}} not {{.*}} constant
-; MIN: Error: {{.*}} Invalid function record: <7 5 1 4>
+; CHECK: Error{{.*}} not {{.*}} constant
+; MIN: Error{{.*}} Invalid function record: <7 5 1 4>
   %r1 = insertelement <16 x i8> %v, i8 34, i32 16
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <7 6 2 4>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <7 6 2 4>
   %r2 = insertelement <16 x i8> %v, i8 34, i32 19
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <7 7 3 4>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <7 7 3 4>
   ret <16 x i8> %r0
 }
 
 define <8 x i16> @InsertV8xi16(<8 x i16> %v, i32 %i) {
   %r0 = insertelement <8 x i16> %v, i16 289, i32 %i
-; CHECK: Error: {{.*}} not {{.*}} constant
-; MIN: Error: {{.*}} Invalid function record: <7 5 1 4>
+; CHECK: Error{{.*}} not {{.*}} constant
+; MIN: Error{{.*}} Invalid function record: <7 5 1 4>
   %r1 = insertelement <8 x i16> %v, i16 289, i32 8
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <7 6 2 4>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <7 6 2 4>
   %r2 = insertelement <8 x i16> %v, i16 289, i32 19
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <7 7 3 4>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <7 7 3 4>
   ret <8 x i16> %r1
 }
 
 define <4 x i32> @InsertV4xi32(<4 x i32> %v, i32 %i) {
   %r0 = insertelement <4 x i32> %v, i32 54545454, i32 %i
-; CHECK: Error: {{.*}} not {{.*}} constant
-; MIN: Error: {{.*}} Invalid function record: <7 5 3 4>
+; CHECK: Error{{.*}} not {{.*}} constant
+; MIN: Error{{.*}} Invalid function record: <7 5 3 4>
   %r1 = insertelement <4 x i32> %v, i32 54545454, i32 4
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <7 6 4 3>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <7 6 4 3>
   %r2 = insertelement <4 x i32> %v, i32 54545454, i32 9
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <7 7 5 3>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <7 7 5 3>
   ret <4 x i32> %r2
 }
 
 define <4 x float> @InsertV4xfloat(<4 x float> %v, i32 %i) {
   %r0 = insertelement <4 x float> %v, float 3.0, i32 %i
-; CHECK: Error: {{.*}} not {{.*}} constant
-; MIN: Error: {{.*}} Invalid function record: <7 5 1 4>
+; CHECK: Error{{.*}} not {{.*}} constant
+; MIN: Error{{.*}} Invalid function record: <7 5 1 4>
   %r1 = insertelement <4 x float> %v, float 3.0, i32 4
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <7 6 2 4>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <7 6 2 4>
   %r2 = insertelement <4 x float> %v, float 3.0, i32 44
-; CHECK: Error: {{.*}} not in range
-; MIN: Error: {{.*}} Invalid function record: <7 7 3 4>
+; CHECK: Error{{.*}} not in range
+; MIN: Error{{.*}} Invalid function record: <7 7 3 4>
   ret <4 x float> %r2
 }
diff --git a/tests_lit/parse_errs/nacl-fake-intrinsic.ll b/tests_lit/parse_errs/nacl-fake-intrinsic.ll
index 3312cfc..ba31eab 100644
--- a/tests_lit/parse_errs/nacl-fake-intrinsic.ll
+++ b/tests_lit/parse_errs/nacl-fake-intrinsic.ll
@@ -28,5 +28,5 @@
   ret i32 %r
 }
 
-; CHECK: Error: ({{.*}}) Invalid PNaCl intrinsic call to llvm.fake.i32
-; MIN: Error: ({{.*}}) Invalid function record: <34 0 3 1>
+; CHECK: Error({{.*}}): Invalid PNaCl intrinsic call to llvm.fake.i32
+; MIN: Error({{.*}}): Invalid function record: <34 0 3 1>
diff --git a/unittest/IceParseInstsTest.cpp b/unittest/IceParseInstsTest.cpp
index f8df189..5d45888 100644
--- a/unittest/IceParseInstsTest.cpp
+++ b/unittest/IceParseInstsTest.cpp
@@ -51,33 +51,17 @@
   // Show bitcode objdump for BitcodeRecords.
   NaClObjDumpMunger DumpMunger(BitcodeRecords,
                                array_lengthof(BitcodeRecords), Terminator);
-  EXPECT_FALSE(DumpMunger.runTestForAssembly("Nonexistent call arg"));
-  EXPECT_EQ(
-      "module {  // BlockID = 8\n"
-            "  types {  // BlockID = 17\n"
-            "    count 3;\n"
-            "    @t0 = i32;\n"
-            "    @t1 = void;\n"
-            "    @t2 = void (i32, i32);\n"
-            "  }\n"
-            "  declare external void @f0(i32, i32);\n"
-            "  define external void @f1(i32, i32);\n"
-            "  function void @f1(i32 %p0, i32 %p1) {  // BlockID = 12\n"
-            "    blocks 1;\n"
-            "  %b0:\n"
-            "    call void @f0(i32 %p0, i32 @f0);\n"
-            "Error(66:4): Invalid relative value id: 100 (Must be <= 4)\n"
-            "    ret void;\n"
-            "  }\n"
-            "}\n",
-            DumpMunger.getTestResults());
+  EXPECT_FALSE(DumpMunger.runTest("Nonexistent call arg"));
+  EXPECT_EQ("      66:4|    3: <34, 0, 4, 2, 100>    |    call void @f0(i32 "
+            "%p0, i32 @f0);\n"
+            "Error(66:4): Invalid relative value id: 100 (Must be <= 4)\n",
+            DumpMunger.getLinesWithSubstring("66:4"));
 
   // Show that we get appropriate error when parsing in Subzero.
   IceTest::SubzeroBitcodeMunger Munger(
       BitcodeRecords, array_lengthof(BitcodeRecords), Terminator);
   EXPECT_FALSE(Munger.runTest("Nonexistent call arg"));
-  EXPECT_EQ(
-      "Error: (66:4) Invalid function record: <34 0 4 2 100>\n",
+  EXPECT_EQ("Error(66:4): Invalid function record: <34 0 4 2 100>\n",
             Munger.getTestResults());
 }
 
@@ -105,24 +89,10 @@
   // Show text when alignment is 1.
   NaClObjDumpMunger DumpMunger(BitcodeRecords, array_lengthof(BitcodeRecords),
                                Terminator);
-  EXPECT_TRUE(DumpMunger.runTestForAssembly("Good alloca alignment 1"));
-  EXPECT_EQ("module {  // BlockID = 8\n"
-            "  types {  // BlockID = 17\n"
-            "    count 4;\n"
-            "    @t0 = i32;\n"
-            "    @t1 = void;\n"
-            "    @t2 = void (i32);\n"
-            "    @t3 = i8;\n"
-            "  }\n"
-            "  define external void @f0(i32);\n"
-            "  function void @f0(i32 %p0) {  // BlockID = 12\n"
-            "    blocks 1;\n"
-            "  %b0:\n"
-            "    %v0 = alloca i8, i32 %p0, align 1;\n"
-            "    ret void;\n"
-            "  }\n"
-            "}\n",
-            DumpMunger.getTestResults());
+  EXPECT_TRUE(DumpMunger.runTest("Good alloca alignment 1"));
+  EXPECT_EQ("      62:4|    3: <19, 1, 1>            |    %v0 = alloca i8, i32 "
+            "%p0, align 1;\n",
+            DumpMunger.getLinesWithSubstring("62:4"));
 
   // Show that we can handle alignment of 1.
   IceTest::SubzeroBitcodeMunger Munger(
@@ -148,7 +118,7 @@
   };
   EXPECT_FALSE(Munger.runTest("Bad alloca alignment 30", Align30,
                               array_lengthof(Align30)));
-  EXPECT_EQ("Error: (62:4) Invalid function record: <19 1 31>\n",
+  EXPECT_EQ("Error(62:4): Invalid function record: <19 1 31>\n",
             Munger.getTestResults());
 
   EXPECT_FALSE(DumpMunger.runTestForAssembly("Bad alloca alignment 30", Align30,
@@ -194,22 +164,10 @@
   // Show text when alignment is 1.
   NaClObjDumpMunger DumpMunger(BitcodeRecords, array_lengthof(BitcodeRecords),
                                Terminator);
-  EXPECT_TRUE(DumpMunger.runTestForAssembly("Good load i32 alignment 1"));
-  EXPECT_EQ("module {  // BlockID = 8\n"
-            "  types {  // BlockID = 17\n"
-            "    count 2;\n"
-            "    @t0 = i32;\n"
-            "    @t1 = i32 (i32);\n"
-            "  }\n"
-            "  define external i32 @f0(i32);\n"
-            "  function i32 @f0(i32 %p0) {  // BlockID = 12\n"
-            "    blocks 1;\n"
-            "  %b0:\n"
-            "    %v0 = load i32* %p0, align 1;\n"
-            "    ret i32 %v0;\n"
-            "  }\n"
-            "}\n",
-            DumpMunger.getTestResults());
+  EXPECT_TRUE(DumpMunger.runTest("Good load i32 alignment 1"));
+  EXPECT_EQ("      58:4|    3: <20, 1, 1, 0>         |    %v0 = load i32* %p0, "
+            "align 1;\n",
+            DumpMunger.getLinesWithSubstring("58:4"));
   IceTest::SubzeroBitcodeMunger Munger(
       BitcodeRecords, array_lengthof(BitcodeRecords), Terminator);
   EXPECT_TRUE(Munger.runTest("Good load i32 alignment 1"));
@@ -221,7 +179,7 @@
   };
   EXPECT_FALSE(Munger.runTest("Bad load i32 alignment 0", Align0,
                               array_lengthof(Align0)));
-  EXPECT_EQ("Error: (58:4) Invalid function record: <20 1 0 0>\n",
+  EXPECT_EQ("Error(58:4): Invalid function record: <20 1 0 0>\n",
             Munger.getTestResults());
   EXPECT_FALSE(DumpMunger.runTestForAssembly("Bad load i32 alignment 0", Align0,
                                              array_lengthof(Align0)));
@@ -236,7 +194,7 @@
   };
   EXPECT_FALSE(Munger.runTest("Bad load i32 alignment 4", Align4,
                               array_lengthof(Align4)));
-  EXPECT_EQ("Error: (58:4) Invalid function record: <20 1 3 0>\n",
+  EXPECT_EQ("Error(58:4): Invalid function record: <20 1 3 0>\n",
             Munger.getTestResults());
   EXPECT_FALSE(DumpMunger.runTestForAssembly("Bad load i32 alignment 4", Align4,
                                              array_lengthof(Align4)));
@@ -251,7 +209,7 @@
   };
   EXPECT_FALSE(Munger.runTest("Bad load i32 alignment 29", Align29,
                               array_lengthof(Align29)));
-  EXPECT_EQ("Error: (58:4) Invalid function record: <20 1 30 0>\n",
+  EXPECT_EQ("Error(58:4): Invalid function record: <20 1 30 0>\n",
             Munger.getTestResults());
   EXPECT_FALSE(DumpMunger.runTestForAssembly("Bad load i32 alignment 29",
                                              Align29, array_lengthof(Align29)));
@@ -266,7 +224,7 @@
   };
   EXPECT_FALSE(Munger.runTest("Bad load i32 alignment 30", Align30,
                               array_lengthof(Align30)));
-  EXPECT_EQ("Error: (58:4) Invalid function record: <20 1 31 0>\n",
+  EXPECT_EQ("Error(58:4): Invalid function record: <20 1 31 0>\n",
             Munger.getTestResults());
   EXPECT_FALSE(DumpMunger.runTestForAssembly("Bad load i32 alignment 30",
                                              Align30, array_lengthof(Align30)));
@@ -298,23 +256,10 @@
   // Show text when alignment is 1.
   NaClObjDumpMunger DumpMunger(BitcodeRecords, array_lengthof(BitcodeRecords),
                                Terminator);
-  EXPECT_TRUE(DumpMunger.runTestForAssembly("Good load float alignment 1"));
-  EXPECT_EQ("module {  // BlockID = 8\n"
-            "  types {  // BlockID = 17\n"
-            "    count 3;\n"
-            "    @t0 = float;\n"
-            "    @t1 = i32;\n"
-            "    @t2 = float (i32);\n"
-            "  }\n"
-            "  define external float @f0(i32);\n"
-            "  function float @f0(i32 %p0) {  // BlockID = 12\n"
-            "    blocks 1;\n"
-            "  %b0:\n"
-            "    %v0 = load float* %p0, align 1;\n"
-            "    ret float %v0;\n"
-            "  }\n"
-            "}\n",
-            DumpMunger.getTestResults());
+  EXPECT_TRUE(DumpMunger.runTest("Good load float alignment 1"));
+  EXPECT_EQ("      58:4|    3: <20, 1, 1, 0>         |    %v0 = load float* "
+            "%p0, align 1;\n",
+            DumpMunger.getLinesWithSubstring("58:4"));
   IceTest::SubzeroBitcodeMunger Munger(
       BitcodeRecords, array_lengthof(BitcodeRecords), Terminator);
   EXPECT_TRUE(Munger.runTest("Good load float alignment 1"));
@@ -326,7 +271,7 @@
   };
   EXPECT_FALSE(Munger.runTest("Bad load float alignment 0", Align0,
                               array_lengthof(Align0)));
-  EXPECT_EQ("Error: (58:4) Invalid function record: <20 1 0 0>\n",
+  EXPECT_EQ("Error(58:4): Invalid function record: <20 1 0 0>\n",
             Munger.getTestResults());
   EXPECT_FALSE(DumpMunger.runTestForAssembly("Bad load float alignment 0",
                                              Align0, array_lengthof(Align0)));
@@ -353,7 +298,7 @@
   };
   EXPECT_FALSE(Munger.runTest("Bad load float alignment 29", Align29,
                               array_lengthof(Align29)));
-  EXPECT_EQ("Error: (58:4) Invalid function record: <20 1 30 0>\n",
+  EXPECT_EQ("Error(58:4): Invalid function record: <20 1 30 0>\n",
             Munger.getTestResults());
   EXPECT_FALSE(DumpMunger.runTestForAssembly("Bad load float alignment 29",
                                              Align29, array_lengthof(Align29)));
@@ -369,7 +314,7 @@
   };
   EXPECT_FALSE(Munger.runTest("Bad load float alignment 30", Align30,
                               array_lengthof(Align30)));
-  EXPECT_EQ("Error: (58:4) Invalid function record: <20 1 31 0>\n",
+  EXPECT_EQ("Error(58:4): Invalid function record: <20 1 31 0>\n",
             Munger.getTestResults());
   EXPECT_FALSE(DumpMunger.runTestForAssembly("Bad load float alignment 30",
                                              Align30, array_lengthof(Align30)));
@@ -402,23 +347,10 @@
   // Show text when alignment is 1.
   NaClObjDumpMunger DumpMunger(BitcodeRecords, array_lengthof(BitcodeRecords),
                                Terminator);
-  EXPECT_TRUE(DumpMunger.runTestForAssembly("Good Store Alignment 1"));
-  EXPECT_EQ("module {  // BlockID = 8\n"
-            "  types {  // BlockID = 17\n"
-            "    count 3;\n"
-            "    @t0 = float;\n"
-            "    @t1 = i32;\n"
-            "    @t2 = float (i32, float);\n"
-            "  }\n"
-            "  define external float @f0(i32, float);\n"
-            "  function float @f0(i32 %p0, float %p1) {  // BlockID = 12\n"
-            "    blocks 1;\n"
-            "  %b0:\n"
-            "    store float %p1, float* %p0, align 1;\n"
-            "    ret float %p1;\n"
-            "  }\n"
-            "}\n",
-            DumpMunger.getTestResults());
+  EXPECT_TRUE(DumpMunger.runTest("Good Store Alignment 1"));
+  EXPECT_EQ("      62:4|    3: <24, 2, 1, 1>         |    store float %p1, "
+            "float* %p0, \n",
+            DumpMunger.getLinesWithSubstring("62:4"));
   IceTest::SubzeroBitcodeMunger Munger(
       BitcodeRecords, array_lengthof(BitcodeRecords), Terminator);
   EXPECT_TRUE(Munger.runTest("Good store alignment"));
@@ -430,7 +362,7 @@
   };
   EXPECT_FALSE(
       Munger.runTest("Bad store alignment 0", Align0, array_lengthof(Align0)));
-  EXPECT_EQ("Error: (62:4) Invalid function record: <24 2 1 0>\n",
+  EXPECT_EQ("Error(62:4): Invalid function record: <24 2 1 0>\n",
             Munger.getTestResults());
   EXPECT_FALSE(DumpMunger.runTestForAssembly("Bad store alignment 0", Align0,
                                              array_lengthof(Align0)));
@@ -456,7 +388,7 @@
   };
   EXPECT_FALSE(
       Munger.runTest("Bad store alignment 8", Align8, array_lengthof(Align8)));
-  EXPECT_EQ("Error: (62:4) Invalid function record: <24 2 1 4>\n",
+  EXPECT_EQ("Error(62:4): Invalid function record: <24 2 1 4>\n",
             Munger.getTestResults());
   EXPECT_FALSE(DumpMunger.runTestForAssembly("Bad store alignment 8", Align8,
                                              array_lengthof(Align8)));
@@ -472,7 +404,7 @@
   };
   EXPECT_FALSE(Munger.runTest("Bad store alignment 29", Align29,
                               array_lengthof(Align29)));
-  EXPECT_EQ("Error: (62:4) Invalid function record: <24 2 1 30>\n",
+  EXPECT_EQ("Error(62:4): Invalid function record: <24 2 1 30>\n",
             Munger.getTestResults());
   EXPECT_FALSE(DumpMunger.runTestForAssembly("Bad store alignment 29", Align29,
                                              array_lengthof(Align29)));
@@ -488,7 +420,7 @@
   };
   EXPECT_FALSE(Munger.runTest("Bad store alignment 30", Align30,
                               array_lengthof(Align30)));
-  EXPECT_EQ("Error: (62:4) Invalid function record: <24 2 1 31>\n",
+  EXPECT_EQ("Error(62:4): Invalid function record: <24 2 1 31>\n",
             Munger.getTestResults());
   EXPECT_FALSE(DumpMunger.runTestForAssembly("Bad Store alignment 30", Align30,
                                              array_lengthof(Align30)));