Fix code checking arguments to an intrinsic call. Fixes instrinsic function "validateCall" to properly define which parameter type doesn't match the expected signature for that intrinsic. Previous code did not take into account that the first element of the intrinsic signature was the return type. Also fixes error messages to print the name of the intrinsic function. BUG= https://code.google.com/p/nativeclient/issues/detail?id=4326 R=stichnot@chromium.org Review URL: https://codereview.chromium.org/1359993002 .
diff --git a/src/IceIntrinsics.cpp b/src/IceIntrinsics.cpp index bbbf086..123817d 100644 --- a/src/IceIntrinsics.cpp +++ b/src/IceIntrinsics.cpp
@@ -330,7 +330,7 @@ } for (size_t i = 1; i < NumTypes; ++i) { if (Call->getArg(i - 1)->getType() != Signature[i]) { - ArgIndex = i; + ArgIndex = i - 1; return Intrinsics::WrongCallArgType; } }
diff --git a/src/PNaClTranslator.cpp b/src/PNaClTranslator.cpp index 812537e..d792865 100644 --- a/src/PNaClTranslator.cpp +++ b/src/PNaClTranslator.cpp
@@ -2666,8 +2666,10 @@ const Ice::FuncSigType *Signature = nullptr; Ice::Type ReturnType = Ice::IceType_void; const Ice::Intrinsics::FullIntrinsicInfo *IntrinsicInfo = nullptr; + // Name of function if a direct call/intrinsic. Null otherwise. + Ice::FunctionDeclaration *Fcn = nullptr; if (Record.GetCode() == naclbitc::FUNC_CODE_INST_CALL) { - Ice::FunctionDeclaration *Fcn = Context->getFunctionByID(CalleeIndex); + Fcn = Context->getFunctionByID(CalleeIndex); Signature = &Fcn->getSignature(); ReturnType = Signature->getReturnType(); @@ -2800,7 +2802,7 @@ case Ice::Intrinsics::BadReturnType: { std::string Buffer; raw_string_ostream StrBuf(Buffer); - StrBuf << "Intrinsic call expects return type " + StrBuf << "Intrinsic " << Fcn->getName() << " expects return type" << IntrinsicInfo->getReturnType() << ". Found: " << Inst->getReturnType(); Error(StrBuf.str()); @@ -2809,7 +2811,8 @@ case Ice::Intrinsics::WrongNumOfArgs: { std::string Buffer; raw_string_ostream StrBuf(Buffer); - StrBuf << "Intrinsic call expects " << IntrinsicInfo->getNumArgs() + StrBuf << "Intrinsic " << Fcn->getName() << " expects " + << IntrinsicInfo->getNumArgs() << ". Found: " << Inst->getNumArgs(); Error(StrBuf.str()); break; @@ -2817,8 +2820,9 @@ case Ice::Intrinsics::WrongCallArgType: { std::string Buffer; raw_string_ostream StrBuf(Buffer); - StrBuf << "Intrinsic call argument " << ArgIndex << " expects type " - << IntrinsicInfo->getArgType(ArgIndex) + StrBuf << "Intrinsic " << Fcn->getName() << " expects " + << IntrinsicInfo->getArgType(ArgIndex) << " for argument " + << (ArgIndex + 1) << ". Found: " << Inst->getArg(ArgIndex)->getType(); Error(StrBuf.str()); break;