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