Skip to content

Commit

Permalink
py/emitnative: Explicitly compare comparison ops in binary_op emitter.
Browse files Browse the repository at this point in the history
Without this it's possible to get a compiler error about the comparison
always being true, because MP_BINARY_OP_LESS is 0.  And it seems that gcc
optimises these 6 equality comparisons into the same size machine code as
before.
  • Loading branch information
pepijndevos authored and dpgeorge committed Feb 26, 2023
1 parent 2e4dda3 commit 72e9318
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions py/emitnative.c
Original file line number Diff line number Diff line change
Expand Up @@ -2365,14 +2365,13 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) {
} else if (op == MP_BINARY_OP_MULTIPLY) {
ASM_MUL_REG_REG(emit->as, REG_ARG_2, reg_rhs);
emit_post_push_reg(emit, vtype_lhs, REG_ARG_2);
} else if (MP_BINARY_OP_LESS <= op && op <= MP_BINARY_OP_NOT_EQUAL) {
// comparison ops are (in enum order):
// MP_BINARY_OP_LESS
// MP_BINARY_OP_MORE
// MP_BINARY_OP_EQUAL
// MP_BINARY_OP_LESS_EQUAL
// MP_BINARY_OP_MORE_EQUAL
// MP_BINARY_OP_NOT_EQUAL
} else if (op == MP_BINARY_OP_LESS
|| op == MP_BINARY_OP_MORE
|| op == MP_BINARY_OP_EQUAL
|| op == MP_BINARY_OP_LESS_EQUAL
|| op == MP_BINARY_OP_MORE_EQUAL
|| op == MP_BINARY_OP_NOT_EQUAL) {
// comparison ops

if (vtype_lhs != vtype_rhs) {
EMIT_NATIVE_VIPER_TYPE_ERROR(emit, MP_ERROR_TEXT("comparison of int and uint"));
Expand Down

0 comments on commit 72e9318

Please sign in to comment.