diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-02-08 23:02:13 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-02-08 23:02:13 -0700 |
| commit | f4fa32a63219917e8fb26f43cbd2d97b17e0aeee (patch) | |
| tree | 6d5e038f63591104b437c663e86c6ef3a7d6c6a6 | |
| parent | 1678825c1450b29a1016bba62511388b3e539cd8 (diff) | |
| download | zig-f4fa32a63219917e8fb26f43cbd2d97b17e0aeee.tar.gz zig-f4fa32a63219917e8fb26f43cbd2d97b17e0aeee.zip | |
Sema: fix `@typeInfo` for pointers returning 0 alignment
| -rw-r--r-- | src/Sema.zig | 7 | ||||
| -rw-r--r-- | src/type.zig | 2 | ||||
| -rw-r--r-- | test/behavior/type_info.zig | 10 |
3 files changed, 7 insertions, 12 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index b202cb696f..df5013fbaf 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -9651,6 +9651,11 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai }, .Pointer => { const info = ty.ptrInfo().data; + const alignment = if (info.@"align" != 0) + info.@"align" + else + info.pointee_type.abiAlignment(target); + const field_values = try sema.arena.alloc(Value, 8); // size: Size, 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 // is_volatile: bool, field_values[2] = if (info.@"volatile") Value.@"true" else Value.@"false"; // alignment: comptime_int, - field_values[3] = try Value.Tag.int_u64.create(sema.arena, info.@"align"); + field_values[3] = try Value.Tag.int_u64.create(sema.arena, alignment); // address_space: AddressSpace field_values[4] = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(info.@"addrspace")); // child: type, diff --git a/src/type.zig b/src/type.zig index e3a4b3d60a..769e48ccc5 100644 --- a/src/type.zig +++ b/src/type.zig @@ -4687,7 +4687,7 @@ pub const Type = extern union { pub const Data = struct { pointee_type: Type, sentinel: ?Value = null, - /// If zero use pointee_type.AbiAlign() + /// If zero use pointee_type.abiAlignment() @"align": u32 = 0, /// See src/target.zig defaultAddressSpace function for how to obtain /// an appropriate value for this field. diff --git a/test/behavior/type_info.zig b/test/behavior/type_info.zig index 14adc4dad5..9f90088ed9 100644 --- a/test/behavior/type_info.zig +++ b/test/behavior/type_info.zig @@ -71,8 +71,6 @@ fn testBasic() !void { } test "type info: pointer type info" { - if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO - try testPointer(); comptime try testPointer(); } @@ -89,8 +87,6 @@ fn testPointer() !void { } test "type info: unknown length pointer type info" { - if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO - try testUnknownLenPtr(); comptime try testUnknownLenPtr(); } @@ -125,8 +121,6 @@ fn testNullTerminatedPtr() !void { } test "type info: slice type info" { - if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO - try testSlice(); comptime try testSlice(); } @@ -306,8 +300,6 @@ const TestStruct = packed struct { }; test "type info: opaque info" { - if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO - try testOpaque(); comptime try testOpaque(); } @@ -417,8 +409,6 @@ test "type info: TypeId -> TypeInfo impl cast" { } test "sentinel of opaque pointer type" { - if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO - const c_void_info = @typeInfo(*anyopaque); try expect(c_void_info.Pointer.sentinel == null); } |
