Skip to content

Commit

Permalink
sandbox/linux/bpf_dsl: eliminate implicit dependency on C++ compiler …
Browse files Browse the repository at this point in the history
…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}
  • Loading branch information
mdempsky authored and Commit bot committed Sep 8, 2015
1 parent 02d09c5 commit 50d2354
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions sandbox/linux/bpf_dsl/bpf_dsl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 50d2354

Please sign in to comment.