Skip to content

stage2: Copied array element aliases with source #13064

@topolarity

Description

@topolarity

Zig Version

0.10.0-dev.4217+9d8cdb855

Steps to Reproduce

const std = @import("std");
const expect = std.testing.expect;

test {
    var x: [10][10]u32 = undefined;

    x[0][1] = 0;
    const a = x[0];
    x[0][1] = 15;

    try expect(a[1] == 0);
}

Expected Behavior

Test should pass (passes in stage1).

Actual Behavior

error: TestUnexpectedResult
/Users/toadman667/repos/zig/lib/std/testing.zig:347:14: 0x10448d83f in expect (test4)
    if (!ok) return error.TestUnexpectedResult;
             ^
./test4.zig:41:5: 0x10448d9d2 in main (test4)
    try expect(a[1] == 0);
    ^

The problem is that .array_elem_val returns a pointer to the element without doing a side effect check like what's done in airLoad

Metadata

Metadata

Assignees

Labels

backend-llvmThe LLVM backend outputs an LLVM IR Module.bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.regressionIt worked in a previous version of Zig, but stopped working.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions