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

Unified Diff: src/PNaClTranslator.cpp

Issue 1303003002: Fix handling unknown branches when parsing switch instructions. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix nit. Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests_lit/parse_errs/Inputs/bad-switch-case.tbc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/PNaClTranslator.cpp
diff --git a/src/PNaClTranslator.cpp b/src/PNaClTranslator.cpp
index 259c62e2007a0244771720a8796c6202adf26616..7368a2b89d3f1bca76f78acc79ddad7b0ded277f 100644
--- a/src/PNaClTranslator.cpp
+++ b/src/PNaClTranslator.cpp
@@ -2415,6 +2415,8 @@ void FunctionParser::ProcessRecord() {
}
Ice::CfgNode *DefaultLabel =
isIRGenDisabled ? nullptr : getBranchBasicBlock(Values[2]);
+ if (DefaultLabel == nullptr)
+ return;
uint64_t NumCasesRaw = Values[3];
if (NumCasesRaw > std::numeric_limits<uint32_t>::max()) {
std::string Buffer;
@@ -2428,10 +2430,10 @@ void FunctionParser::ProcessRecord() {
// Now recognize each of the cases.
if (!isValidRecordSize(4 + NumCases * 4, "switch"))
return;
- Ice::InstSwitch *Switch =
- isIRGenDisabled
- ? nullptr
- : Ice::InstSwitch::create(Func.get(), NumCases, Cond, DefaultLabel);
+ std::unique_ptr<Ice::InstSwitch> Switch(
+ isIRGenDisabled ? nullptr
+ : Ice::InstSwitch::create(Func.get(), NumCases, Cond,
+ DefaultLabel));
unsigned ValCaseIndex = 4; // index to beginning of case entry.
for (uint32_t CaseIndex = 0; CaseIndex < NumCases;
++CaseIndex, ValCaseIndex += 4) {
@@ -2448,11 +2450,13 @@ void FunctionParser::ProcessRecord() {
if (isIRGenDisabled)
continue;
Ice::CfgNode *Label = getBranchBasicBlock(Values[ValCaseIndex + 3]);
+ if (Label == nullptr)
+ return;
Switch->addBranch(CaseIndex, Value.getSExtValue(), Label);
}
if (isIRGenDisabled)
return;
- CurrentNode->appendInst(Switch);
+ CurrentNode->appendInst(Switch.release());
return;
}
case naclbitc::FUNC_CODE_INST_UNREACHABLE: {
« no previous file with comments | « no previous file | tests_lit/parse_errs/Inputs/bad-switch-case.tbc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698