Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bad logical-and implementation #131

Merged
merged 2 commits into from
Jul 7, 2024
Merged

Commits on Jul 7, 2024

  1. Fix bad logical-and implementation

    The previous implementation of the logical-and operation produced
    incorrect result. This implementation ensures the correctness of the
    logical-and behavior and guarantees left-to-right evaluation as
    mentioned in the C99 standard.
    
    Add new function, `read_log_and_operation` and `finalize_log_and`.
    
    `read_log_and_operation` is used when `read_expr` encounters
    `OP_log_and`. This function creates a new branch instruction to test the
    operand before `OP_log_and`, and then creates a new basic block for next
    expression.
    
    `finalize_log_and` is used when all operands are consumed or when an
    operator with lower priority than logical-and is encountered. This
    function create new basic blocks and new branchs to derive the final
    value (0 or 1) for the result of the logical-and operation, and then
    creates a new basic block for other new instructions.
    
    In `read_expr`, we provide data for the false branch of logical-and
    operation, including `else_bb` and `land_else_label`. All operands of
    logical-and operator are designed to branch to the same "else" basic
    block for the false branch.
    
    This commit adjusts the order of connecting the basic block during
    parsing `T_for` and `T_while`. This change ensures that basic blocks are
    connected correctly when the condition expression includes a logical-and
    operation.
    
    Resolve sysprog21#137
    nosba0957 committed Jul 7, 2024
    Configuration menu
    Copy the full SHA
    8e632e7 View commit details
    Browse the repository at this point in the history
  2. Fix incorrect phi node insertion/removal

    The current "prev" pointer of instruction doesn't be updated after
    inserting/removing the phi node. This causes the unexpected result of
    phi node unwinding.
    vacantron authored and nosba0957 committed Jul 7, 2024
    Configuration menu
    Copy the full SHA
    43f02a7 View commit details
    Browse the repository at this point in the history