]> gcc.gnu.org Git - gcc.git/commit
compiler: do order_evaluations before remove_shortcuts
authorIan Lance Taylor <ian@gcc.gnu.org>
Fri, 20 Jul 2018 19:56:21 +0000 (19:56 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Fri, 20 Jul 2018 19:56:21 +0000 (19:56 +0000)
commitd9a81cdb415ff070289eda51d122663c62219330
tree090e83349d8f9d7e192730b2bcdbfe630a88edab
parent523a59ff86fb66df06dd3a9e29a24e59c3b7f9d8
compiler: do order_evaluations before remove_shortcuts

    In remove_shortcuts, the shortcut expressions (&&, ||) are
    rewritten to if statements, which are lifted out before the
    statement containing the shortcut expression. If the containing
    statement has other (sub)expressions that should be evaluated
    before the shortcut expression, which has not been lifted out,
    this will result in wrong evaluation order.

    For example, F() + G(A() && B()), the evaluation order per spec
    is F, A, B (if A returns true), G. If we lift A() and B() out
    first, they will be called before F, which is wrong.

    To fix this, we split order_evaluations to two phases. The first
    phase, which runs before remove_shortcuts, skips shortcut
    expressions' components. So it won't lift out subexpressions that
    are evaluated conditionally. The shortcut expression itself is
    ordered, since it may have side effects. Then we run
    remove_shortcuts. At this point the subexpressions that should be
    evaluated before the shortcut expression are already lifted out.
    remove_shortcuts also runs the second phase of order_evaluations
    to order the components of shortcut expressions, which were
    skipped during the first phase.

    Reorder the code blocks of remove_shortcuts and order_evaluations,
    since remove_shortcuts now calls Order_eval.

    Fixes golang/go#26495.

    Reviewed-on: https://go-review.googlesource.com/125299

From-SVN: r262908
gcc/go/gofrontend/MERGE
gcc/go/gofrontend/go.cc
gcc/go/gofrontend/gogo.cc
This page took 0.057129 seconds and 5 git commands to generate.