Fix error reporting for parallel parsed function blocks.

Fixes error reporting in function blocks by adding a start address
with parallel parses, and then using the getErrorBitNo() method
of the bitstream cursor to correct error bit number, based on the
start address.

Dependent on CL https://codereview.chromium.org/1851163002.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4363
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/1848313003 .
diff --git a/src/PNaClTranslator.cpp b/src/PNaClTranslator.cpp
index 514d817..4aef244 100644
--- a/src/PNaClTranslator.cpp
+++ b/src/PNaClTranslator.cpp
@@ -774,7 +774,8 @@
   } else {
     StrBuf << Message;
   }
-  return Context->ErrorAt(Level, Bit, StrBuf.str());
+  return Context->ErrorAt(Level, Record.GetCursor().getErrorBitNo(Bit),
+                          StrBuf.str());
 }
 
 void BlockParserBaseClass::reportRecordSizeError(size_t ExpectedSize,
@@ -3106,7 +3107,8 @@
 
 std::unique_ptr<Ice::Cfg> CfgParserWorkItem::getParsedCfg() {
   NaClBitstreamCursor &OldCursor(ModParser->getCursor());
-  llvm::NaClBitstreamReader Reader(Buffer.get(), Buffer.get() + BufferSize,
+  llvm::NaClBitstreamReader Reader(OldCursor.getStartWordByteForBit(StartBit),
+                                   Buffer.get(), Buffer.get() + BufferSize,
                                    OldCursor.getBitStreamReader());
   NaClBitstreamCursor NewCursor(Reader);
   NewCursor.JumpToBit(NewCursor.getWordBitNo(StartBit));
diff --git a/tests_lit/parse_errs/parallel.ll b/tests_lit/parse_errs/parallel.ll
new file mode 100644
index 0000000..6b1ba99
--- /dev/null
+++ b/tests_lit/parse_errs/parallel.ll
@@ -0,0 +1,23 @@
+; Test that we report a bug at the same place, independent of a parallel parse.
+
+; REQUIRES: no_minimal_build
+
+; RUN: %p2i --expect-fail -i %s --args -threads=0 -parse-parallel=0 \
+; RUN:      -allow-externally-defined-symbols | FileCheck %s
+
+; RUN: %p2i --expect-fail -i %s --args -threads=1 -parse-parallel=1 \
+; RUN:      -allow-externally-defined-symbols | FileCheck %s
+
+declare i32 @f();
+
+declare i64 @g();
+
+define void @Test(i32 %ifcn) {
+entry:
+  %fcn =  inttoptr i32 %ifcn to i1()*
+  %v = call i1 %fcn()
+
+; CHECK: Error(222:6): Return type of function is invalid: i1
+
+  ret void
+}