From 695792719450facba99adf2b6711392657975268 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 18 May 2019 10:59:56 +0200 Subject: [PATCH 1/2] Fix some test cases to run on 32bit systems --- test/stage1/behavior/pointers.zig | 4 ++-- test/stage1/behavior/struct.zig | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/test/stage1/behavior/pointers.zig b/test/stage1/behavior/pointers.zig index 50b36fe583..bf292bad0d 100644 --- a/test/stage1/behavior/pointers.zig +++ b/test/stage1/behavior/pointers.zig @@ -132,8 +132,8 @@ test "initialize const optional C pointer to null" { } test "compare equality of optional and non-optional pointer" { - const a = @intToPtr(*const usize, 0x123456789); - const b = @intToPtr(?*usize, 0x123456789); + const a = @intToPtr(*const usize, 0x12345678); + const b = @intToPtr(?*usize, 0x12345678); expect(a == b); expect(b == a); } diff --git a/test/stage1/behavior/struct.zig b/test/stage1/behavior/struct.zig index 114f06982b..ec404213f0 100644 --- a/test/stage1/behavior/struct.zig +++ b/test/stage1/behavior/struct.zig @@ -2,7 +2,7 @@ const std = @import("std"); const expect = std.testing.expect; const expectEqualSlices = std.testing.expectEqualSlices; const builtin = @import("builtin"); -const maxInt = std.math.maxInt; +const maxInt = std.math.maxInt; const StructWithNoFields = struct { fn add(a: i32, b: i32) i32 { return a + b; @@ -256,7 +256,11 @@ const Foo96Bits = packed struct { test "packed struct 24bits" { comptime { expect(@sizeOf(Foo24Bits) == 4); - expect(@sizeOf(Foo96Bits) == 16); + if (@sizeOf(usize) == 4) { + expect(@sizeOf(Foo96Bits) == 12); + } else { + expect(@sizeOf(Foo96Bits) == 16); + } } var value = Foo96Bits{ @@ -505,10 +509,10 @@ test "packed struct with u0 field access" { comptime expect(s.f0 == 0); } -const S0 = struct{ +const S0 = struct { bar: S1, - pub const S1 = struct{ + pub const S1 = struct { value: u8, }; From 232bc1bdeecc62185984705118adb81e7cf759c2 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Fri, 10 May 2019 10:15:47 +0200 Subject: [PATCH 2/2] Remove more 64bit-centric assumptions from stdlib --- std/debug.zig | 26 +++++++++++++------------- std/elf.zig | 4 ++-- std/os/file.zig | 3 ++- std/pdb.zig | 2 +- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/std/debug.zig b/std/debug.zig index 234eebcd5e..d8dd2c3980 100644 --- a/std/debug.zig +++ b/std/debug.zig @@ -1181,8 +1181,8 @@ pub const DwarfInfo = struct { func_list: ArrayList(Func), pub const Section = struct { - offset: usize, - size: usize, + offset: u64, + size: u64, }; pub fn allocator(self: DwarfInfo) *mem.Allocator { @@ -1344,8 +1344,8 @@ const FileEntry = struct { }; pub const LineInfo = struct { - line: usize, - column: usize, + line: u64, + column: u64, file_name: []const u8, allocator: ?*mem.Allocator, @@ -1358,8 +1358,8 @@ pub const LineInfo = struct { const LineNumberProgram = struct { address: usize, file: usize, - line: isize, - column: usize, + line: i64, + column: u64, is_stmt: bool, basic_block: bool, end_sequence: bool, @@ -1370,8 +1370,8 @@ const LineNumberProgram = struct { prev_address: usize, prev_file: usize, - prev_line: isize, - prev_column: usize, + prev_line: i64, + prev_column: u64, prev_is_stmt: bool, prev_basic_block: bool, prev_end_sequence: bool, @@ -1414,7 +1414,7 @@ const LineNumberProgram = struct { const file_name = try os.path.join(self.file_entries.allocator, [][]const u8{ dir_name, file_entry.file_name }); errdefer self.file_entries.allocator.free(file_name); return LineInfo{ - .line = if (self.prev_line >= 0) @intCast(usize, self.prev_line) else 0, + .line = if (self.prev_line >= 0) @intCast(u64, self.prev_line) else 0, .column = self.prev_column, .file_name = file_name, .allocator = self.file_entries.allocator, @@ -1789,7 +1789,7 @@ fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: u prog.basic_block = false; }, DW.LNS_advance_pc => { - const arg = try leb.readULEB128Mem(u64, &ptr); + const arg = try leb.readULEB128Mem(usize, &ptr); prog.address += arg * minimum_instruction_length; }, DW.LNS_advance_line => { @@ -1797,7 +1797,7 @@ fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: u prog.line += arg; }, DW.LNS_set_file => { - const arg = try leb.readULEB128Mem(u64, &ptr); + const arg = try leb.readULEB128Mem(usize, &ptr); prog.file = arg; }, DW.LNS_set_column => { @@ -1955,7 +1955,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr prog.basic_block = false; }, DW.LNS_advance_pc => { - const arg = try leb.readULEB128(u64, di.dwarf_in_stream); + const arg = try leb.readULEB128(usize, di.dwarf_in_stream); prog.address += arg * minimum_instruction_length; }, DW.LNS_advance_line => { @@ -1963,7 +1963,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr prog.line += arg; }, DW.LNS_set_file => { - const arg = try leb.readULEB128(u64, di.dwarf_in_stream); + const arg = try leb.readULEB128(usize, di.dwarf_in_stream); prog.file = arg; }, DW.LNS_set_column => { diff --git a/std/elf.zig b/std/elf.zig index 49f2f7d137..39617d3cf4 100644 --- a/std/elf.zig +++ b/std/elf.zig @@ -363,7 +363,7 @@ pub const Elf = struct { entry_addr: u64, program_header_offset: u64, section_header_offset: u64, - string_section_index: u64, + string_section_index: usize, string_section: *SectionHeader, section_headers: []SectionHeader, allocator: *mem.Allocator, @@ -458,7 +458,7 @@ pub const Elf = struct { const ph_entry_count = try in.readInt(u16, elf.endian); const sh_entry_size = try in.readInt(u16, elf.endian); const sh_entry_count = try in.readInt(u16, elf.endian); - elf.string_section_index = u64(try in.readInt(u16, elf.endian)); + elf.string_section_index = usize(try in.readInt(u16, elf.endian)); if (elf.string_section_index >= sh_entry_count) return error.InvalidFormat; diff --git a/std/os/file.zig b/std/os/file.zig index 814e5e318c..d223d55a46 100644 --- a/std/os/file.zig +++ b/std/os/file.zig @@ -238,7 +238,8 @@ pub const File = struct { pub fn seekForward(self: File, amount: i64) SeekError!void { switch (builtin.os) { Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => { - const result = posix.lseek(self.handle, amount, posix.SEEK_CUR); + const iamount = try math.cast(isize, amount); + const result = posix.lseek(self.handle, iamount, posix.SEEK_CUR); const err = posix.getErrno(result); if (err > 0) { return switch (err) { diff --git a/std/pdb.zig b/std/pdb.zig index 043be2bcf4..f3b73663e8 100644 --- a/std/pdb.zig +++ b/std/pdb.zig @@ -632,7 +632,7 @@ const MsfStream = struct { } fn read(self: *MsfStream, buffer: []u8) !usize { - var block_id = self.pos / self.block_size; + var block_id = @intCast(usize, self.pos / self.block_size); var block = self.blocks[block_id]; var offset = self.pos % self.block_size;