Skip to content

Commit f181e81

Browse files
committed
- Temporary backport of aro and translate-c (drop this commit)
1 parent b4c11da commit f181e81

File tree

2 files changed

+31
-26
lines changed

2 files changed

+31
-26
lines changed

lib/compiler/aro/aro/Compilation.zig

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ fn generateSystemDefines(comp: *Compilation, w: *std.Io.Writer) !void {
263263
};
264264
try w.print("#define __ARO_EMULATE__ {s}\n", .{emulated});
265265

266+
if (comp.langopts.emulate == .msvc) {
267+
try w.writeAll("#define _MSC_VER 1933\n");
268+
try w.writeAll("#define _MSC_FULL_VER 193300000\n");
269+
}
270+
266271
if (comp.code_gen_options.optimization_level.hasAnyOptimizations()) {
267272
try define(w, "__OPTIMIZE__");
268273
}
@@ -1663,13 +1668,11 @@ const FindInclude = struct {
16631668
only_search_after_dir: []const u8,
16641669
},
16651670
) Allocator.Error!?Result {
1666-
var wait_for: ?[]u8 = null;
16671671
var find: FindInclude = .{
16681672
.comp = comp,
16691673
.include_path = include_path,
16701674
.wait_for = null,
16711675
};
1672-
defer if (wait_for) |buf| comp.gpa.free(buf);
16731676

16741677
if (std.fs.path.isAbsolute(include_path)) {
16751678
switch (search_strat) {
@@ -1690,12 +1693,7 @@ const FindInclude = struct {
16901693
// because a file might not be directly inside of an include directory. To implement
16911694
// this correctly, we will need to track which include directory a file has been
16921695
// included from.
1693-
wait_for = if (std.fs.path.dirname(other_file)) |path|
1694-
try std.fs.path.resolve(comp.gpa, &.{path})
1695-
else
1696-
null;
1697-
1698-
find.wait_for = wait_for;
1696+
find.wait_for = std.fs.path.dirname(other_file);
16991697
},
17001698
}
17011699
switch (include_type) {
@@ -1724,9 +1722,28 @@ const FindInclude = struct {
17241722
}
17251723
return null;
17261724
}
1725+
fn pathMatches(a: []const u8, b: []const u8) bool {
1726+
if (@import("builtin").os.tag != .windows) {
1727+
return std.mem.eql(u8, a, b);
1728+
}
1729+
1730+
const separators = std.fs.path.sep_str_windows ++ std.fs.path.sep_str_posix;
1731+
var a_iter = std.mem.splitAny(u8, a, separators);
1732+
var b_iter = std.mem.splitAny(u8, b, separators);
1733+
var a_component = a_iter.next();
1734+
var b_component = b_iter.next();
1735+
while (a_component != null and b_component != null) : ({
1736+
a_component = a_iter.next();
1737+
b_component = b_iter.next();
1738+
}) {
1739+
if (!std.mem.eql(u8, a_component.?, b_component.?)) return false;
1740+
}
1741+
1742+
return a_component == null and b_component == null;
1743+
}
17271744
fn checkIncludeDir(find: *FindInclude, include_dir: []const u8, kind: Source.Kind) Allocator.Error!?Result {
17281745
if (find.wait_for) |wait_for| {
1729-
if (std.mem.eql(u8, include_dir, wait_for)) find.wait_for = null;
1746+
if (pathMatches(include_dir, wait_for)) find.wait_for = null;
17301747
return null;
17311748
}
17321749
return find.check("{s}{c}{s}", .{
@@ -1739,7 +1756,7 @@ const FindInclude = struct {
17391756
const path = find.comp.getSource(source_id).path;
17401757
const dir = std.fs.path.dirname(path) orelse ".";
17411758
if (find.wait_for) |wait_for| {
1742-
if (std.mem.eql(u8, dir, wait_for)) find.wait_for = null;
1759+
if (pathMatches(dir, wait_for)) find.wait_for = null;
17431760
return null;
17441761
}
17451762
return find.check("{s}{c}{s}", .{
@@ -1754,7 +1771,7 @@ const FindInclude = struct {
17541771
// If this is a match, then `wait_for` looks like '.../Foo.framework/Headers'.
17551772
const wait_framework = std.fs.path.dirname(wait_for) orelse break :match;
17561773
const wait_framework_dir = std.fs.path.dirname(wait_framework) orelse break :match;
1757-
if (!std.mem.eql(u8, framework_dir, wait_framework_dir)) break :match;
1774+
if (!pathMatches(framework_dir, wait_framework_dir)) break :match;
17581775
find.wait_for = null;
17591776
}
17601777
return null;

lib/compiler/translate-c/Translator.zig

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,17 +1165,8 @@ fn headFieldAlignment(t: *Translator, record_decl: aro.Type.Record) ?c_uint {
11651165
const parent_ptr_alignment_bits = record_decl.layout.?.pointer_alignment_bits;
11661166
const parent_ptr_alignment = parent_ptr_alignment_bits / bits_per_byte;
11671167
var max_field_alignment_bits: u64 = 0;
1168-
for (record_decl.fields) |field| {
1169-
if (field.qt.getRecord(t.comp)) |field_record_decl| {
1170-
const child_record_alignment = field_record_decl.layout.?.field_alignment_bits;
1171-
if (child_record_alignment > max_field_alignment_bits)
1172-
max_field_alignment_bits = child_record_alignment;
1173-
} else {
1174-
const field_size = field.layout.size_bits;
1175-
if (field_size > max_field_alignment_bits)
1176-
max_field_alignment_bits = field_size;
1177-
}
1178-
}
1168+
for (record_decl.fields) |field|
1169+
max_field_alignment_bits = @max(max_field_alignment_bits, bits_per_byte * field.qt.alignof(t.comp));
11791170
if (max_field_alignment_bits != parent_ptr_alignment_bits) {
11801171
return parent_ptr_alignment;
11811172
} else {
@@ -1227,10 +1218,7 @@ fn alignmentForField(
12271218
// Records have a natural alignment when used as a field, and their size is
12281219
// a multiple of this alignment value. For all other types, the natural alignment
12291220
// is their size.
1230-
const field_natural_alignment_bits: u64 = if (field.qt.getRecord(t.comp)) |record|
1231-
record.layout.?.field_alignment_bits
1232-
else
1233-
field_size_bits;
1221+
const field_natural_alignment_bits: u64 = bits_per_byte * field.qt.alignof(t.comp);
12341222
const rem_bits = field_offset_bits % field_natural_alignment_bits;
12351223

12361224
// If there's a remainder, then the alignment is smaller than the field's

0 commit comments

Comments
 (0)