codegen: fix taking the address of a zero-bit field in a zero-bit struct

Normally when we want a pointer to the end of a struct we just add 1 to
the struct pointer.  However, when it is a zero-bit struct, the pointer
type being used during lowering is often a dummy pointer type that
actually points to a non-zero-bit type, so we actually want to add 0
instead, since a zero-bit struct begins and ends at the same address.
This commit is contained in:
Jacob Young
2022-12-18 22:09:13 -05:00
parent 52e5c66025
commit 0e3feebb04
3 changed files with 30 additions and 9 deletions

View File

@@ -5131,7 +5131,9 @@ fn structFieldPtr(f: *Function, inst: Air.Inst.Index, struct_ptr_ty: Type, struc
.begin, .end => {
try writer.writeByte('(');
try f.writeCValue(writer, struct_ptr, .Other);
try writer.print(")[{}]", .{@boolToInt(field_loc == .end)});
try writer.print(")[{}]", .{
@boolToInt(field_loc == .end and struct_ty.hasRuntimeBitsIgnoreComptime()),
});
},
.field => |field| if (extra_name != .none) {
try f.writeCValueDerefMember(writer, struct_ptr, extra_name);