Fix bitcode parser to check type signatures of functions.

Before, type signatures of functions were only checked when called.
This CL fixes this by checking all function signatures.

BUG=None
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/1579203002 .
diff --git a/src/PNaClTranslator.cpp b/src/PNaClTranslator.cpp
index a7b367c..13e0870 100644
--- a/src/PNaClTranslator.cpp
+++ b/src/PNaClTranslator.cpp
@@ -338,6 +338,8 @@
     installFunctionNames();
   }
 
+  void verifyFunctionTypeSignatures();
+
   void createValueIDs() {
     assert(VariableDeclarations);
     ValueIDConstants.reserve(VariableDeclarations->size() +
@@ -637,6 +639,14 @@
   return Ice::IceType_void;
 }
 
+void TopLevelParser::verifyFunctionTypeSignatures() {
+  const Ice::GlobalContext *Ctx = getTranslator().getContext();
+  for (Ice::FunctionDeclaration *FuncDecl : FunctionDeclarations) {
+    if (!FuncDecl->validateTypeSignature(Ctx))
+      Error(FuncDecl->getTypeSignatureError(Ctx));
+  }
+}
+
 // Base class for parsing blocks within the bitcode file. Note: Because this is
 // the base class of block parsers, we generate error messages if ParseBlock or
 // ParseRecord is not overridden in derived classes.
@@ -2648,16 +2658,7 @@
       }
 
       // Check if this direct call is to an Intrinsic (starts with "llvm.")
-      bool BadIntrinsic;
-      IntrinsicInfo = getTranslator().getContext()->getIntrinsicsInfo().find(
-          Fcn->getName(), BadIntrinsic);
-      if (BadIntrinsic) {
-        std::string Buffer;
-        raw_string_ostream StrBuf(Buffer);
-        StrBuf << "Invalid PNaCl intrinsic call to " << Fcn->getName();
-        Error(StrBuf.str());
-        IntrinsicInfo = nullptr;
-      }
+      IntrinsicInfo = Fcn->getIntrinsicInfo(getTranslator().getContext());
       if (IntrinsicInfo && IntrinsicInfo->getNumArgs() != NumParams) {
         std::string Buffer;
         raw_string_ostream StrBuf(Buffer);
@@ -2712,16 +2713,14 @@
       if (Signature)
         verifyCallArgTypeMatches(Fcn, Index, OpType,
                                  Signature->getArgType(Index));
-      if (IntrinsicInfo) {
-        verifyCallArgTypeMatches(Fcn, Index, OpType,
-                                 IntrinsicInfo->getArgType(Index));
-      } else if (!isCallParameterType(OpType)) {
+      else if (!isCallParameterType(OpType)) {
         std::string Buffer;
         raw_string_ostream StrBuf(Buffer);
         StrBuf << "Argument " << *Op << " of " << printName(Fcn)
                << " has invalid type: " << Op->getType();
         Error(StrBuf.str());
         appendErrorInstruction(ReturnType);
+        return;
       }
     }
 
@@ -3007,6 +3006,7 @@
     if (!GlobalDeclarationNamesAndInitializersInstalled) {
       Context->installGlobalNames();
       Context->createValueIDs();
+      Context->verifyFunctionTypeSignatures();
       std::unique_ptr<Ice::VariableDeclarationList> Globals =
           Context->getGlobalVariables();
       if (Globals)