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

Incorrect evaluation precedence for bitwise operators #1902

Open
tgschultz opened this issue Jan 30, 2019 · 4 comments
Open

Incorrect evaluation precedence for bitwise operators #1902

tgschultz opened this issue Jan 30, 2019 · 4 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. miscompilation The compiler reports success but produces semantically incorrect code.
Milestone

Comments

@tgschultz
Copy link
Contributor

tgschultz commented Jan 30, 2019

According to the documentation, bitwise operator precedence is as follows:

  • ~x
  • << >>
  • &
  • ^
  • |

However, this changed at some point, causing the following test to fail:

const std = @import("std");
const debug = std.debug;

test "" {
    var x = u16(0xFF00);
    x = x | u8(0xFF) & 0x0F;
    debug.assert(x == 0xFF0F);
}
@andrewrk andrewrk added this to the 0.4.0 milestone Jan 30, 2019
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Jan 30, 2019
@andrewrk
Copy link
Member

Related #114

@markfirmware
Copy link
Contributor

markfirmware/zig-bare-metal-microbit#10

What would be needed to get | and & to evaluate as specified? Thanks, Mark.

@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Feb 10, 2020
@markfirmware
Copy link
Contributor

@tgschultz @andrewrk I think this should be labeled miscompilation.

@andrewrk andrewrk added the miscompilation The compiler reports success but produces semantically incorrect code. label Feb 26, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.6.0 Feb 26, 2020
@andrewrk
Copy link
Member

It's planned for this to be a compile error; one must use parentheses for this. #114

@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Apr 8, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 30, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@andrewrk andrewrk modified the milestones: 0.14.0, 0.11.0 Jul 22, 2023
@andrewrk andrewrk added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Jul 27, 2023
@andrewrk andrewrk modified the milestones: 0.11.0, 0.11.1 Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. miscompilation The compiler reports success but produces semantically incorrect code.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants