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

@shlWithOverflow produces incorrect results when used at comptime #948

Closed
tgschultz opened this Issue Apr 23, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@tgschultz
Contributor

tgschultz commented Apr 23, 2018

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

test "comptime shlWithOverflow" {
    const ct_shifted: u64 = comptime amt: {
        var amt = u64(0);
        _ = @shlWithOverflow(u64, ~u64(0), 16, &amt);
        break :amt amt;
    };
    
    const rt_shifted: u64 = amt: {
        var amt = u64(0);
        _ = @shlWithOverflow(u64, ~u64(0), 16, &amt);
        break :amt amt;
    };
    
    //debug.warn("\nct: {x}, rt: {x}\n", ct_shifted, rt_shifted);
    debug.assert(ct_shifted == rt_shifted);
}

Assertion will fail. Uncomment the warn line to see that the comptime version produces undefined result.

@andrewrk andrewrk added the bug label Apr 23, 2018

@andrewrk andrewrk added this to the 0.3.0 milestone Apr 23, 2018

@andrewrk andrewrk closed this in 89a4c37 Apr 23, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment