Skip to content

Commit

Permalink
remove usages of .alignment = 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexicon226 committed Feb 24, 2025
1 parent 6b1aa36 commit ebf81fb
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/compiler/aro/aro/Attribute.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
};
}

Expand Down
2 changes: 1 addition & 1 deletion lib/std/meta.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,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),
};
}

Expand Down
38 changes: 22 additions & 16 deletions src/InternPool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1135,13 +1135,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,
Expand All @@ -1156,22 +1159,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,
Expand Down
7 changes: 4 additions & 3 deletions src/codegen/llvm/Builder.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8465,18 +8465,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 ++ "]S}";
const T = std.fmt.Formatter(format);
field.* = .{
.name = name,
.type = std.fmt.Formatter(format),
.type = T,
.default_value_ptr = null,
.is_comptime = false,
.alignment = 0,
.alignment = @alignOf(T),
};
}
fmt_str = fmt_str ++ ")\n";
Expand Down
2 changes: 1 addition & 1 deletion test/behavior/tuple.zig
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ test "zero sized struct in tuple handled correctly" {
.type = struct {},
.default_value_ptr = null,
.is_comptime = false,
.alignment = 0,
.alignment = @alignOf(struct {}),
}},
},
}),
Expand Down
2 changes: 1 addition & 1 deletion test/behavior/type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ebf81fb

Please sign in to comment.