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

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 formatting. 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 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 } 1291 }
1292 1292
1293 // Set the next constant ID to the given constant C. 1293 // Set the next constant ID to the given constant C.
1294 void setNextConstantID(Ice::Constant *C) { setNextLocalInstIndex(C); } 1294 void setNextConstantID(Ice::Constant *C) { setNextLocalInstIndex(C); }
1295 1295
1296 // Returns the value referenced by the given value Index. 1296 // Returns the value referenced by the given value Index.
1297 Ice::Operand *getOperand(NaClBcIndexSize_t Index) { 1297 Ice::Operand *getOperand(NaClBcIndexSize_t Index) {
1298 if (Index < CachedNumGlobalValueIDs) { 1298 if (Index < CachedNumGlobalValueIDs) {
1299 return Context->getGlobalConstantByID(Index); 1299 return Context->getGlobalConstantByID(Index);
1300 } 1300 }
1301 if (isIRGenerationDisabled())
1302 return nullptr;
1301 NaClBcIndexSize_t LocalIndex = Index - CachedNumGlobalValueIDs; 1303 NaClBcIndexSize_t LocalIndex = Index - CachedNumGlobalValueIDs;
1304 if (LocalIndex >= LocalOperands.size())
1305 reportGetOperandUndefined(Index);
1302 Ice::Operand *Op = LocalOperands[LocalIndex]; 1306 Ice::Operand *Op = LocalOperands[LocalIndex];
1303 if (Op == nullptr) { 1307 if (Op == nullptr)
1304 if (isIRGenerationDisabled()) 1308 reportGetOperandUndefined(Index);
1305 return nullptr;
1306 std::string Buffer;
1307 raw_string_ostream StrBuf(Buffer);
1308 StrBuf << "Value index " << Index << " not defined!";
1309 Fatal(StrBuf.str());
1310 }
1311 return Op; 1309 return Op;
1312 } 1310 }
1313 1311
1314 private: 1312 private:
1315 Ice::TimerMarker Timer; 1313 Ice::TimerMarker Timer;
1316 // The number of words in the bitstream defining the function block. 1314 // The number of words in the bitstream defining the function block.
1317 uint64_t NumBytesDefiningFunction = 0; 1315 uint64_t NumBytesDefiningFunction = 0;
1318 // Maximum number of records that can appear in the function block, based on 1316 // Maximum number of records that can appear in the function block, based on
1319 // the number of bytes defining the function block. 1317 // the number of bytes defining the function block.
1320 uint64_t MaxRecordsInBlock = 0; 1318 uint64_t MaxRecordsInBlock = 0;
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
1997 // for the badly formed instruction is not needed. Hence, if Ty is 1995 // for the badly formed instruction is not needed. Hence, if Ty is
1998 // void, an error instruction is not appended. 1996 // void, an error instruction is not appended.
1999 void appendErrorInstruction(Ice::Type Ty) { 1997 void appendErrorInstruction(Ice::Type Ty) {
2000 // Note: we don't worry about downstream translation errors because 1998 // Note: we don't worry about downstream translation errors because
2001 // the function will not be translated if any errors occur. 1999 // the function will not be translated if any errors occur.
2002 if (Ty == Ice::IceType_void) 2000 if (Ty == Ice::IceType_void)
2003 return; 2001 return;
2004 Ice::Variable *Var = getNextInstVar(Ty); 2002 Ice::Variable *Var = getNextInstVar(Ty);
2005 CurrentNode->appendInst(Ice::InstAssign::create(Func.get(), Var, Var)); 2003 CurrentNode->appendInst(Ice::InstAssign::create(Func.get(), Var, Var));
2006 } 2004 }
2005
2006 Ice::Operand *reportGetOperandUndefined(NaClBcIndexSize_t Index);
Jim Stichnoth 2015/09/16 19:57:41 Seems a little odd not to just provide the definit
Karl 2015/09/16 20:47:29 Done.
2007 }; 2007 };
2008 2008
2009 Ice::Operand *
2010 FunctionParser::reportGetOperandUndefined(NaClBcIndexSize_t Index) {
2011 std::string Buffer;
2012 raw_string_ostream StrBuf(Buffer);
2013 StrBuf << "Value index " << Index << " not defined!";
2014 Fatal(StrBuf.str());
2015 }
2016
2009 void FunctionParser::ExitBlock() { 2017 void FunctionParser::ExitBlock() {
2010 // Check if the last instruction in the function was terminating. 2018 // Check if the last instruction in the function was terminating.
2011 if (!InstIsTerminating) { 2019 if (!InstIsTerminating) {
2012 Error("Last instruction in function not terminator"); 2020 Error("Last instruction in function not terminator");
2013 if (isIRGenerationDisabled()) 2021 if (isIRGenerationDisabled())
2014 return; 2022 return;
2015 // Recover by inserting an unreachable instruction. 2023 // Recover by inserting an unreachable instruction.
2016 CurrentNode->appendInst(Ice::InstUnreachable::create(Func.get())); 2024 CurrentNode->appendInst(Ice::InstUnreachable::create(Func.get()));
2017 } 2025 }
2018 ++CurrentBbIndex; 2026 ++CurrentBbIndex;
(...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after
3171 } 3179 }
3172 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { 3180 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) {
3173 ErrStream 3181 ErrStream
3174 << IRFilename 3182 << IRFilename
3175 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; 3183 << ": Bitcode stream should be a multiple of 4 bytes in length.\n";
3176 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); 3184 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes");
3177 } 3185 }
3178 } 3186 }
3179 3187
3180 } // end of namespace Ice 3188 } // 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