Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: src/PNaClTranslator.cpp

Issue 1346723002: Fix operand lookup in functions to check if local index out of range. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix nit in last patch. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests_lit/parse_errs/Inputs/fcn-value-index-isnt-defined.tbc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===// 1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 /// 9 ///
10 /// \file 10 /// \file
(...skipping 1265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 } 1276 }
1277 1277
1278 // Set the next constant ID to the given constant C. 1278 // Set the next constant ID to the given constant C.
1279 void setNextConstantID(Ice::Constant *C) { setNextLocalInstIndex(C); } 1279 void setNextConstantID(Ice::Constant *C) { setNextLocalInstIndex(C); }
1280 1280
1281 // Returns the value referenced by the given value Index. 1281 // Returns the value referenced by the given value Index.
1282 Ice::Operand *getOperand(NaClBcIndexSize_t Index) { 1282 Ice::Operand *getOperand(NaClBcIndexSize_t Index) {
1283 if (Index < CachedNumGlobalValueIDs) { 1283 if (Index < CachedNumGlobalValueIDs) {
1284 return Context->getGlobalConstantByID(Index); 1284 return Context->getGlobalConstantByID(Index);
1285 } 1285 }
1286 if (isIRGenerationDisabled())
1287 return nullptr;
1286 NaClBcIndexSize_t LocalIndex = Index - CachedNumGlobalValueIDs; 1288 NaClBcIndexSize_t LocalIndex = Index - CachedNumGlobalValueIDs;
1289 if (LocalIndex >= LocalOperands.size())
1290 reportGetOperandUndefined(Index);
1287 Ice::Operand *Op = LocalOperands[LocalIndex]; 1291 Ice::Operand *Op = LocalOperands[LocalIndex];
1288 if (Op == nullptr) { 1292 if (Op == nullptr)
1289 if (isIRGenerationDisabled()) 1293 reportGetOperandUndefined(Index);
1290 return nullptr;
1291 std::string Buffer;
1292 raw_string_ostream StrBuf(Buffer);
1293 StrBuf << "Value index " << Index << " not defined!";
1294 Fatal(StrBuf.str());
1295 }
1296 return Op; 1294 return Op;
1297 } 1295 }
1298 1296
1299 private: 1297 private:
1300 Ice::TimerMarker Timer; 1298 Ice::TimerMarker Timer;
1301 // The number of words in the bitstream defining the function block. 1299 // The number of words in the bitstream defining the function block.
1302 uint64_t NumBytesDefiningFunction = 0; 1300 uint64_t NumBytesDefiningFunction = 0;
1303 // Maximum number of records that can appear in the function block, based on 1301 // Maximum number of records that can appear in the function block, based on
1304 // the number of bytes defining the function block. 1302 // the number of bytes defining the function block.
1305 uint64_t MaxRecordsInBlock = 0; 1303 uint64_t MaxRecordsInBlock = 0;
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 // cases, a placeholder value for the badly formed instruction is not needed. 1972 // cases, a placeholder value for the badly formed instruction is not needed.
1975 // Hence, if Ty is void, an error instruction is not appended. 1973 // Hence, if Ty is void, an error instruction is not appended.
1976 void appendErrorInstruction(Ice::Type Ty) { 1974 void appendErrorInstruction(Ice::Type Ty) {
1977 // Note: we don't worry about downstream translation errors because the 1975 // Note: we don't worry about downstream translation errors because the
1978 // function will not be translated if any errors occur. 1976 // function will not be translated if any errors occur.
1979 if (Ty == Ice::IceType_void) 1977 if (Ty == Ice::IceType_void)
1980 return; 1978 return;
1981 Ice::Variable *Var = getNextInstVar(Ty); 1979 Ice::Variable *Var = getNextInstVar(Ty);
1982 CurrentNode->appendInst(Ice::InstAssign::create(Func.get(), Var, Var)); 1980 CurrentNode->appendInst(Ice::InstAssign::create(Func.get(), Var, Var));
1983 } 1981 }
1982
1983 Ice::Operand *reportGetOperandUndefined(NaClBcIndexSize_t Index) {
1984 std::string Buffer;
1985 raw_string_ostream StrBuf(Buffer);
1986 StrBuf << "Value index " << Index << " not defined!";
1987 Fatal(StrBuf.str());
1988 }
1984 }; 1989 };
1985 1990
1986 void FunctionParser::ExitBlock() { 1991 void FunctionParser::ExitBlock() {
1987 // Check if the last instruction in the function was terminating. 1992 // Check if the last instruction in the function was terminating.
1988 if (!InstIsTerminating) { 1993 if (!InstIsTerminating) {
1989 Error("Last instruction in function not terminator"); 1994 Error("Last instruction in function not terminator");
1990 if (isIRGenerationDisabled()) 1995 if (isIRGenerationDisabled())
1991 return; 1996 return;
1992 // Recover by inserting an unreachable instruction. 1997 // Recover by inserting an unreachable instruction.
1993 CurrentNode->appendInst(Ice::InstUnreachable::create(Func.get())); 1998 CurrentNode->appendInst(Ice::InstUnreachable::create(Func.get()));
(...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after
3146 } 3151 }
3147 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { 3152 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) {
3148 ErrStream 3153 ErrStream
3149 << IRFilename 3154 << IRFilename
3150 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; 3155 << ": Bitcode stream should be a multiple of 4 bytes in length.\n";
3151 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); 3156 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes");
3152 } 3157 }
3153 } 3158 }
3154 3159
3155 } // end of namespace Ice 3160 } // end of namespace Ice
OLDNEW
« no previous file with comments | « no previous file | tests_lit/parse_errs/Inputs/fcn-value-index-isnt-defined.tbc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698