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

comptime code can incorrectly modify constant data #1076

andrewrk opened this Issue Jun 8, 2018 · 0 comments


None yet
1 participant

andrewrk commented Jun 8, 2018

Remove the ++ as described by the TODO comment to reveal the bug.

test "single-item pointer of array to slice and to unknown length pointer" {
    comptime testCastPtrOfArrayToSliceAndPtr();

fn testCastPtrOfArrayToSliceAndPtr() void {
    var array = "ao" ++ "eu"; // TODO without the ++ this incorrectly modifies the global const
    const x: [*]u8 = &array;
    x[0] += 1;
    assert(mem.eql(u8, array[0..], "boeu"));
    const y: []u8 = &array;
    y[0] += 1;
    assert(mem.eql(u8, array[0..], "coeu"));

The test fails because the initializer for array gets incorrectly modified by the comptime invocation of the function, so that when we get to the runtime invocation, array starts off with the value boeu.

@andrewrk andrewrk added the bug label Jun 8, 2018

@andrewrk andrewrk added this to the 0.3.0 milestone Jun 8, 2018

@andrewrk andrewrk closed this in f8fe517 Sep 20, 2018

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