Commit e0b6140009

Veikka Tuominen <git@vexu.eu>
2022-12-29 11:47:11
Type: fix printing of default alignment on non-byte aligned pointers
1 parent 8a6295f
src/type.zig
@@ -2195,7 +2195,12 @@ pub const Type = extern union {
                     .Slice => try writer.writeAll("[]"),
                 }
                 if (info.@"align" != 0 or info.host_size != 0 or info.vector_index != .none) {
-                    try writer.print("align({d}", .{info.@"align"});
+                    if (info.@"align" != 0) {
+                        try writer.print("align({d}", .{info.@"align"});
+                    } else {
+                        const alignment = info.pointee_type.abiAlignment(mod.getTarget());
+                        try writer.print("align({d}", .{alignment});
+                    }
 
                     if (info.bit_offset != 0 or info.host_size != 0) {
                         try writer.print(":{d}:{d}", .{ info.bit_offset, info.host_size });
test/cases/compile_errors/casting_bit_offset_pointer_to_regular_pointer.zig
@@ -18,7 +18,7 @@ export fn entry() usize { return @sizeOf(@TypeOf(&foo)); }
 // backend=stage2
 // target=native
 //
-// :8:16: error: expected type '*const u3', found '*align(0:3:1) const u3'
+// :8:16: error: expected type '*const u3', found '*align(1:3:1) const u3'
 // :8:16: note: pointer host size '1' cannot cast into pointer host size '0'
 // :8:16: note: pointer bit offset '3' cannot cast into pointer bit offset '0'
 // :11:11: note: parameter type declared here
test/cases/compile_errors/incompatible sub-byte fields.zig
@@ -24,4 +24,4 @@ export fn entry() void {
 // backend=stage2
 // target=native
 //
-// :14:17: error: incompatible types: '*align(0:0:1) u2' and '*align(2:8:2) u2'
+// :14:17: error: incompatible types: '*align(1:0:1) u2' and '*align(2:8:2) u2'