From 95e0cc06a2c0954499691528672e549383fba6f1 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 21 Sep 2021 12:05:55 +0200 Subject: [PATCH] Fix missing undef checks for comparisons --- ext/opcache/jit/zend_jit_x86.dasc | 24 ++++++------- ext/opcache/tests/jit/cmp_006.phpt | 57 ++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 ext/opcache/tests/jit/cmp_006.phpt diff --git a/ext/opcache/jit/zend_jit_x86.dasc b/ext/opcache/jit/zend_jit_x86.dasc index 2b3d4869424..9c3e77a56a8 100644 --- a/ext/opcache/jit/zend_jit_x86.dasc +++ b/ext/opcache/jit/zend_jit_x86.dasc @@ -7697,19 +7697,19 @@ static int zend_jit_cmp(dasm_State **Dst, (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE)))); if ((op1_info & MAY_BE_LONG) && (op2_info & MAY_BE_LONG)) { - if (op1_info & (MAY_BE_ANY-MAY_BE_LONG)) { + if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG)) { if (op1_info & MAY_BE_DOUBLE) { | IF_NOT_ZVAL_TYPE op1_addr, IS_LONG, >4 } else { | IF_NOT_ZVAL_TYPE op1_addr, IS_LONG, >9 } } - if (!same_ops && (op2_info & (MAY_BE_ANY-MAY_BE_LONG))) { + if (!same_ops && (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG))) { if (op2_info & MAY_BE_DOUBLE) { | IF_NOT_ZVAL_TYPE op2_addr, IS_LONG, >3 |.cold_code |3: - if (op2_info & (MAY_BE_ANY-(MAY_BE_LONG|MAY_BE_DOUBLE))) { + if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))) { | IF_NOT_ZVAL_TYPE op2_addr, IS_DOUBLE, >9 } if (!zend_jit_cmp_long_double(Dst, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr)) { @@ -7727,11 +7727,11 @@ static int zend_jit_cmp(dasm_State **Dst, if (op1_info & MAY_BE_DOUBLE) { |.cold_code |4: - if (op1_info & (MAY_BE_ANY-(MAY_BE_LONG|MAY_BE_DOUBLE))) { + if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))) { | IF_NOT_ZVAL_TYPE op1_addr, IS_DOUBLE, >9 } if (op2_info & MAY_BE_DOUBLE) { - if (!same_ops && (op2_info & (MAY_BE_ANY-MAY_BE_DOUBLE))) { + if (!same_ops && (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE))) { if (!same_ops) { | IF_NOT_ZVAL_TYPE op2_addr, IS_DOUBLE, >5 } else { @@ -7745,7 +7745,7 @@ static int zend_jit_cmp(dasm_State **Dst, } if (!same_ops) { |5: - if (op2_info & (MAY_BE_ANY-(MAY_BE_LONG|MAY_BE_DOUBLE))) { + if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))) { | IF_NOT_ZVAL_TYPE op2_addr, IS_LONG, >9 } if (!zend_jit_cmp_double_long(Dst, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr)) { @@ -7758,11 +7758,11 @@ static int zend_jit_cmp(dasm_State **Dst, } else if ((op1_info & MAY_BE_DOUBLE) && !(op1_info & MAY_BE_LONG) && (op2_info & (MAY_BE_LONG|MAY_BE_DOUBLE))) { - if (op1_info & (MAY_BE_ANY-MAY_BE_DOUBLE)) { + if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE)) { | IF_NOT_ZVAL_TYPE op1_addr, IS_DOUBLE, >9 } if (op2_info & MAY_BE_DOUBLE) { - if (!same_ops && (op2_info & (MAY_BE_ANY-MAY_BE_DOUBLE))) { + if (!same_ops && (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE))) { if (!same_ops && (op2_info & MAY_BE_LONG)) { | IF_NOT_ZVAL_TYPE op2_addr, IS_DOUBLE, >3 } else { @@ -7778,7 +7778,7 @@ static int zend_jit_cmp(dasm_State **Dst, |.cold_code } |3: - if (op2_info & (MAY_BE_ANY-(MAY_BE_DOUBLE|MAY_BE_LONG))) { + if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_DOUBLE|MAY_BE_LONG))) { | IF_NOT_ZVAL_TYPE op2_addr, IS_LONG, >9 } if (!zend_jit_cmp_double_long(Dst, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr)) { @@ -7792,11 +7792,11 @@ static int zend_jit_cmp(dasm_State **Dst, } else if ((op2_info & MAY_BE_DOUBLE) && !(op2_info & MAY_BE_LONG) && (op1_info & (MAY_BE_LONG|MAY_BE_DOUBLE))) { - if (op2_info & (MAY_BE_ANY-MAY_BE_DOUBLE)) { + if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE)) { | IF_NOT_ZVAL_TYPE op2_addr, IS_DOUBLE, >9 } if (op1_info & MAY_BE_DOUBLE) { - if (!same_ops && (op1_info & (MAY_BE_ANY-MAY_BE_DOUBLE))) { + if (!same_ops && (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE))) { if (!same_ops && (op1_info & MAY_BE_LONG)) { | IF_NOT_ZVAL_TYPE op1_addr, IS_DOUBLE, >3 } else { @@ -7812,7 +7812,7 @@ static int zend_jit_cmp(dasm_State **Dst, |.cold_code } |3: - if (op1_info & (MAY_BE_ANY-(MAY_BE_DOUBLE|MAY_BE_LONG))) { + if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_DOUBLE|MAY_BE_LONG))) { | IF_NOT_ZVAL_TYPE op1_addr, IS_LONG, >9 } if (!zend_jit_cmp_long_double(Dst, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr)) { diff --git a/ext/opcache/tests/jit/cmp_006.phpt b/ext/opcache/tests/jit/cmp_006.phpt new file mode 100644 index 00000000000..aeaab458520 --- /dev/null +++ b/ext/opcache/tests/jit/cmp_006.phpt @@ -0,0 +1,57 @@ +--TEST-- +JIT CMP: 006 Undefined variable checks +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_update_protection=0 +opcache.jit_buffer_size=1M +opcache.protect_memory=1 +--FILE-- + +--EXPECTF-- +Warning: Undefined variable $x in %s on line %d +bool(false) + +Warning: Undefined variable $x in %s on line %d +bool(false) + +Warning: Undefined variable $y in %s on line %d +bool(false) + +Warning: Undefined variable $y in %s on line %d +bool(false)