-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
Milestone
Description
Zig Version
0.12.0-dev.700+376242e58
Steps to Reproduce and Observed Behavior
const std = @import("std");
const testing = std.testing;
test "memset packed union" {
const U = packed union {
a: u32,
b: u8 align(8),
};
var u: U = undefined;
@memset(std.mem.asBytes(&u), 0x2a);
try testing.expectEqual(@as(u32, 0x2a2a2a2a), u.a);
try testing.expectEqual(@as(u8, 0x2a), u.b);
}$ zig test memset_packed.zig -O ReleaseFast
Test [1/1] test.memset packed union... expected 707406378, found 00
$ zig test memset_packed.zig
All 1 tests passed.
A few things seem to be required for this to happen:
- The
@memset. Replacing it withvar u: U = .{ .a = 0x2a2a2a2a };resolves the issue. - The alignment of the over-aligned field must be greater than the size of any other field. If you change the
align(8)toalign(4), or if you add au64field, the issue is resolved.
Expected Behavior
Consistent behaviour between Debug and Release*.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior