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

Unified Diff: src/PNaClTranslator.cpp

Issue 1210013005: Fixes case where terminator instruction is missing at end of function. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: fix nits. Created 5 years, 6 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 | « pydir/run-pnacl-sz.py ('k') | tests_lit/lit.cfg » ('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 5382bcc7f8f5a12835e686fde60e5a6b437bc876..fea11d0239c544a8f9f570bc4e21aa641a3c7676 100644
--- a/src/PNaClTranslator.cpp
+++ b/src/PNaClTranslator.cpp
@@ -1961,9 +1961,16 @@ private:
};
void FunctionParser::ExitBlock() {
- if (isIRGenerationDisabled()) {
- return;
+ // Check if the last instruction in the function was terminating.
+ if (!InstIsTerminating) {
+ Error("Last instruction in function not terminator");
+ if (isIRGenerationDisabled())
+ return;
+ // Recover by inserting an unreachable instruction.
+ CurrentNode->appendInst(Ice::InstUnreachable::create(Func.get()));
}
+ if (isIRGenerationDisabled())
+ return;
// Before translating, check for blocks without instructions, and
// insert unreachable. This shouldn't happen, but be safe.
size_t Index = 0;
@@ -2256,6 +2263,7 @@ void FunctionParser::ProcessRecord() {
}
case naclbitc::FUNC_CODE_INST_RET: {
// RET: [opval?]
+ InstIsTerminating = true;
if (!isValidRecordSizeInRange(0, 1, "return"))
return;
if (Values.empty()) {
@@ -2270,10 +2278,10 @@ void FunctionParser::ProcessRecord() {
}
CurrentNode->appendInst(Ice::InstRet::create(Func.get(), RetVal));
}
- InstIsTerminating = true;
return;
}
case naclbitc::FUNC_CODE_INST_BR: {
+ InstIsTerminating = true;
if (Values.size() == 1) {
// BR: [bb#]
if (isIRGenerationDisabled())
@@ -2306,7 +2314,6 @@ void FunctionParser::ProcessRecord() {
CurrentNode->appendInst(
Ice::InstBr::create(Func.get(), Cond, ThenBlock, ElseBlock));
}
- InstIsTerminating = true;
return;
}
case naclbitc::FUNC_CODE_INST_SWITCH: {
@@ -2318,6 +2325,7 @@ void FunctionParser::ProcessRecord() {
// unnecesary data fields (i.e. constants 1). These were not
// cleaned up in PNaCl bitcode because the bitcode format was
// already frozen when the problem was noticed.
+ InstIsTerminating = true;
if (!isValidRecordSizeAtLeast(4, "switch"))
return;
@@ -2383,17 +2391,16 @@ void FunctionParser::ProcessRecord() {
if (isIRGenDisabled)
return;
CurrentNode->appendInst(Switch);
- InstIsTerminating = true;
return;
}
case naclbitc::FUNC_CODE_INST_UNREACHABLE: {
// UNREACHABLE: []
+ InstIsTerminating = true;
if (!isValidRecordSize(0, "unreachable"))
return;
if (isIRGenerationDisabled())
return;
CurrentNode->appendInst(Ice::InstUnreachable::create(Func.get()));
- InstIsTerminating = true;
return;
}
case naclbitc::FUNC_CODE_INST_PHI: {
« no previous file with comments | « pydir/run-pnacl-sz.py ('k') | tests_lit/lit.cfg » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698