commit c7a952858e846738ee9983796a20585b6635429c
Author: Aaron Merey <amerey@redhat.com>
Date: Wed Jun 20 18:26:36 2018 -0400
bpf translator: binary operations now act on copy of left operand.
Needed for cases where evaluating right operand causes side effects that
mutate the left (ex. x + x++).
diff --git a/bpf-translate.cxx b/bpf-translate.cxx
index fd9021e70..adfef97a5 100644
--- a/bpf-translate.cxx
+++ b/bpf-translate.cxx
@@ -1008,7 +1008,11 @@ bpf_unparser::visit_binary_expression (binary_expression* e)
else
throw SEMANTIC_ERROR (_("unhandled binary operator"), e->tok);
- value *s0 = emit_expr (e->left);
+ value *s0 = this_prog.new_reg();
+ // copy e->left into a seperate reg incase evaluating e->right
+ // causes e->left to mutate (ex. x + x++).
+ this_prog.mk_mov(this_ins, s0, emit_expr (e->left));
+
value *s1 = emit_expr (e->right);
value *d = this_prog.new_reg ();
this_prog.mk_binary (this_ins, code, d, s0, s1);