authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-08-26 04:16:36+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-09-20 02:29:03+02:00
log538f1bbcb35c10fb0aa633adbac64932cc89d034
tree5f73b1f3bd41fb7285d4b10f9c07468956c06ba7
parent497c0d3783c6a11cc64eaff72be050ce09a0ac13

Address Spaces: Return proper address space for &x.y


1 files changed, 16 insertions(+), 2 deletions(-)

src/Sema.zig+16-2
......@@ -8778,13 +8778,20 @@ fn structFieldPtr(
87788778 const arena = sema.arena;
87798779 assert(unresolved_struct_ty.zigTypeTag() == .Struct);
87808780
8781 const struct_ptr_ty = sema.typeOf(struct_ptr);
87818782 const struct_ty = try sema.resolveTypeFields(block, src, unresolved_struct_ty);
87828783 const struct_obj = struct_ty.castTag(.@"struct").?.data;
87838784
87848785 const field_index = struct_obj.fields.getIndex(field_name) orelse
87858786 return sema.failWithBadFieldAccess(block, struct_obj, field_name_src, field_name);
87868787 const field = struct_obj.fields.values()[field_index];
8787 const ptr_field_ty = try Module.simplePtrType(arena, field.ty, true, .One);
8788 const ptr_field_ty = try Module.simplePtrTypeWithAddressSpace(
8789 arena,
8790 field.ty,
8791 struct_ptr_ty.ptrIsMutable(),
8792 .One,
8793 struct_ptr_ty.ptrAddressSpace(),
8794 );
87888795
87898796 if (try sema.resolveDefinedValue(block, src, struct_ptr)) |struct_ptr_val| {
87908797 return sema.addConstant(
......@@ -8875,6 +8882,7 @@ fn unionFieldPtr(
88758882 const arena = sema.arena;
88768883 assert(unresolved_union_ty.zigTypeTag() == .Union);
88778884
8885 const union_ptr_ty = sema.typeOf(union_ptr);
88788886 const union_ty = try sema.resolveTypeFields(block, src, unresolved_union_ty);
88798887 const union_obj = union_ty.cast(Type.Payload.Union).?.data;
88808888
......@@ -8882,7 +8890,13 @@ fn unionFieldPtr(
88828890 return sema.failWithBadUnionFieldAccess(block, union_obj, field_name_src, field_name);
88838891
88848892 const field = union_obj.fields.values()[field_index];
8885 const ptr_field_ty = try Module.simplePtrType(arena, field.ty, true, .One);
8893 const ptr_field_ty = try Module.simplePtrTypeWithAddressSpace(
8894 arena,
8895 field.ty,
8896 union_ptr_ty.ptrIsMutable(),
8897 .One,
8898 union_ptr_ty.ptrAddressSpace(),
8899 );
88868900
88878901 if (try sema.resolveDefinedValue(block, src, union_ptr)) |union_ptr_val| {
88888902 // TODO detect inactive union field and emit compile error