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(...@@ -8778,13 +8778,20 @@ fn structFieldPtr(
8778 const arena = sema.arena;8778 const arena = sema.arena;
8779 assert(unresolved_struct_ty.zigTypeTag() == .Struct);8779 assert(unresolved_struct_ty.zigTypeTag() == .Struct);
87808780
8781 const struct_ptr_ty = sema.typeOf(struct_ptr);
8781 const struct_ty = try sema.resolveTypeFields(block, src, unresolved_struct_ty);8782 const struct_ty = try sema.resolveTypeFields(block, src, unresolved_struct_ty);
8782 const struct_obj = struct_ty.castTag(.@"struct").?.data;8783 const struct_obj = struct_ty.castTag(.@"struct").?.data;
87838784
8784 const field_index = struct_obj.fields.getIndex(field_name) orelse8785 const field_index = struct_obj.fields.getIndex(field_name) orelse
8785 return sema.failWithBadFieldAccess(block, struct_obj, field_name_src, field_name);8786 return sema.failWithBadFieldAccess(block, struct_obj, field_name_src, field_name);
8786 const field = struct_obj.fields.values()[field_index];8787 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
8789 if (try sema.resolveDefinedValue(block, src, struct_ptr)) |struct_ptr_val| {8796 if (try sema.resolveDefinedValue(block, src, struct_ptr)) |struct_ptr_val| {
8790 return sema.addConstant(8797 return sema.addConstant(
...@@ -8875,6 +8882,7 @@ fn unionFieldPtr(...@@ -8875,6 +8882,7 @@ fn unionFieldPtr(
8875 const arena = sema.arena;8882 const arena = sema.arena;
8876 assert(unresolved_union_ty.zigTypeTag() == .Union);8883 assert(unresolved_union_ty.zigTypeTag() == .Union);
88778884
8885 const union_ptr_ty = sema.typeOf(union_ptr);
8878 const union_ty = try sema.resolveTypeFields(block, src, unresolved_union_ty);8886 const union_ty = try sema.resolveTypeFields(block, src, unresolved_union_ty);
8879 const union_obj = union_ty.cast(Type.Payload.Union).?.data;8887 const union_obj = union_ty.cast(Type.Payload.Union).?.data;
88808888
...@@ -8882,7 +8890,13 @@ fn unionFieldPtr(...@@ -8882,7 +8890,13 @@ fn unionFieldPtr(
8882 return sema.failWithBadUnionFieldAccess(block, union_obj, field_name_src, field_name);8890 return sema.failWithBadUnionFieldAccess(block, union_obj, field_name_src, field_name);
88838891
8884 const field = union_obj.fields.values()[field_index];8892 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
8887 if (try sema.resolveDefinedValue(block, src, union_ptr)) |union_ptr_val| {8901 if (try sema.resolveDefinedValue(block, src, union_ptr)) |union_ptr_val| {
8888 // TODO detect inactive union field and emit compile error8902 // TODO detect inactive union field and emit compile error