Commit 958ff342 by Karl Schimpf

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 .
parent 28fc2d7d
......@@ -330,7 +330,7 @@ Intrinsics::FullIntrinsicInfo::validateCall(const InstCall *Call,
}
for (size_t i = 1; i < NumTypes; ++i) {
if (Call->getArg(i - 1)->getType() != Signature[i]) {
ArgIndex = i;
ArgIndex = i - 1;
return Intrinsics::WrongCallArgType;
}
}
......
......@@ -2666,8 +2666,10 @@ void FunctionParser::ProcessRecord() {
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 @@ void FunctionParser::ProcessRecord() {
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 @@ void FunctionParser::ProcessRecord() {
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 @@ void FunctionParser::ProcessRecord() {
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;
......
65535,8,2;
1,1;
65535,17,2;
1,6;
7,32;
4;
21,0,0,0;
2;
21,0,0,1;
21,0,3,0,1;
65534;
8,4,0,1,0;
8,2,0,1,0;
8,4,0,1,0;
8,5,0,0,0;
65535,19,2;
5,0;
65534;
65535,14,2;
1,1,102,111,111;
1,2,98,97,114;
1,3,102;
1,0,108,108,118,109,46,110,97,99,108,46,115,101,116,106,109,112;
65534;
65535,12,2;
1,1;
34,0,6,1;
10;
65534;
65534;
; Tests that we correctly check parameter types for intrinsics.
; REQUIRES: no_minimal_build
; RUN: not %pnacl_sz -bitcode-as-text \
; RUN: %p/Inputs/bad-intrinsic-arg.tbc \
; RUN: -bitcode-format=pnacl -notranslate -build-on-read 2>&1 \
; RUN: | FileCheck %s
; CHECK: Intrinsic llvm.nacl.setjmp expects i32 for argument 1. Found: double
; RUN: pnacl-bcfuzz -bitcode-as-text \
; RUN: %p/Inputs/bad-intrinsic-arg.tbc -output - \
; RUN: | not pnacl-bcdis -no-records | FileCheck -check-prefix=ASM %s
; ASM: module { // BlockID = 8
; ASM: declare external i32 @f0(double);
; ASM: valuesymtab { // BlockID = 14
; ASM: @f0 : "llvm.nacl.setjmp";
; ASM: Error(118:0): Intrinsic llvm.nacl.setjmp expects i8* for argument 1. Found: double
; ASM: }
; ASM: function void @f3(i32 %p0, double %p1) { // BlockID = 12
; ASM: blocks 1;
; ASM: %b0:
; ASM: %v0 = call i32 @f0(double %p1);
; ASM: ret void;
; ASM: }
; ASM: }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment