diff -r ece75a3b942c -r dcf0fdad8f68 Python/peephole.c --- a/Python/peephole.c Wed Dec 05 17:59:29 2012 +0200 +++ b/Python/peephole.c Wed Dec 05 22:30:28 2012 +0100 @@ -418,13 +418,20 @@ codestr = (unsigned char *)memcpy(codestr, PyBytes_AS_STRING(code), codelen); - /* Verify that RETURN_VALUE terminates the codestring. This allows - the various transformation patterns to look ahead several - instructions without additional checks to make sure they are not - looking beyond the end of the code string. + /* Verify that RETURN_VALUE terminates the codestring. If not, strip + strip unreachable code out. This allows the various transformation + patterns to look ahead several instructions without additional checks + to make sure they are not looking beyond the end of the code string. */ - if (codestr[codelen-1] != RETURN_VALUE) - goto exitUnchanged; + if (codestr[codelen-1] != RETURN_VALUE){ + for (i=codelen-1; i>=0; i--){ + if (codestr[i] == RETURN_VALUE) + break; + } + if (i == 0) + goto exitUnchanged; + codelen = i+1; + } /* Mapping to new jump targets after NOPs are removed */ addrmap = (int *)PyMem_Malloc(codelen * sizeof(int));