Type: fix printing of default alignment on non-byte aligned pointers

This commit is contained in:
Veikka Tuominen
2022-12-29 12:47:11 +02:00
parent 8a6295fcba
commit e0b6140009
3 changed files with 8 additions and 3 deletions

View File

@@ -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 });

View File

@@ -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

View File

@@ -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'