Skip to content

stage2: Copied union field aliases with source #13065

@topolarity

Description

@topolarity

Zig Version

0.10.0-dev.4217+9d8cdb855

Steps to Reproduce

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

const U = union(enum) {
    array: [10]u32,
    other: u32,
};

test {
    var x = U{ .array = undefined };

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

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

In -O Debug, the .load of the overall union object is not elided because of an intervening union tag check, so this bug does not manifest. However, that elision would actually be correct and is applied in .ReleaseFast mode.

The incorrect part is that .struct_field_val returns a pointer to the union field without doing a side effect check like what's done in airLoad

Expected Behavior

Test should pass (like in stage1).

Actual Behavior

$ zig test test.zig  -O ReleaseFast
Test [1/1] test_0... FAIL (TestUnexpectedResult)
0 passed; 0 skipped; 1 failed.
error: the following test command failed with exit code 1:
/Users/toadman667/repos/zig/zig-cache/o/8907a365291a8522093c111f26d53494/test

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