summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2019-06-14 07:18:51 +0100
committerGitHub <noreply@github.com>2019-06-14 07:18:51 +0100
commit5292179afc6fd0dc533add054d4790773c9766d0 (patch)
tree92cb11639e7834233f8d83a112d8d7d0491513f2 /Python
parent6a433f5ae63de72a85d20b05ff826c6f72d529b7 (diff)
downloadcpython-git-5292179afc6fd0dc533add054d4790773c9766d0.tar.gz
[3.7] bpo-37269: Correctly optimise conditionals with constant booleans (GH-14071) (GH-14073)
Fix a regression introduced by af8646c8054d0f4180a2013383039b6a472f9698 that was causing code of the form: if True and False: do_something() to be optimized incorrectly, eliminating the block.. (cherry picked from commit 05f831865545b08c9a21cfb7773af58b76ec64cb) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Python')
-rw-r--r--Python/peephole.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/Python/peephole.c b/Python/peephole.c
index 1ae62fa39a..f1b71ed1a7 100644
--- a/Python/peephole.c
+++ b/Python/peephole.c
@@ -313,6 +313,11 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
fill_nops(codestr, op_start, nexti + 1);
cumlc = 0;
} else if (is_true == 0) {
+ if (i > 1 &&
+ (_Py_OPCODE(codestr[i - 1]) == POP_JUMP_IF_TRUE ||
+ _Py_OPCODE(codestr[i - 1]) == POP_JUMP_IF_FALSE)) {
+ break;
+ }
h = get_arg(codestr, nexti) / sizeof(_Py_CODEUNIT);
tgt = find_op(codestr, codelen, h);
fill_nops(codestr, op_start, tgt);