Commit 9d25e620 by Karl Schimpf

Fix operand lookup in functions to check if local index out of range.

parent 57e12689
...@@ -1283,16 +1283,14 @@ public: ...@@ -1283,16 +1283,14 @@ public:
if (Index < CachedNumGlobalValueIDs) { if (Index < CachedNumGlobalValueIDs) {
return Context->getGlobalConstantByID(Index); return Context->getGlobalConstantByID(Index);
} }
NaClBcIndexSize_t LocalIndex = Index - CachedNumGlobalValueIDs;
Ice::Operand *Op = LocalOperands[LocalIndex];
if (Op == nullptr) {
if (isIRGenerationDisabled()) if (isIRGenerationDisabled())
return nullptr; return nullptr;
std::string Buffer; NaClBcIndexSize_t LocalIndex = Index - CachedNumGlobalValueIDs;
raw_string_ostream StrBuf(Buffer); if (LocalIndex >= LocalOperands.size())
StrBuf << "Value index " << Index << " not defined!"; reportGetOperandUndefined(Index);
Fatal(StrBuf.str()); Ice::Operand *Op = LocalOperands[LocalIndex];
} if (Op == nullptr)
reportGetOperandUndefined(Index);
return Op; return Op;
} }
...@@ -1981,6 +1979,13 @@ private: ...@@ -1981,6 +1979,13 @@ private:
Ice::Variable *Var = getNextInstVar(Ty); Ice::Variable *Var = getNextInstVar(Ty);
CurrentNode->appendInst(Ice::InstAssign::create(Func.get(), Var, Var)); CurrentNode->appendInst(Ice::InstAssign::create(Func.get(), Var, Var));
} }
Ice::Operand *reportGetOperandUndefined(NaClBcIndexSize_t Index) {
std::string Buffer;
raw_string_ostream StrBuf(Buffer);
StrBuf << "Value index " << Index << " not defined!";
Fatal(StrBuf.str());
}
}; };
void FunctionParser::ExitBlock() { void FunctionParser::ExitBlock() {
......
65535,8,2;
1,1;
65535,17,2;
1,4;
7,32;
21,0,0;
7,8;
2;
65534;
8,1,0,0,0;
65535,19,2;
5,0;
65534;
65535,14,2;
1,0,102;
65534;
65535,12,2;
1,1;
65535,11,2;
1,0;
4,2;
65534;
19,1,3;
10,0;
65534;
65534;
; Test if we detect duplicate names in a symbol table.
; REQUIRES: no_minimal_build
; RUN: not %pnacl_sz -bitcode-as-text \
; RUN: %p/Inputs/fcn-value-index-isnt-defined.tbc \
; RUN: -bitcode-format=pnacl -notranslate -build-on-read 2>&1 \
; RUN: | FileCheck %s
; CHECK: Value index {{.*}} not defined!
; RUN: pnacl-bcfuzz -bitcode-as-text \
; RUN: %p/Inputs/fcn-value-index-isnt-defined.tbc -output - \
; RUN: | not pnacl-bcdis -no-records | FileCheck -check-prefix=ASM %s
; ASM: module { // BlockID = 8
; ASM: version 1;
; ASM: types { // BlockID = 17
; ASM: count 4;
; ASM: @t0 = i32;
; ASM: @t1 = i32 ();
; ASM: @t2 = i8;
; ASM: @t3 = void;
; ASM: }
; ASM: define external i32 @f0();
; ASM: globals { // BlockID = 19
; ASM: count 0;
; ASM: }
; ASM: valuesymtab { // BlockID = 14
; ASM: @f0 : "f";
; ASM: }
; ASM: function i32 @f0() { // BlockID = 12
; ASM: blocks 1;
; ASM: constants { // BlockID = 11
; ASM: i32:
; ASM: %c0 = i32 1;
; ASM: }
; ASM: %b0:
; ASM: %v0 = alloca i8, i32 %c0, align 4;
; ASM: ret void %v1;
; ASM: Error({{.*}}): Can't find type for %v1
; 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