Open michalsieron opened 2 years ago
If I change MyPackedStruct
to have two u16
fields instead I get:
for Fast
and Small
0000000000000010 <packed_assign_with_undefined>:
10: 66 c7 07 02 00 movw $0x2,(%rdi)
15: c3 ret
and for Safe
0000000000000010 <packed_assign_with_undefined>:
10: c7 07 02 00 aa aa movl $0xaaaa0002,(%rdi)
16: c3 ret
When I change packed_assign_with_undefined
to assign undefined
to both fields I get:
for Fast
and Small
for both original and two u16
fields versions of MyPackedStruct
0000000000000010 <packed_assign_with_undefined>:
10: c3 ret
for Safe
for original MyPackedStruct
definition
0000000000000010 <packed_assign_with_undefined>:
10: c7 07 00 00 00 00 movl $0x0,(%rdi)
16: c3 ret
and for Safe
for MyPackedStruct
definition with two u16
fields
0000000000000010 <packed_assign_with_undefined>:
10: c7 07 aa aa aa aa movl $0xaaaaaaaa,(%rdi)
16: c3 ret
It's kinda weird, because in both cases we 'assign' 32 bits of undefined data and yet Safe
mode behaves differently.
If I force packed_assign_with_undefined
to compute value to assign in comptime
then all modes generate correct code
export fn packed_assign_with_undefined(x: *MyPackedStruct) void {
x.* = comptime blk: {
break :blk MyPackedStruct{ .field1 = 2, .field2 = undefined };
};
}
both u17/u15
and u16/u16
MyPackedStruct
definitions, all modes:
0000000000000010 <packed_assign_with_undefined>:
10: c7 07 02 00 00 00 movl $0x2,(%rdi)
16: c3 ret
changing packed_assign_with_undefined
to assign undefined
to both fields (still computed in comptime
):
both u17/u15
and u16/u16
MyPackedStruct
definitions, Fast
and Small
modes:
0000000000000010 <packed_assign_with_undefined>:
10: c3 ret
both u17/u15
and u16/u16
MyPackedStruct
definitions, Safe
mode:
0000000000000010 <packed_assign_with_undefined>:
10: c7 07 aa aa aa aa movl $0xaaaaaaaa,(%rdi)
16: c3 ret
Packed structs work differently now and these produce the expected result except that safe modes don't set the bytes to 0xAA
.
Zig Version
0.10.0-dev.1933+5f2d0d414
Steps to Reproduce
Compile following code with
and then run
objdump -d safe.o small.o fast.o
Expected Behavior
All of compiled examples have the same or similar code. Or at least code that makes sense.
Actual Behavior
Fast
andSmall
modes for some reason set undefined bits to 1. They also do it inefficientlySafe
mode doesn't set undefined bytes to0xaa
.