Skip to content

Shift binops appear to mutate their right operand. #152

@froystig

Description

@froystig

The following program:

fn main() {
  let uint b = 1u;
  while (b <= 32u) {
    0u << b;
    b <<= 1u;
    log b;
  }
}

Gives the following output:

rt: 8d08:main:main:                       rust: 2 (0x2)
rt: 8d08:main:main:                       rust: 8 (0x8)
rt: 8d08:main:main:                       rust: 2048 (0x800)

The shift-left 0u << b is necessary to make this happen, but 0u >> b and 0u >>> b suffice to reproduce the bug just as well. Also, changing b <<= 1u to b = b << 1u makes the bug go away.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions