authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-08 23:02:13-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-08 23:02:13-07:00
logf4fa32a63219917e8fb26f43cbd2d97b17e0aeee
tree6d5e038f63591104b437c663e86c6ef3a7d6c6a6
parent1678825c1450b29a1016bba62511388b3e539cd8

Sema: fix `@typeInfo` for pointers returning 0 alignment


3 files changed, 7 insertions(+), 12 deletions(-)

src/Sema.zig+6-1
......@@ -9651,6 +9651,11 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
96519651 },
96529652 .Pointer => {
96539653 const info = ty.ptrInfo().data;
9654 const alignment = if (info.@"align" != 0)
9655 info.@"align"
9656 else
9657 info.pointee_type.abiAlignment(target);
9658
96549659 const field_values = try sema.arena.alloc(Value, 8);
96559660 // size: Size,
96569661 field_values[0] = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(info.size));
......@@ -9659,7 +9664,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
96599664 // is_volatile: bool,
96609665 field_values[2] = if (info.@"volatile") Value.@"true" else Value.@"false";
96619666 // alignment: comptime_int,
9662 field_values[3] = try Value.Tag.int_u64.create(sema.arena, info.@"align");
9667 field_values[3] = try Value.Tag.int_u64.create(sema.arena, alignment);
96639668 // address_space: AddressSpace
96649669 field_values[4] = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(info.@"addrspace"));
96659670 // child: type,
src/type.zig+1-1
......@@ -4687,7 +4687,7 @@ pub const Type = extern union {
46874687 pub const Data = struct {
46884688 pointee_type: Type,
46894689 sentinel: ?Value = null,
4690 /// If zero use pointee_type.AbiAlign()
4690 /// If zero use pointee_type.abiAlignment()
46914691 @"align": u32 = 0,
46924692 /// See src/target.zig defaultAddressSpace function for how to obtain
46934693 /// an appropriate value for this field.
test/behavior/type_info.zig-10
......@@ -71,8 +71,6 @@ fn testBasic() !void {
7171}
7272
7373test "type info: pointer type info" {
74 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
75
7674 try testPointer();
7775 comptime try testPointer();
7876}
......@@ -89,8 +87,6 @@ fn testPointer() !void {
8987}
9088
9189test "type info: unknown length pointer type info" {
92 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
93
9490 try testUnknownLenPtr();
9591 comptime try testUnknownLenPtr();
9692}
......@@ -125,8 +121,6 @@ fn testNullTerminatedPtr() !void {
125121}
126122
127123test "type info: slice type info" {
128 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
129
130124 try testSlice();
131125 comptime try testSlice();
132126}
......@@ -306,8 +300,6 @@ const TestStruct = packed struct {
306300};
307301
308302test "type info: opaque info" {
309 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
310
311303 try testOpaque();
312304 comptime try testOpaque();
313305}
......@@ -417,8 +409,6 @@ test "type info: TypeId -> TypeInfo impl cast" {
417409}
418410
419411test "sentinel of opaque pointer type" {
420 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
421
422412 const c_void_info = @typeInfo(*anyopaque);
423413 try expect(c_void_info.Pointer.sentinel == null);
424414}