Commit 50d2354a authored by mdempsky's avatar mdempsky Committed by Commit bot

sandbox/linux/bpf_dsl: eliminate implicit dependency on C++ compiler behavior

For the expression F(G(), H()), C++ does not guarantee whether G() or
H() will be evaluated first.  Apparently the system compiler on Chrome
OS makes a different decision than on Ubuntu, which causes the golden
file tests introduced by https://crrev.com/1306723002 (which were
generated on Ubuntu) to fail on Chrome OS.

Easy fix: rewrite the expression as

    g = G()
    h = H()
    F(g, h)

to avoid any compiler behavior dependency.

BUG=529480

Review URL: https://codereview.chromium.org/1327693005

Cr-Commit-Position: refs/heads/master@{#347838}
parent 02d09c5f
......@@ -118,8 +118,11 @@ class IfThenResultExprImpl : public internal::ResultExprImpl {
: cond_(cond), then_result_(then_result), else_result_(else_result) {}
CodeGen::Node Compile(PolicyCompiler* pc) const override {
return cond_->Compile(
pc, then_result_->Compile(pc), else_result_->Compile(pc));
// We compile the "then" and "else" expressions in separate statements so
// they have a defined sequencing. See https://crbug.com/529480.
CodeGen::Node then_node = then_result_->Compile(pc);
CodeGen::Node else_node = else_result_->Compile(pc);
return cond_->Compile(pc, then_node, else_node);
}
bool HasUnsafeTraps() const override {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment