remove usages of .alignment = 0

This commit is contained in:
David Rubin 2025-02-24 04:02:06 -08:00 committed by David Rubin
parent 17330867eb
commit d6c74a95fd
No known key found for this signature in database
GPG Key ID: B30A9572D968B0E1
9 changed files with 45 additions and 51 deletions

View File

@ -708,7 +708,7 @@ pub const Arguments = blk: {
field.* = .{
.name = decl.name,
.type = @field(attributes, decl.name),
.alignment = 0,
.alignment = @alignOf(@field(attributes, decl.name)),
};
}

View File

@ -939,7 +939,7 @@ fn CreateUniqueTuple(comptime N: comptime_int, comptime types: [N]type) type {
.type = T,
.default_value_ptr = null,
.is_comptime = false,
.alignment = 0,
.alignment = @alignOf(T),
};
}

View File

@ -8533,18 +8533,19 @@ pub const Metadata = enum(u32) {
.type = []const u8,
.default_value_ptr = null,
.is_comptime = false,
.alignment = 0,
.alignment = @alignOf([]const u8),
};
}
fmt_str = fmt_str ++ "(";
inline for (fields[2..], names) |*field, name| {
fmt_str = fmt_str ++ "{[" ++ name ++ "]f}";
const T = std.fmt.Formatter(FormatData, format);
field.* = .{
.name = name,
.type = std.fmt.Formatter(FormatData, format),
.type = T,
.default_value_ptr = null,
.is_comptime = false,
.alignment = 0,
.alignment = @alignOf(T),
};
}
fmt_str = fmt_str ++ ")\n";

View File

@ -1137,13 +1137,16 @@ const Local = struct {
const elem_info = @typeInfo(Elem).@"struct";
const elem_fields = elem_info.fields;
var new_fields: [elem_fields.len]std.builtin.Type.StructField = undefined;
for (&new_fields, elem_fields) |*new_field, elem_field| new_field.* = .{
.name = elem_field.name,
.type = *[len]elem_field.type,
.default_value_ptr = null,
.is_comptime = false,
.alignment = 0,
};
for (&new_fields, elem_fields) |*new_field, elem_field| {
const T = *[len]elem_field.type;
new_field.* = .{
.name = elem_field.name,
.type = T,
.default_value_ptr = null,
.is_comptime = false,
.alignment = @alignOf(T),
};
}
return @Type(.{ .@"struct" = .{
.layout = .auto,
.fields = &new_fields,
@ -1158,22 +1161,25 @@ const Local = struct {
const elem_info = @typeInfo(Elem).@"struct";
const elem_fields = elem_info.fields;
var new_fields: [elem_fields.len]std.builtin.Type.StructField = undefined;
for (&new_fields, elem_fields) |*new_field, elem_field| new_field.* = .{
.name = elem_field.name,
.type = @Type(.{ .pointer = .{
for (&new_fields, elem_fields) |*new_field, elem_field| {
const T = @Type(.{ .pointer = .{
.size = opts.size,
.is_const = opts.is_const,
.is_volatile = false,
.alignment = 0,
.alignment = @alignOf(elem_field.type),
.address_space = .generic,
.child = elem_field.type,
.is_allowzero = false,
.sentinel_ptr = null,
} }),
.default_value_ptr = null,
.is_comptime = false,
.alignment = 0,
};
} });
new_field.* = .{
.name = elem_field.name,
.type = T,
.default_value_ptr = null,
.is_comptime = false,
.alignment = @alignOf(T),
};
}
return @Type(.{ .@"struct" = .{
.layout = .auto,
.fields = &new_fields,

View File

@ -20332,7 +20332,7 @@ fn zirReify(
).?);
if (!try sema.intFitsInType(alignment_val, align_ty, null)) {
return sema.fail(block, src, "alignment must fit in '{}'", .{align_ty.fmt(pt)});
return sema.fail(block, src, "alignment must fit in '{f}'", .{align_ty.fmt(pt)});
}
const alignment_val_int = try alignment_val.toUnsignedIntSema(pt);
const abi_align = try sema.validateAlign(block, src, alignment_val_int);

View File

@ -33,13 +33,16 @@ pub fn nextInstruction(as: *Assemble) !?Instruction {
var symbols: Symbols: {
const symbols = @typeInfo(@TypeOf(instruction.symbols)).@"struct".fields;
var symbol_fields: [symbols.len]std.builtin.Type.StructField = undefined;
for (&symbol_fields, symbols) |*symbol_field, symbol| symbol_field.* = .{
.name = symbol.name,
.type = zonCast(SymbolSpec, @field(instruction.symbols, symbol.name), .{}).Storage(),
.default_value_ptr = null,
.is_comptime = false,
.alignment = 0,
};
for (&symbol_fields, symbols) |*symbol_field, symbol| {
const Storage = zonCast(SymbolSpec, @field(instruction.symbols, symbol.name), .{}).Storage();
symbol_field.* = .{
.name = symbol.name,
.type = Storage,
.default_value_ptr = null,
.is_comptime = false,
.alignment = @alignOf(Storage),
};
}
break :Symbols @Type(.{ .@"struct" = .{
.layout = .auto,
.fields = &symbol_fields,

View File

@ -318,6 +318,8 @@ test "tuple type with void field" {
test "zero sized struct in tuple handled correctly" {
const State = struct {
const Self = @This();
const Inner = struct {};
data: @Type(.{
.@"struct" = .{
.is_tuple = true,
@ -325,10 +327,10 @@ test "zero sized struct in tuple handled correctly" {
.decls = &.{},
.fields = &.{.{
.name = "0",
.type = struct {},
.type = Inner,
.default_value_ptr = null,
.is_comptime = false,
.alignment = 0,
.alignment = @alignOf(Inner),
}},
},
}),

View File

@ -735,7 +735,7 @@ test "struct field names sliced at comptime from larger string" {
var it = std.mem.tokenizeScalar(u8, text, '\n');
while (it.next()) |name| {
fields = fields ++ &[_]Type.StructField{.{
.alignment = 0,
.alignment = @alignOf(usize),
.name = name ++ "",
.type = usize,
.default_value_ptr = null,

View File

@ -65,24 +65,7 @@ export fn k() void {
} });
}
export fn l() void {
_ = @Type(.{ .@"struct" = .{
.layout = .@"packed",
.fields = &.{.{
.name = "test",
.type = u32,
.default_value_ptr = null,
.is_comptime = false,
.alignment = 8,
}},
.decls = &.{},
.is_tuple = false,
} });
}
// error
// backend=stage2
// target=native
//
// :1:27: error: alignment must be >= 1
// :7:34: error: alignment must be >= 1
@ -93,6 +76,5 @@ export fn l() void {
// :29:17: error: alignment must be >= 1
// :33:35: error: alignment must be >= 1
// :37:34: error: alignment must be >= 1
// :41:9: error: alignment can only be 0 on packed struct fields
// :41:9: error: alignment must be >= 1
// :56:9: error: alignment must be >= 1
// :69:9: error: alignment in a packed struct field must be set to 0