Sema: preserve volatileness when constructing field pointers

Closes #12928
This commit is contained in:
Veikka Tuominen 2022-09-23 12:00:02 +03:00
parent cae76d8293
commit 8d1fdfc8ed
3 changed files with 30 additions and 0 deletions

View File

@ -22027,6 +22027,7 @@ fn structFieldPtrByIndex(
var ptr_ty_data: Type.Payload.Pointer.Data = .{
.pointee_type = field.ty,
.mutable = struct_ptr_ty_info.mutable,
.@"volatile" = struct_ptr_ty_info.@"volatile",
.@"addrspace" = struct_ptr_ty_info.@"addrspace",
};
@ -22246,6 +22247,7 @@ fn unionFieldPtr(
const ptr_field_ty = try Type.ptr(arena, sema.mod, .{
.pointee_type = field.ty,
.mutable = union_ptr_ty.ptrIsMutable(),
.@"volatile" = union_ptr_ty.isVolatilePtr(),
.@"addrspace" = union_ptr_ty.ptrAddressSpace(),
});
const enum_field_index = @intCast(u32, union_obj.tag_ty.enumFieldIndex(field_name).?);
@ -22568,6 +22570,7 @@ fn tupleFieldPtr(
const ptr_field_ty = try Type.ptr(sema.arena, sema.mod, .{
.pointee_type = field_ty,
.mutable = tuple_ptr_ty.ptrIsMutable(),
.@"volatile" = tuple_ptr_ty.isVolatilePtr(),
.@"addrspace" = tuple_ptr_ty.ptrAddressSpace(),
});

View File

@ -93,6 +93,7 @@ test {
_ = @import("behavior/bugs/12794.zig");
_ = @import("behavior/bugs/12801-1.zig");
_ = @import("behavior/bugs/12801-2.zig");
_ = @import("behavior/bugs/12928.zig");
_ = @import("behavior/byteswap.zig");
_ = @import("behavior/byval_arg_var.zig");
_ = @import("behavior/call.zig");

View File

@ -0,0 +1,26 @@
const std = @import("std");
const expect = std.testing.expect;
const A = extern struct {
value: *volatile B,
};
const B = extern struct {
a: u32,
b: i32,
};
test {
var a: *A = undefined;
try expect(@TypeOf(&a.value.a) == *volatile u32);
try expect(@TypeOf(&a.value.b) == *volatile i32);
}
const C = extern struct {
value: *volatile D,
};
const D = extern union {
a: u32,
b: i32,
};
test {
var c: *C = undefined;
try expect(@TypeOf(&c.value.a) == *volatile u32);
try expect(@TypeOf(&c.value.b) == *volatile i32);
}