authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-02-22 23:06:07+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-02-22 23:06:07+01:00
loge5c30eef1f338ed65325ddbfd4d631baef0d9b81
treefe3707565525f342ce0aa6c86e58c828809ae600
parentb23f10b42403406f40158ec11de95a3f80ce5879
parentc64d3b0a96a854b093fbedc976397f225ea964fa
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #10949 from ziglang/x64-print-results

stage2,x64: print test_runner results

50 files changed, 1717 insertions(+), 319 deletions(-)

lib/std/special/c.zig+19
......@@ -46,6 +46,10 @@ comptime {
4646
4747 @export(log10, .{ .name = "log10", .linkage = .Strong });
4848 @export(log10f, .{ .name = "log10f", .linkage = .Strong });
49
50 @export(ceil, .{ .name = "ceil", .linkage = .Strong });
51 @export(ceilf, .{ .name = "ceilf", .linkage = .Strong });
52 @export(ceill, .{ .name = "ceill", .linkage = .Strong });
4953}
5054
5155// Avoid dragging in the runtime safety mechanisms into this .o file,
......@@ -179,3 +183,18 @@ fn log10(a: f64) callconv(.C) f64 {
179183fn log10f(a: f32) callconv(.C) f32 {
180184 return math.log10(a);
181185}
186
187fn ceilf(x: f32) callconv(.C) f32 {
188 return math.ceil(x);
189}
190
191fn ceil(x: f64) callconv(.C) f64 {
192 return math.ceil(x);
193}
194
195fn ceill(x: c_longdouble) callconv(.C) c_longdouble {
196 if (!long_double_is_f128) {
197 @panic("TODO implement this");
198 }
199 return math.ceil(x);
200}
lib/std/special/c_stage1.zig-13
......@@ -613,19 +613,6 @@ export fn fmod(x: f64, y: f64) f64 {
613613 return generic_fmod(f64, x, y);
614614}
615615
616export fn ceilf(x: f32) f32 {
617 return math.ceil(x);
618}
619export fn ceil(x: f64) f64 {
620 return math.ceil(x);
621}
622export fn ceill(x: c_longdouble) c_longdouble {
623 if (!long_double_is_f128) {
624 @panic("TODO implement this");
625 }
626 return math.ceil(x);
627}
628
629616export fn fmaf(a: f32, b: f32, c: f32) f32 {
630617 return math.fma(f32, a, b, c);
631618}
lib/std/special/test_runner.zig+4-1
......@@ -141,7 +141,10 @@ pub fn main2() anyerror!void {
141141 }
142142 };
143143 }
144 if (builtin.zig_backend == .stage2_llvm or builtin.zig_backend == .stage2_wasm) {
144 if (builtin.zig_backend == .stage2_llvm or
145 builtin.zig_backend == .stage2_wasm or
146 (builtin.zig_backend == .stage2_x86_64 and builtin.os.tag != .macos))
147 {
145148 const passed = builtin.test_functions.len - skipped - failed;
146149 const stderr = std.io.getStdErr();
147150 writeInt(stderr, passed) catch {};
src/Liveness.zig+36
......@@ -135,6 +135,42 @@ pub fn getCondBr(l: Liveness, inst: Air.Inst.Index) CondBrSlices {
135135 };
136136}
137137
138/// Indexed by case number as they appear in AIR.
139/// Else is the last element.
140pub const SwitchBrTable = struct {
141 deaths: []const []const Air.Inst.Index,
142};
143
144/// Caller owns the memory.
145pub fn getSwitchBr(l: Liveness, gpa: Allocator, inst: Air.Inst.Index, cases_len: u32) Allocator.Error!SwitchBrTable {
146 var index: usize = l.special.get(inst) orelse return SwitchBrTable{
147 .deaths = &.{},
148 };
149 const else_death_count = l.extra[index];
150 index += 1;
151
152 var deaths = std.ArrayList([]const Air.Inst.Index).init(gpa);
153 defer deaths.deinit();
154 try deaths.ensureTotalCapacity(cases_len + 1);
155
156 var case_i: u32 = 0;
157 while (case_i < cases_len - 1) : (case_i += 1) {
158 const case_death_count: u32 = l.extra[index];
159 index += 1;
160 const case_deaths = l.extra[index..][0..case_death_count];
161 index += case_death_count;
162 deaths.appendAssumeCapacity(case_deaths);
163 }
164 {
165 // Else
166 const else_deaths = l.extra[index..][0..else_death_count];
167 deaths.appendAssumeCapacity(else_deaths);
168 }
169 return SwitchBrTable{
170 .deaths = deaths.toOwnedSlice(),
171 };
172}
173
138174pub fn deinit(l: *Liveness, gpa: Allocator) void {
139175 gpa.free(l.tomb_bits);
140176 gpa.free(l.extra);
src/arch/x86_64/CodeGen.zig+646-161
......@@ -49,6 +49,9 @@ arg_index: u32,
4949src_loc: Module.SrcLoc,
5050stack_align: u32,
5151
52ret_backpatch: ?Mir.Inst.Index = null,
53compare_flags_inst: ?Air.Inst.Index = null,
54
5255/// MIR Instructions
5356mir_instructions: std.MultiArrayList(Mir.Inst) = .{},
5457/// MIR extra data
......@@ -470,6 +473,20 @@ fn gen(self: *Self) InnerError!void {
470473 };
471474 inline for (callee_preserved_regs) |reg, i| {
472475 if (self.register_manager.isRegAllocated(reg)) {
476 if (self.ret_backpatch) |inst| {
477 if (reg.to64() == .rdi) {
478 const ops = Mir.Ops.decode(self.mir_instructions.items(.ops)[inst]);
479 self.mir_instructions.set(inst, Mir.Inst{
480 .tag = .mov,
481 .ops = (Mir.Ops{
482 .reg1 = ops.reg1,
483 .reg2 = .rbp,
484 .flags = 0b01,
485 }).encode(),
486 .data = .{ .imm = @bitCast(u32, -@intCast(i32, self.max_end_stack + 8)) },
487 });
488 }
489 }
473490 data.regs |= 1 << @intCast(u5, i);
474491 self.max_end_stack += 8;
475492 }
......@@ -758,6 +775,9 @@ fn processDeath(self: *Self, inst: Air.Inst.Index) void {
758775 const canon_reg = reg.to64();
759776 self.register_manager.freeReg(canon_reg);
760777 },
778 .compare_flags_signed, .compare_flags_unsigned => {
779 self.compare_flags_inst = null;
780 },
761781 else => {}, // TODO process stack allocation death
762782 }
763783}
......@@ -870,7 +890,23 @@ pub fn spillInstruction(self: *Self, reg: Register, inst: Air.Inst.Index) !void
870890 assert(reg.to64() == reg_mcv.register.to64());
871891 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
872892 try branch.inst_table.put(self.gpa, inst, stack_mcv);
873 try self.genSetStack(self.air.typeOfIndex(inst), stack_mcv.stack_offset, reg_mcv);
893 try self.genSetStack(self.air.typeOfIndex(inst), stack_mcv.stack_offset, reg_mcv, .{});
894}
895
896pub fn spillCompareFlagsIfOccupied(self: *Self) !void {
897 if (self.compare_flags_inst) |inst_to_save| {
898 const mcv = self.getResolvedInstValue(inst_to_save);
899 assert(mcv == .compare_flags_signed or mcv == .compare_flags_unsigned);
900
901 const new_mcv = try self.allocRegOrMem(inst_to_save, true);
902 try self.setRegOrMem(self.air.typeOfIndex(inst_to_save), new_mcv, mcv);
903 log.debug("spilling {d} to mcv {any}", .{ inst_to_save, new_mcv });
904
905 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
906 try branch.inst_table.put(self.gpa, inst_to_save, new_mcv);
907
908 self.compare_flags_inst = null;
909 }
874910}
875911
876912/// Copies a value to a register without tracking the register. The register is not considered
......@@ -925,8 +961,6 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
925961 const operand = try self.resolveInst(ty_op.operand);
926962 const info_a = operand_ty.intInfo(self.target.*);
927963 const info_b = self.air.typeOfIndex(inst).intInfo(self.target.*);
928 if (info_a.signedness != info_b.signedness)
929 return self.fail("TODO gen intcast sign safety in semantic analysis", .{});
930964
931965 const operand_abi_size = operand_ty.abiSize(self.target.*);
932966 const dest_ty = self.air.typeOfIndex(inst);
......@@ -1058,10 +1092,44 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
10581092
10591093fn airMin(self: *Self, inst: Air.Inst.Index) !void {
10601094 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
1061 const result: MCValue = if (self.liveness.isUnused(inst))
1062 .dead
1063 else
1064 return self.fail("TODO implement min for {}", .{self.target.cpu.arch});
1095 if (self.liveness.isUnused(inst)) {
1096 return self.finishAir(inst, .dead, .{ bin_op.lhs, bin_op.rhs, .none });
1097 }
1098
1099 const ty = self.air.typeOfIndex(inst);
1100 if (ty.zigTypeTag() != .Int) {
1101 return self.fail("TODO implement min for type {}", .{ty});
1102 }
1103 const signedness = ty.intInfo(self.target.*).signedness;
1104 const result: MCValue = result: {
1105 // TODO improve by checking if any operand can be reused.
1106 // TODO audit register allocation
1107 const lhs = try self.resolveInst(bin_op.lhs);
1108 lhs.freezeIfRegister(&self.register_manager);
1109 defer lhs.unfreezeIfRegister(&self.register_manager);
1110
1111 const lhs_reg = try self.copyToTmpRegister(ty, lhs);
1112 self.register_manager.freezeRegs(&.{lhs_reg});
1113 defer self.register_manager.unfreezeRegs(&.{lhs_reg});
1114
1115 const rhs_mcv = try self.limitImmediateType(bin_op.rhs, i32);
1116 rhs_mcv.freezeIfRegister(&self.register_manager);
1117 defer rhs_mcv.unfreezeIfRegister(&self.register_manager);
1118
1119 try self.genBinMathOpMir(.cmp, ty, .{ .register = lhs_reg }, rhs_mcv);
1120
1121 const dst_mcv = try self.copyToRegisterWithInstTracking(inst, ty, rhs_mcv);
1122 _ = try self.addInst(.{
1123 .tag = if (signedness == .signed) .cond_mov_lt else .cond_mov_below,
1124 .ops = (Mir.Ops{
1125 .reg1 = dst_mcv.register,
1126 .reg2 = lhs_reg,
1127 }).encode(),
1128 .data = undefined,
1129 });
1130
1131 break :result dst_mcv;
1132 };
10651133 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
10661134}
10671135
......@@ -1081,9 +1149,6 @@ fn genPtrBinMathOp(self: *Self, inst: Air.Inst.Index, op_lhs: Air.Inst.Ref, op_r
10811149 const offset = try self.resolveInst(op_rhs);
10821150 const offset_ty = self.air.typeOf(op_rhs);
10831151
1084 ptr.freezeIfRegister(&self.register_manager);
1085 defer ptr.unfreezeIfRegister(&self.register_manager);
1086
10871152 offset.freezeIfRegister(&self.register_manager);
10881153 defer offset.unfreezeIfRegister(&self.register_manager);
10891154
......@@ -1091,9 +1156,12 @@ fn genPtrBinMathOp(self: *Self, inst: Air.Inst.Index, op_lhs: Air.Inst.Ref, op_r
10911156 if (self.reuseOperand(inst, op_lhs, 0, ptr)) {
10921157 if (ptr.isMemory() or ptr.isRegister()) break :blk ptr;
10931158 }
1094 break :blk try self.copyToRegisterWithInstTracking(inst, dst_ty, ptr);
1159 break :blk MCValue{ .register = try self.copyToTmpRegister(dst_ty, ptr) };
10951160 };
10961161
1162 dst_mcv.freezeIfRegister(&self.register_manager);
1163 defer dst_mcv.unfreezeIfRegister(&self.register_manager);
1164
10971165 const offset_mcv = blk: {
10981166 if (self.reuseOperand(inst, op_rhs, 1, offset)) {
10991167 if (offset.isRegister()) break :blk offset;
......@@ -1101,6 +1169,9 @@ fn genPtrBinMathOp(self: *Self, inst: Air.Inst.Index, op_lhs: Air.Inst.Ref, op_r
11011169 break :blk MCValue{ .register = try self.copyToTmpRegister(offset_ty, offset) };
11021170 };
11031171
1172 offset_mcv.freezeIfRegister(&self.register_manager);
1173 defer offset_mcv.unfreezeIfRegister(&self.register_manager);
1174
11041175 try self.genIMulOpMir(offset_ty, offset_mcv, .{ .immediate = elem_size });
11051176
11061177 const tag = self.air.instructions.items(.tag)[inst];
......@@ -1145,8 +1216,8 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
11451216 const len_ty = self.air.typeOf(bin_op.rhs);
11461217
11471218 const stack_offset = @intCast(i32, try self.allocMem(inst, 16, 16));
1148 try self.genSetStack(ptr_ty, stack_offset, ptr);
1149 try self.genSetStack(len_ty, stack_offset - 8, len);
1219 try self.genSetStack(ptr_ty, stack_offset, ptr, .{});
1220 try self.genSetStack(len_ty, stack_offset - 8, len, .{});
11501221 const result = MCValue{ .stack_offset = stack_offset };
11511222
11521223 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
......@@ -1179,12 +1250,43 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
11791250 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
11801251}
11811252
1253fn genSubOp(self: *Self, inst: Air.Inst.Index, op_lhs: Air.Inst.Ref, op_rhs: Air.Inst.Ref) !MCValue {
1254 const dst_ty = self.air.typeOfIndex(inst);
1255 const lhs = try self.resolveInst(op_lhs);
1256 const rhs = try self.resolveInst(op_rhs);
1257
1258 rhs.freezeIfRegister(&self.register_manager);
1259 defer rhs.unfreezeIfRegister(&self.register_manager);
1260
1261 const dst_mcv = blk: {
1262 if (self.reuseOperand(inst, op_lhs, 0, lhs)) {
1263 if (lhs.isMemory() or lhs.isRegister()) break :blk lhs;
1264 }
1265 break :blk try self.copyToRegisterWithInstTracking(inst, dst_ty, lhs);
1266 };
1267
1268 dst_mcv.freezeIfRegister(&self.register_manager);
1269 defer dst_mcv.unfreezeIfRegister(&self.register_manager);
1270
1271 const rhs_mcv = blk: {
1272 if (rhs.isRegister()) break :blk rhs;
1273 break :blk MCValue{ .register = try self.copyToTmpRegister(dst_ty, rhs) };
1274 };
1275
1276 rhs_mcv.freezeIfRegister(&self.register_manager);
1277 defer rhs_mcv.unfreezeIfRegister(&self.register_manager);
1278
1279 try self.genBinMathOpMir(.sub, dst_ty, dst_mcv, rhs_mcv);
1280
1281 return dst_mcv;
1282}
1283
11821284fn airSub(self: *Self, inst: Air.Inst.Index) !void {
11831285 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
11841286 const result: MCValue = if (self.liveness.isUnused(inst))
11851287 .dead
11861288 else
1187 try self.genBinMathOp(inst, bin_op.lhs, bin_op.rhs);
1289 try self.genSubOp(inst, bin_op.lhs, bin_op.rhs);
11881290 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
11891291}
11901292
......@@ -1523,11 +1625,58 @@ fn airXor(self: *Self, inst: Air.Inst.Index) !void {
15231625
15241626fn airShl(self: *Self, inst: Air.Inst.Index) !void {
15251627 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
1526 const result: MCValue = if (self.liveness.isUnused(inst))
1527 .dead
1528 else
1529 return self.fail("TODO implement shl for {}", .{self.target.cpu.arch});
1530 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1628 if (self.liveness.isUnused(inst)) {
1629 return self.finishAir(inst, .dead, .{ bin_op.lhs, bin_op.rhs, .none });
1630 }
1631
1632 const ty = self.air.typeOfIndex(inst);
1633 const tag = self.air.instructions.items(.tag)[inst];
1634 switch (tag) {
1635 .shl_exact => return self.fail("TODO implement {} for type {}", .{ tag, ty }),
1636 .shl => {},
1637 else => unreachable,
1638 }
1639
1640 if (ty.zigTypeTag() != .Int) {
1641 return self.fail("TODO implement .shl for type {}", .{ty});
1642 }
1643 if (ty.abiSize(self.target.*) > 8) {
1644 return self.fail("TODO implement .shl for integers larger than 8 bytes", .{});
1645 }
1646
1647 // TODO look into reusing the operands
1648 // TODO audit register allocation mechanics
1649 const shift = try self.resolveInst(bin_op.rhs);
1650 const shift_ty = self.air.typeOf(bin_op.rhs);
1651
1652 blk: {
1653 switch (shift) {
1654 .register => |reg| {
1655 if (reg.to64() == .rcx) break :blk;
1656 },
1657 else => {},
1658 }
1659 try self.register_manager.getReg(.rcx, null);
1660 try self.genSetReg(shift_ty, .rcx, shift);
1661 }
1662 self.register_manager.freezeRegs(&.{.rcx});
1663 defer self.register_manager.unfreezeRegs(&.{.rcx});
1664
1665 const value = try self.resolveInst(bin_op.lhs);
1666 value.freezeIfRegister(&self.register_manager);
1667 defer value.unfreezeIfRegister(&self.register_manager);
1668
1669 const dst_mcv = try self.copyToRegisterWithInstTracking(inst, ty, value);
1670 _ = try self.addInst(.{
1671 .tag = .sal,
1672 .ops = (Mir.Ops{
1673 .reg1 = dst_mcv.register,
1674 .flags = 0b01,
1675 }).encode(),
1676 .data = undefined,
1677 });
1678
1679 return self.finishAir(inst, dst_mcv, .{ bin_op.lhs, bin_op.rhs, .none });
15311680}
15321681
15331682fn airShlSat(self: *Self, inst: Air.Inst.Index) !void {
......@@ -1580,23 +1729,44 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
15801729
15811730fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {
15821731 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
1583 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1584 const err_union_ty = self.air.typeOf(ty_op.operand);
1585 const payload_ty = err_union_ty.errorUnionPayload();
1586 const mcv = try self.resolveInst(ty_op.operand);
1587 if (!payload_ty.hasRuntimeBits()) break :result mcv;
1588 return self.fail("TODO implement unwrap error union error for non-empty payloads", .{});
1732 if (self.liveness.isUnused(inst)) {
1733 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
1734 }
1735 const err_union_ty = self.air.typeOf(ty_op.operand);
1736 const payload_ty = err_union_ty.errorUnionPayload();
1737 const operand = try self.resolveInst(ty_op.operand);
1738 const result: MCValue = result: {
1739 if (!payload_ty.hasRuntimeBits()) break :result operand;
1740 switch (operand) {
1741 .stack_offset => |off| {
1742 break :result MCValue{ .stack_offset = off };
1743 },
1744 else => return self.fail("TODO implement unwrap_err_err for {}", .{operand}),
1745 }
15891746 };
15901747 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
15911748}
15921749
15931750fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
15941751 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
1595 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1596 const err_union_ty = self.air.typeOf(ty_op.operand);
1597 const payload_ty = err_union_ty.errorUnionPayload();
1752 if (self.liveness.isUnused(inst)) {
1753 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
1754 }
1755 const err_union_ty = self.air.typeOf(ty_op.operand);
1756 const payload_ty = err_union_ty.errorUnionPayload();
1757 const result: MCValue = result: {
15981758 if (!payload_ty.hasRuntimeBits()) break :result MCValue.none;
1599 return self.fail("TODO implement unwrap error union payload for non-empty payloads", .{});
1759
1760 const operand = try self.resolveInst(ty_op.operand);
1761 const err_ty = err_union_ty.errorUnionSet();
1762 const err_abi_size = @intCast(u32, err_ty.abiSize(self.target.*));
1763 switch (operand) {
1764 .stack_offset => |off| {
1765 const offset = off - @intCast(i32, err_abi_size);
1766 break :result MCValue{ .stack_offset = offset };
1767 },
1768 else => return self.fail("TODO implement unwrap_err_payload for {}", .{operand}),
1769 }
16001770 };
16011771 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
16021772}
......@@ -1647,24 +1817,47 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
16471817/// T to E!T
16481818fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
16491819 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
1650 const result: MCValue = if (self.liveness.isUnused(inst))
1651 .dead
1652 else
1653 return self.fail("TODO implement wrap errunion payload for {}", .{self.target.cpu.arch});
1654 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1820 if (self.liveness.isUnused(inst)) {
1821 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
1822 }
1823 const error_union_ty = self.air.getRefType(ty_op.ty);
1824 const error_ty = error_union_ty.errorUnionSet();
1825 const payload_ty = error_union_ty.errorUnionPayload();
1826 const operand = try self.resolveInst(ty_op.operand);
1827 assert(payload_ty.hasRuntimeBits());
1828
1829 const abi_size = @intCast(u32, error_union_ty.abiSize(self.target.*));
1830 const abi_align = error_union_ty.abiAlignment(self.target.*);
1831 const err_abi_size = @intCast(u32, error_ty.abiSize(self.target.*));
1832 const stack_offset = @intCast(i32, try self.allocMem(inst, abi_size, abi_align));
1833 try self.genSetStack(error_ty, stack_offset, .{ .immediate = 0 }, .{});
1834 try self.genSetStack(payload_ty, stack_offset - @intCast(i32, err_abi_size), operand, .{});
1835
1836 return self.finishAir(inst, .{ .stack_offset = stack_offset }, .{ ty_op.operand, .none, .none });
16551837}
16561838
16571839/// E to E!T
16581840fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
16591841 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
1660 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1661 const error_union_ty = self.air.getRefType(ty_op.ty);
1662 const payload_ty = error_union_ty.errorUnionPayload();
1663 const mcv = try self.resolveInst(ty_op.operand);
1664 if (!payload_ty.hasRuntimeBits()) break :result mcv;
1665
1666 return self.fail("TODO implement wrap errunion error for non-empty payloads", .{});
1842 if (self.liveness.isUnused(inst)) {
1843 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
1844 }
1845 const error_union_ty = self.air.getRefType(ty_op.ty);
1846 const error_ty = error_union_ty.errorUnionSet();
1847 const payload_ty = error_union_ty.errorUnionPayload();
1848 const err = try self.resolveInst(ty_op.operand);
1849 const result: MCValue = result: {
1850 if (!payload_ty.hasRuntimeBits()) break :result err;
1851
1852 const abi_size = @intCast(u32, error_union_ty.abiSize(self.target.*));
1853 const abi_align = error_union_ty.abiAlignment(self.target.*);
1854 const err_abi_size = @intCast(u32, error_ty.abiSize(self.target.*));
1855 const stack_offset = @intCast(i32, try self.allocMem(inst, abi_size, abi_align));
1856 try self.genSetStack(error_ty, stack_offset, err, .{});
1857 try self.genSetStack(payload_ty, stack_offset - @intCast(i32, err_abi_size), .undef, .{});
1858 break :result MCValue{ .stack_offset = stack_offset };
16671859 };
1860
16681861 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
16691862}
16701863
......@@ -1824,7 +2017,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
18242017 @intCast(u32, array_ty.abiSize(self.target.*)),
18252018 array_ty.abiAlignment(self.target.*),
18262019 ));
1827 try self.genSetStack(array_ty, off, array);
2020 try self.genSetStack(array_ty, off, array, .{});
18282021 break :inner off;
18292022 },
18302023 .stack_offset => |off| {
......@@ -2057,10 +2250,10 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo
20572250 if (abi_size <= 8) {
20582251 const tmp_reg = try self.register_manager.allocReg(null);
20592252 try self.load(.{ .register = tmp_reg }, ptr, ptr_ty);
2060 return self.genSetStack(elem_ty, off, MCValue{ .register = tmp_reg });
2253 return self.genSetStack(elem_ty, off, MCValue{ .register = tmp_reg }, .{});
20612254 }
20622255
2063 try self.genInlineMemcpy(off, .rbp, elem_ty, ptr);
2256 try self.genInlineMemcpy(off, elem_ty, ptr, .{});
20642257 },
20652258 else => return self.fail("TODO implement loading from register into {}", .{dst_mcv}),
20662259 }
......@@ -2155,7 +2348,7 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type
21552348 try self.store(.{ .register = reg }, value, ptr_ty, value_ty);
21562349 },
21572350 .ptr_stack_offset => |off| {
2158 try self.genSetStack(value_ty, off, value);
2351 try self.genSetStack(value_ty, off, value, .{});
21592352 },
21602353 .ptr_embedded_in_code => |off| {
21612354 try self.setRegOrMem(value_ty, .{ .embedded_in_code = off }, value);
......@@ -2590,6 +2783,8 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
25902783 .memory,
25912784 .got_load,
25922785 .direct_load,
2786 .compare_flags_signed,
2787 .compare_flags_unsigned,
25932788 => {
25942789 assert(abi_size <= 8);
25952790 self.register_manager.freezeRegs(&.{dst_reg});
......@@ -2611,12 +2806,6 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
26112806 .data = .{ .imm = @bitCast(u32, -off) },
26122807 });
26132808 },
2614 .compare_flags_unsigned => {
2615 return self.fail("TODO implement x86 ADD/SUB/CMP source compare flag (unsigned)", .{});
2616 },
2617 .compare_flags_signed => {
2618 return self.fail("TODO implement x86 ADD/SUB/CMP source compare flag (signed)", .{});
2619 },
26202809 }
26212810 },
26222811 .stack_offset => |off| {
......@@ -2629,7 +2818,7 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
26292818
26302819 switch (src_mcv) {
26312820 .none => unreachable,
2632 .undef => return self.genSetStack(dst_ty, off, .undef),
2821 .undef => return self.genSetStack(dst_ty, off, .undef, .{}),
26332822 .dead, .unreach => unreachable,
26342823 .ptr_stack_offset => unreachable,
26352824 .ptr_embedded_in_code => unreachable,
......@@ -2772,7 +2961,7 @@ fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !
27722961 .stack_offset => |off| {
27732962 switch (src_mcv) {
27742963 .none => unreachable,
2775 .undef => return self.genSetStack(dst_ty, off, .undef),
2964 .undef => return self.genSetStack(dst_ty, off, .undef, .{}),
27762965 .dead, .unreach => unreachable,
27772966 .ptr_stack_offset => unreachable,
27782967 .ptr_embedded_in_code => unreachable,
......@@ -2790,7 +2979,7 @@ fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !
27902979 .data = undefined,
27912980 });
27922981 // copy dst_reg back out
2793 return self.genSetStack(dst_ty, off, MCValue{ .register = dst_reg });
2982 return self.genSetStack(dst_ty, off, MCValue{ .register = dst_reg }, .{});
27942983 },
27952984 .immediate => |imm| {
27962985 _ = imm;
......@@ -2888,6 +3077,20 @@ fn airCall(self: *Self, inst: Air.Inst.Index) !void {
28883077 var info = try self.resolveCallingConventionValues(fn_ty);
28893078 defer info.deinit(self);
28903079
3080 try self.spillCompareFlagsIfOccupied();
3081
3082 if (info.return_value == .stack_offset) {
3083 const ret_ty = fn_ty.fnReturnType();
3084 const ret_abi_size = @intCast(u32, ret_ty.abiSize(self.target.*));
3085 const ret_abi_align = @intCast(u32, ret_ty.abiAlignment(self.target.*));
3086 const stack_offset = @intCast(i32, try self.allocMem(inst, ret_abi_size, ret_abi_align));
3087
3088 try self.register_manager.getReg(.rdi, inst);
3089 try self.genSetReg(Type.usize, .rdi, .{ .ptr_stack_offset = stack_offset });
3090
3091 info.return_value.stack_offset = stack_offset;
3092 }
3093
28913094 for (args) |arg, arg_i| {
28923095 const mc_arg = info.args[arg_i];
28933096 const arg_ty = self.air.typeOf(arg);
......@@ -3099,9 +3302,33 @@ fn airCall(self: *Self, inst: Air.Inst.Index) !void {
30993302 return bt.finishAir(result);
31003303}
31013304
3102fn ret(self: *Self, mcv: MCValue) !void {
3305fn airRet(self: *Self, inst: Air.Inst.Index) !void {
3306 const un_op = self.air.instructions.items(.data)[inst].un_op;
3307 const operand = try self.resolveInst(un_op);
31033308 const ret_ty = self.fn_type.fnReturnType();
3104 try self.setRegOrMem(ret_ty, self.ret_mcv, mcv);
3309 switch (self.ret_mcv) {
3310 .stack_offset => {
3311 // TODO audit register allocation!
3312 self.register_manager.freezeRegs(&.{ .rax, .rcx, .rdi });
3313 defer self.register_manager.unfreezeRegs(&.{ .rax, .rcx, .rdi });
3314 const reg = try self.register_manager.allocReg(null);
3315 self.ret_backpatch = try self.addInst(.{
3316 .tag = .mov,
3317 .ops = (Mir.Ops{
3318 .reg1 = reg,
3319 .reg2 = .rdi,
3320 }).encode(),
3321 .data = undefined,
3322 });
3323 try self.genSetStack(ret_ty, 0, operand, .{
3324 .source_stack_base = .rbp,
3325 .dest_stack_base = reg,
3326 });
3327 },
3328 else => {
3329 try self.setRegOrMem(ret_ty, self.ret_mcv, operand);
3330 },
3331 }
31053332 // TODO when implementing defer, this will need to jump to the appropriate defer expression.
31063333 // TODO optimization opportunity: figure out when we can emit this as a 2 byte instruction
31073334 // which is available if the jump is 127 bytes or less forward.
......@@ -3113,21 +3340,49 @@ fn ret(self: *Self, mcv: MCValue) !void {
31133340 .data = .{ .inst = undefined },
31143341 });
31153342 try self.exitlude_jump_relocs.append(self.gpa, jmp_reloc);
3116}
3117
3118fn airRet(self: *Self, inst: Air.Inst.Index) !void {
3119 const un_op = self.air.instructions.items(.data)[inst].un_op;
3120 const operand = try self.resolveInst(un_op);
3121 try self.ret(operand);
31223343 return self.finishAir(inst, .dead, .{ un_op, .none, .none });
31233344}
31243345
31253346fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
31263347 const un_op = self.air.instructions.items(.data)[inst].un_op;
31273348 const ptr = try self.resolveInst(un_op);
3128 // we can reuse self.ret_mcv because it just gets returned
3129 try self.load(self.ret_mcv, ptr, self.air.typeOf(un_op));
3130 try self.ret(self.ret_mcv);
3349 const ptr_ty = self.air.typeOf(un_op);
3350 const elem_ty = ptr_ty.elemType();
3351 switch (self.ret_mcv) {
3352 .stack_offset => {
3353 // TODO audit register allocation!
3354 self.register_manager.freezeRegs(&.{ .rax, .rcx, .rdi });
3355 defer self.register_manager.unfreezeRegs(&.{ .rax, .rcx, .rdi });
3356 const reg = try self.register_manager.allocReg(null);
3357 self.ret_backpatch = try self.addInst(.{
3358 .tag = .mov,
3359 .ops = (Mir.Ops{
3360 .reg1 = reg,
3361 .reg2 = .rdi,
3362 }).encode(),
3363 .data = undefined,
3364 });
3365 try self.genInlineMemcpy(0, elem_ty, ptr, .{
3366 .source_stack_base = .rbp,
3367 .dest_stack_base = reg,
3368 });
3369 },
3370 else => {
3371 try self.load(self.ret_mcv, ptr, ptr_ty);
3372 try self.setRegOrMem(elem_ty, self.ret_mcv, self.ret_mcv);
3373 },
3374 }
3375 // TODO when implementing defer, this will need to jump to the appropriate defer expression.
3376 // TODO optimization opportunity: figure out when we can emit this as a 2 byte instruction
3377 // which is available if the jump is 127 bytes or less forward.
3378 const jmp_reloc = try self.addInst(.{
3379 .tag = .jmp,
3380 .ops = (Mir.Ops{
3381 .flags = 0b00,
3382 }).encode(),
3383 .data = .{ .inst = undefined },
3384 });
3385 try self.exitlude_jump_relocs.append(self.gpa, jmp_reloc);
31313386 return self.finishAir(inst, .dead, .{ un_op, .none, .none });
31323387}
31333388
......@@ -3147,16 +3402,24 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
31473402 break :blk ty.intInfo(self.target.*).signedness;
31483403 };
31493404
3150 const lhs = try self.resolveInst(bin_op.lhs);
3151 const rhs = try self.resolveInst(bin_op.rhs);
3405 try self.spillCompareFlagsIfOccupied();
3406 self.compare_flags_inst = inst;
3407
31523408 const result: MCValue = result: {
31533409 // There are 2 operands, destination and source.
31543410 // Either one, but not both, can be a memory operand.
31553411 // Source operand can be an immediate, 8 bits or 32 bits.
3156 const dst_mcv = if (lhs.isImmediate() or (lhs.isMemory() and rhs.isMemory()))
3157 MCValue{ .register = try self.copyToTmpRegister(ty, lhs) }
3158 else
3159 lhs;
3412 // TODO look into reusing the operand
3413 const lhs = try self.resolveInst(bin_op.lhs);
3414 lhs.freezeIfRegister(&self.register_manager);
3415 defer lhs.unfreezeIfRegister(&self.register_manager);
3416
3417 const dst_reg = try self.copyToTmpRegister(ty, lhs);
3418 self.register_manager.freezeRegs(&.{dst_reg});
3419 defer self.register_manager.unfreezeRegs(&.{dst_reg});
3420
3421 const dst_mcv = MCValue{ .register = dst_reg };
3422
31603423 // This instruction supports only signed 32-bit immediates at most.
31613424 const src_mcv = try self.limitImmediateType(bin_op.rhs, i32);
31623425
......@@ -3166,6 +3429,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
31663429 .unsigned => MCValue{ .compare_flags_unsigned = op },
31673430 };
31683431 };
3432
31693433 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
31703434}
31713435
......@@ -3213,6 +3477,7 @@ fn genCondBrMir(self: *Self, ty: Type, mcv: MCValue) !u32 {
32133477 });
32143478 },
32153479 .register => |reg| {
3480 try self.spillCompareFlagsIfOccupied();
32163481 _ = try self.addInst(.{
32173482 .tag = .@"test",
32183483 .ops = (Mir.Ops{
......@@ -3229,19 +3494,15 @@ fn genCondBrMir(self: *Self, ty: Type, mcv: MCValue) !u32 {
32293494 .data = .{ .inst = undefined },
32303495 });
32313496 },
3232 .immediate => {
3233 if (abi_size <= 8) {
3234 const reg = try self.copyToTmpRegister(ty, mcv);
3235 return self.genCondBrMir(ty, .{ .register = reg });
3236 }
3237 return self.fail("TODO implement condbr when condition is immediate larger than 4 bytes", .{});
3238 },
3239 .stack_offset => {
3497 .immediate,
3498 .stack_offset,
3499 => {
3500 try self.spillCompareFlagsIfOccupied();
32403501 if (abi_size <= 8) {
32413502 const reg = try self.copyToTmpRegister(ty, mcv);
32423503 return self.genCondBrMir(ty, .{ .register = reg });
32433504 }
3244 return self.fail("TODO implement condbr when condition is stack offset with abi larger than 8 bytes", .{});
3505 return self.fail("TODO implement condbr when condition is {} with abi larger than 8 bytes", .{mcv});
32453506 },
32463507 else => return self.fail("TODO implement condbr when condition is {s}", .{@tagName(mcv)}),
32473508 }
......@@ -3258,9 +3519,23 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
32583519
32593520 const reloc = try self.genCondBrMir(cond_ty, cond);
32603521
3522 // If the condition dies here in this condbr instruction, process
3523 // that death now instead of later as this has an effect on
3524 // whether it needs to be spilled in the branches
3525 // TODO I need investigate how to make this work without removing
3526 // an assertion from getResolvedInstValue()
3527 if (self.liveness.operandDies(inst, 0)) {
3528 const op_int = @enumToInt(pl_op.operand);
3529 if (op_int >= Air.Inst.Ref.typed_value_map.len) {
3530 const op_index = @intCast(Air.Inst.Index, op_int - Air.Inst.Ref.typed_value_map.len);
3531 self.processDeath(op_index);
3532 }
3533 }
3534
32613535 // Capture the state of register and stack allocation state so that we can revert to it.
32623536 const parent_next_stack_offset = self.next_stack_offset;
32633537 const parent_free_registers = self.register_manager.free_registers;
3538 const parent_compare_flags_inst = self.compare_flags_inst;
32643539 var parent_stack = try self.stack.clone(self.gpa);
32653540 defer parent_stack.deinit(self.gpa);
32663541 const parent_registers = self.register_manager.registers;
......@@ -3282,6 +3557,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
32823557 defer saved_then_branch.deinit(self.gpa);
32833558
32843559 self.register_manager.registers = parent_registers;
3560 self.compare_flags_inst = parent_compare_flags_inst;
32853561
32863562 self.stack.deinit(self.gpa);
32873563 self.stack = parent_stack;
......@@ -3352,6 +3628,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
33523628 // We already deleted the items from this table that matched the else_branch.
33533629 // So these are all instructions that are only overridden in the then branch.
33543630 parent_branch.inst_table.putAssumeCapacity(then_key, then_value);
3631 log.debug("then_value = {}", .{then_value});
33553632 if (then_value == .dead)
33563633 continue;
33573634 const parent_mcv = blk: {
......@@ -3376,23 +3653,31 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
33763653 return self.finishAir(inst, .unreach, .{ pl_op.operand, .none, .none });
33773654}
33783655
3379fn isNull(self: *Self, ty: Type, operand: MCValue) !MCValue {
3656fn isNull(self: *Self, inst: Air.Inst.Index, ty: Type, operand: MCValue) !MCValue {
3657 try self.spillCompareFlagsIfOccupied();
3658 self.compare_flags_inst = inst;
3659
33803660 try self.genBinMathOpMir(.cmp, ty, operand, MCValue{ .immediate = 0 });
33813661 return MCValue{ .compare_flags_unsigned = .eq };
33823662}
33833663
3384fn isNonNull(self: *Self, ty: Type, operand: MCValue) !MCValue {
3385 const is_null_res = try self.isNull(ty, operand);
3664fn isNonNull(self: *Self, inst: Air.Inst.Index, ty: Type, operand: MCValue) !MCValue {
3665 const is_null_res = try self.isNull(inst, ty, operand);
33863666 assert(is_null_res.compare_flags_unsigned == .eq);
33873667 return MCValue{ .compare_flags_unsigned = .neq };
33883668}
33893669
3390fn isErr(self: *Self, ty: Type, operand: MCValue) !MCValue {
3670fn isErr(self: *Self, inst: Air.Inst.Index, ty: Type, operand: MCValue) !MCValue {
33913671 const err_type = ty.errorUnionSet();
33923672 const payload_type = ty.errorUnionPayload();
33933673 if (!err_type.hasRuntimeBits()) {
33943674 return MCValue{ .immediate = 0 }; // always false
3395 } else if (!payload_type.hasRuntimeBits()) {
3675 }
3676
3677 try self.spillCompareFlagsIfOccupied();
3678 self.compare_flags_inst = inst;
3679
3680 if (!payload_type.hasRuntimeBits()) {
33963681 if (err_type.abiSize(self.target.*) <= 8) {
33973682 try self.genBinMathOpMir(.cmp, err_type, operand, MCValue{ .immediate = 0 });
33983683 return MCValue{ .compare_flags_unsigned = .gt };
......@@ -3400,12 +3685,13 @@ fn isErr(self: *Self, ty: Type, operand: MCValue) !MCValue {
34003685 return self.fail("TODO isErr for errors with size larger than register size", .{});
34013686 }
34023687 } else {
3403 return self.fail("TODO isErr for non-empty payloads", .{});
3688 try self.genBinMathOpMir(.cmp, err_type, operand, MCValue{ .immediate = 0 });
3689 return MCValue{ .compare_flags_unsigned = .gt };
34043690 }
34053691}
34063692
3407fn isNonErr(self: *Self, ty: Type, operand: MCValue) !MCValue {
3408 const is_err_res = try self.isErr(ty, operand);
3693fn isNonErr(self: *Self, inst: Air.Inst.Index, ty: Type, operand: MCValue) !MCValue {
3694 const is_err_res = try self.isErr(inst, ty, operand);
34093695 switch (is_err_res) {
34103696 .compare_flags_unsigned => |op| {
34113697 assert(op == .gt);
......@@ -3424,7 +3710,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
34243710 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
34253711 const operand = try self.resolveInst(un_op);
34263712 const ty = self.air.typeOf(un_op);
3427 break :result try self.isNull(ty, operand);
3713 break :result try self.isNull(inst, ty, operand);
34283714 };
34293715 return self.finishAir(inst, result, .{ un_op, .none, .none });
34303716}
......@@ -3445,7 +3731,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
34453731 };
34463732 const ptr_ty = self.air.typeOf(un_op);
34473733 try self.load(operand, operand_ptr, ptr_ty);
3448 break :result try self.isNull(ptr_ty.elemType(), operand);
3734 break :result try self.isNull(inst, ptr_ty.elemType(), operand);
34493735 };
34503736 return self.finishAir(inst, result, .{ un_op, .none, .none });
34513737}
......@@ -3455,7 +3741,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
34553741 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
34563742 const operand = try self.resolveInst(un_op);
34573743 const ty = self.air.typeOf(un_op);
3458 break :result try self.isNonNull(ty, operand);
3744 break :result try self.isNonNull(inst, ty, operand);
34593745 };
34603746 return self.finishAir(inst, result, .{ un_op, .none, .none });
34613747}
......@@ -3476,7 +3762,7 @@ fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
34763762 };
34773763 const ptr_ty = self.air.typeOf(un_op);
34783764 try self.load(operand, operand_ptr, ptr_ty);
3479 break :result try self.isNonNull(ptr_ty.elemType(), operand);
3765 break :result try self.isNonNull(inst, ptr_ty.elemType(), operand);
34803766 };
34813767 return self.finishAir(inst, result, .{ un_op, .none, .none });
34823768}
......@@ -3486,7 +3772,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
34863772 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
34873773 const operand = try self.resolveInst(un_op);
34883774 const ty = self.air.typeOf(un_op);
3489 break :result try self.isErr(ty, operand);
3775 break :result try self.isErr(inst, ty, operand);
34903776 };
34913777 return self.finishAir(inst, result, .{ un_op, .none, .none });
34923778}
......@@ -3507,7 +3793,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
35073793 };
35083794 const ptr_ty = self.air.typeOf(un_op);
35093795 try self.load(operand, operand_ptr, ptr_ty);
3510 break :result try self.isErr(ptr_ty.elemType(), operand);
3796 break :result try self.isErr(inst, ptr_ty.elemType(), operand);
35113797 };
35123798 return self.finishAir(inst, result, .{ un_op, .none, .none });
35133799}
......@@ -3517,7 +3803,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
35173803 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
35183804 const operand = try self.resolveInst(un_op);
35193805 const ty = self.air.typeOf(un_op);
3520 break :result try self.isNonErr(ty, operand);
3806 break :result try self.isNonErr(inst, ty, operand);
35213807 };
35223808 return self.finishAir(inst, result, .{ un_op, .none, .none });
35233809}
......@@ -3538,7 +3824,7 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
35383824 };
35393825 const ptr_ty = self.air.typeOf(un_op);
35403826 try self.load(operand, operand_ptr, ptr_ty);
3541 break :result try self.isNonErr(ptr_ty.elemType(), operand);
3827 break :result try self.isNonErr(inst, ptr_ty.elemType(), operand);
35423828 };
35433829 return self.finishAir(inst, result, .{ un_op, .none, .none });
35443830}
......@@ -3584,12 +3870,185 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
35843870 return self.finishAir(inst, result, .{ .none, .none, .none });
35853871}
35863872
3873fn genCondSwitchMir(self: *Self, ty: Type, condition: MCValue, case: MCValue) !u32 {
3874 const abi_size = @intCast(u32, ty.abiSize(self.target.*));
3875 switch (condition) {
3876 .none => unreachable,
3877 .undef => unreachable,
3878 .dead, .unreach => unreachable,
3879 .compare_flags_signed => unreachable,
3880 .compare_flags_unsigned => unreachable,
3881 .register => |cond_reg| {
3882 try self.spillCompareFlagsIfOccupied();
3883
3884 self.register_manager.freezeRegs(&.{cond_reg});
3885 defer self.register_manager.unfreezeRegs(&.{cond_reg});
3886
3887 switch (case) {
3888 .none => unreachable,
3889 .undef => unreachable,
3890 .dead, .unreach => unreachable,
3891 .immediate => |imm| {
3892 _ = try self.addInst(.{
3893 .tag = .@"test",
3894 .ops = (Mir.Ops{
3895 .reg1 = registerAlias(cond_reg, abi_size),
3896 }).encode(),
3897 .data = .{ .imm = @intCast(u32, imm) },
3898 });
3899 return self.addInst(.{
3900 .tag = .cond_jmp_eq_ne,
3901 .ops = (Mir.Ops{
3902 .flags = 0b00,
3903 }).encode(),
3904 .data = .{ .inst = undefined },
3905 });
3906 },
3907 .register => |reg| {
3908 _ = try self.addInst(.{
3909 .tag = .@"test",
3910 .ops = (Mir.Ops{
3911 .reg1 = registerAlias(cond_reg, abi_size),
3912 .reg2 = registerAlias(reg, abi_size),
3913 }).encode(),
3914 .data = undefined,
3915 });
3916 return self.addInst(.{
3917 .tag = .cond_jmp_eq_ne,
3918 .ops = (Mir.Ops{
3919 .flags = 0b00,
3920 }).encode(),
3921 .data = .{ .inst = undefined },
3922 });
3923 },
3924 .stack_offset => {
3925 if (abi_size <= 8) {
3926 const reg = try self.copyToTmpRegister(ty, case);
3927 return self.genCondSwitchMir(ty, condition, .{ .register = reg });
3928 }
3929
3930 return self.fail("TODO implement switch mir when case is stack offset with abi larger than 8 bytes", .{});
3931 },
3932 else => {
3933 return self.fail("TODO implement switch mir when case is {}", .{case});
3934 },
3935 }
3936 },
3937 .stack_offset => {
3938 try self.spillCompareFlagsIfOccupied();
3939
3940 if (abi_size <= 8) {
3941 const reg = try self.copyToTmpRegister(ty, condition);
3942 self.register_manager.freezeRegs(&.{reg});
3943 defer self.register_manager.unfreezeRegs(&.{reg});
3944 return self.genCondSwitchMir(ty, .{ .register = reg }, case);
3945 }
3946
3947 return self.fail("TODO implement switch mir when condition is stack offset with abi larger than 8 bytes", .{});
3948 },
3949 else => {
3950 return self.fail("TODO implemenent switch mir when condition is {}", .{condition});
3951 },
3952 }
3953}
3954
35873955fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
35883956 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
3589 const condition = pl_op.operand;
3590 _ = condition;
3591 return self.fail("TODO airSwitch for {}", .{self.target.cpu.arch});
3592 // return self.finishAir(inst, .dead, .{ condition, .none, .none });
3957 const condition = try self.resolveInst(pl_op.operand);
3958 const condition_ty = self.air.typeOf(pl_op.operand);
3959 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
3960 var extra_index: usize = switch_br.end;
3961 var case_i: u32 = 0;
3962 const liveness = try self.liveness.getSwitchBr(
3963 self.gpa,
3964 inst,
3965 switch_br.data.cases_len + 1,
3966 );
3967 defer self.gpa.free(liveness.deaths);
3968
3969 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
3970 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
3971 const items = @bitCast([]const Air.Inst.Ref, self.air.extra[case.end..][0..case.data.items_len]);
3972 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];
3973 extra_index = case.end + items.len + case_body.len;
3974
3975 var relocs = try self.gpa.alloc(u32, items.len);
3976 defer self.gpa.free(relocs);
3977
3978 for (items) |item, item_i| {
3979 const item_mcv = try self.resolveInst(item);
3980 relocs[item_i] = try self.genCondSwitchMir(condition_ty, condition, item_mcv);
3981 }
3982
3983 // If the condition dies here in this condbr instruction, process
3984 // that death now instead of later as this has an effect on
3985 // whether it needs to be spilled in the branches
3986 // TODO I need investigate how to make this work without removing
3987 // an assertion from getResolvedInstValue()
3988 if (self.liveness.operandDies(inst, 0)) {
3989 const op_int = @enumToInt(pl_op.operand);
3990 if (op_int >= Air.Inst.Ref.typed_value_map.len) {
3991 const op_index = @intCast(Air.Inst.Index, op_int - Air.Inst.Ref.typed_value_map.len);
3992 self.processDeath(op_index);
3993 }
3994 }
3995
3996 // Capture the state of register and stack allocation state so that we can revert to it.
3997 const parent_next_stack_offset = self.next_stack_offset;
3998 const parent_free_registers = self.register_manager.free_registers;
3999 const parent_compare_flags_inst = self.compare_flags_inst;
4000 var parent_stack = try self.stack.clone(self.gpa);
4001 defer parent_stack.deinit(self.gpa);
4002 const parent_registers = self.register_manager.registers;
4003
4004 try self.branch_stack.append(.{});
4005 errdefer {
4006 _ = self.branch_stack.pop();
4007 }
4008
4009 try self.ensureProcessDeathCapacity(liveness.deaths[case_i].len);
4010 for (liveness.deaths[case_i]) |operand| {
4011 self.processDeath(operand);
4012 }
4013
4014 try self.genBody(case_body);
4015
4016 // Revert to the previous register and stack allocation state.
4017 var saved_case_branch = self.branch_stack.pop();
4018 defer saved_case_branch.deinit(self.gpa);
4019
4020 self.register_manager.registers = parent_registers;
4021 self.compare_flags_inst = parent_compare_flags_inst;
4022 self.stack.deinit(self.gpa);
4023 self.stack = parent_stack;
4024 parent_stack = .{};
4025
4026 self.next_stack_offset = parent_next_stack_offset;
4027 self.register_manager.free_registers = parent_free_registers;
4028
4029 for (relocs) |reloc| {
4030 try self.performReloc(reloc);
4031 }
4032 }
4033
4034 if (switch_br.data.else_body_len > 0) {
4035 const else_body = self.air.extra[extra_index..][0..switch_br.data.else_body_len];
4036 try self.branch_stack.append(.{});
4037 defer self.branch_stack.pop().deinit(self.gpa);
4038
4039 const else_deaths = liveness.deaths.len - 1;
4040 try self.ensureProcessDeathCapacity(liveness.deaths[else_deaths].len);
4041 for (liveness.deaths[else_deaths]) |operand| {
4042 self.processDeath(operand);
4043 }
4044
4045 try self.genBody(else_body);
4046
4047 // TODO consolidate returned MCValues between prongs and else branch like we do
4048 // in airCondBr.
4049 }
4050
4051 return self.finishAir(inst, .unreach, .{ pl_op.operand, .none, .none });
35934052}
35944053
35954054fn performReloc(self: *Self, reloc: Mir.Inst.Index) !void {
......@@ -3628,7 +4087,7 @@ fn br(self: *Self, block: Air.Inst.Index, operand: Air.Inst.Ref) !void {
36284087 block_data.mcv = switch (operand_mcv) {
36294088 .none, .dead, .unreach => unreachable,
36304089 .register, .stack_offset, .memory => operand_mcv,
3631 .immediate => blk: {
4090 .compare_flags_signed, .compare_flags_unsigned, .immediate => blk: {
36324091 const new_mcv = try self.allocRegOrMem(block, true);
36334092 try self.setRegOrMem(self.air.typeOfIndex(block), new_mcv, operand_mcv);
36344093 break :blk new_mcv;
......@@ -3828,7 +4287,7 @@ fn setRegOrMem(self: *Self, ty: Type, loc: MCValue, val: MCValue) !void {
38284287 .none => return,
38294288 .immediate => unreachable,
38304289 .register => |reg| return self.genSetReg(ty, reg, val),
3831 .stack_offset => |off| return self.genSetStack(ty, off, val),
4290 .stack_offset => |off| return self.genSetStack(ty, off, val, .{}),
38324291 .memory => {
38334292 return self.fail("TODO implement setRegOrMem for memory", .{});
38344293 },
......@@ -3849,7 +4308,9 @@ fn genSetStackArg(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerE
38494308 const reg = try self.copyToTmpRegister(ty, mcv);
38504309 return self.genSetStackArg(ty, stack_offset, MCValue{ .register = reg });
38514310 }
3852 try self.genInlineMemset(stack_offset, .rsp, ty, .{ .immediate = 0xaa });
4311 try self.genInlineMemset(stack_offset, ty, .{ .immediate = 0xaa }, .{
4312 .dest_stack_base = .rsp,
4313 });
38534314 },
38544315 .compare_flags_unsigned,
38554316 .compare_flags_signed,
......@@ -3904,7 +4365,10 @@ fn genSetStackArg(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerE
39044365 return self.genSetStackArg(ty, stack_offset, MCValue{ .register = reg });
39054366 }
39064367
3907 try self.genInlineMemcpy(stack_offset, .rsp, ty, mcv);
4368 try self.genInlineMemcpy(stack_offset, ty, mcv, .{
4369 .source_stack_base = .rbp,
4370 .dest_stack_base = .rsp,
4371 });
39084372 },
39094373 .register => |reg| {
39104374 _ = try self.addInst(.{
......@@ -3927,12 +4391,15 @@ fn genSetStackArg(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerE
39274391 return self.genSetStackArg(ty, stack_offset, MCValue{ .register = reg });
39284392 }
39294393
3930 try self.genInlineMemcpy(stack_offset, .rsp, ty, mcv);
4394 try self.genInlineMemcpy(stack_offset, ty, mcv, .{
4395 .source_stack_base = .rbp,
4396 .dest_stack_base = .rsp,
4397 });
39314398 },
39324399 }
39334400}
39344401
3935fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerError!void {
4402fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue, opts: InlineMemcpyOpts) InnerError!void {
39364403 const abi_size = ty.abiSize(self.target.*);
39374404 switch (mcv) {
39384405 .dead => unreachable,
......@@ -3943,23 +4410,21 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerErro
39434410 return; // The already existing value will do just fine.
39444411 // TODO Upgrade this to a memset call when we have that available.
39454412 switch (ty.abiSize(self.target.*)) {
3946 1 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaa }),
3947 2 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaaaa }),
3948 4 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaaaaaaaa }),
3949 8 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaaaaaaaaaaaaaaaa }),
3950 else => return self.genInlineMemset(stack_offset, .rbp, ty, .{ .immediate = 0xaa }),
4413 1 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaa }, opts),
4414 2 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaaaa }, opts),
4415 4 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaaaaaaaa }, opts),
4416 8 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaaaaaaaaaaaaaaaa }, opts),
4417 else => return self.genInlineMemset(stack_offset, ty, .{ .immediate = 0xaa }, opts),
39514418 }
39524419 },
39534420 .compare_flags_unsigned,
39544421 .compare_flags_signed,
39554422 => {
39564423 const reg = try self.copyToTmpRegister(ty, mcv);
3957 return self.genSetStack(ty, stack_offset, .{ .register = reg });
4424 return self.genSetStack(ty, stack_offset, .{ .register = reg }, opts);
39584425 },
39594426 .immediate => |x_big| {
3960 if (stack_offset > 128) {
3961 return self.fail("TODO implement set stack variable with large stack offset", .{});
3962 }
4427 const base_reg = opts.dest_stack_base orelse .rbp;
39634428 switch (abi_size) {
39644429 1, 2, 4 => {
39654430 const payload = try self.addExtra(Mir.ImmPair{
......@@ -3969,7 +4434,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerErro
39694434 _ = try self.addInst(.{
39704435 .tag = .mov_mem_imm,
39714436 .ops = (Mir.Ops{
3972 .reg1 = .rbp,
4437 .reg1 = base_reg,
39734438 .flags = switch (abi_size) {
39744439 1 => 0b00,
39754440 2 => 0b01,
......@@ -3991,7 +4456,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerErro
39914456 _ = try self.addInst(.{
39924457 .tag = .mov_mem_imm,
39934458 .ops = (Mir.Ops{
3994 .reg1 = .rbp,
4459 .reg1 = base_reg,
39954460 .flags = 0b10,
39964461 }).encode(),
39974462 .data = .{ .payload = payload },
......@@ -4005,7 +4470,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerErro
40054470 _ = try self.addInst(.{
40064471 .tag = .mov_mem_imm,
40074472 .ops = (Mir.Ops{
4008 .reg1 = .rbp,
4473 .reg1 = base_reg,
40094474 .flags = 0b10,
40104475 }).encode(),
40114476 .data = .{ .payload = payload },
......@@ -4022,6 +4487,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerErro
40224487 return self.fail("stack offset too large", .{});
40234488 }
40244489
4490 const base_reg = opts.dest_stack_base orelse .rbp;
40254491 const is_power_of_two = (abi_size % 2) == 0;
40264492 if (!is_power_of_two) {
40274493 self.register_manager.freezeRegs(&.{reg});
......@@ -4037,7 +4503,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerErro
40374503 _ = try self.addInst(.{
40384504 .tag = .mov,
40394505 .ops = (Mir.Ops{
4040 .reg1 = .rbp,
4506 .reg1 = base_reg,
40414507 .reg2 = registerAlias(tmp_reg, closest_power_of_two),
40424508 .flags = 0b10,
40434509 }).encode(),
......@@ -4062,7 +4528,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerErro
40624528 _ = try self.addInst(.{
40634529 .tag = .mov,
40644530 .ops = (Mir.Ops{
4065 .reg1 = .rbp,
4531 .reg1 = base_reg,
40664532 .reg2 = registerAlias(reg, @intCast(u32, abi_size)),
40674533 .flags = 0b10,
40684534 }).encode(),
......@@ -4077,14 +4543,14 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerErro
40774543 => {
40784544 if (abi_size <= 8) {
40794545 const reg = try self.copyToTmpRegister(ty, mcv);
4080 return self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
4546 return self.genSetStack(ty, stack_offset, MCValue{ .register = reg }, opts);
40814547 }
40824548
4083 try self.genInlineMemcpy(stack_offset, .rbp, ty, mcv);
4549 try self.genInlineMemcpy(stack_offset, ty, mcv, opts);
40844550 },
40854551 .ptr_stack_offset => {
40864552 const reg = try self.copyToTmpRegister(ty, mcv);
4087 return self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
4553 return self.genSetStack(ty, stack_offset, MCValue{ .register = reg }, opts);
40884554 },
40894555 .stack_offset => |off| {
40904556 if (stack_offset == off) {
......@@ -4094,22 +4560,35 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerErro
40944560
40954561 if (abi_size <= 8) {
40964562 const reg = try self.copyToTmpRegister(ty, mcv);
4097 return self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
4563 return self.genSetStack(ty, stack_offset, MCValue{ .register = reg }, opts);
40984564 }
40994565
4100 try self.genInlineMemcpy(stack_offset, .rbp, ty, mcv);
4566 try self.genInlineMemcpy(stack_offset, ty, mcv, opts);
41014567 },
41024568 }
41034569}
41044570
4105fn genInlineMemcpy(self: *Self, stack_offset: i32, stack_reg: Register, ty: Type, val: MCValue) InnerError!void {
4571const InlineMemcpyOpts = struct {
4572 source_stack_base: ?Register = null,
4573 dest_stack_base: ?Register = null,
4574};
4575
4576fn genInlineMemcpy(self: *Self, stack_offset: i32, ty: Type, val: MCValue, opts: InlineMemcpyOpts) InnerError!void {
41064577 const abi_size = ty.abiSize(self.target.*);
41074578
4579 // TODO this is wrong. We should check first if any of the operands is in `.rax` or `.rcx` before
4580 // spilling. Consolidate with other TODOs regarding register allocation mechanics.
41084581 try self.register_manager.getReg(.rax, null);
41094582 try self.register_manager.getReg(.rcx, null);
41104583
4111 self.register_manager.freezeRegs(&.{ .rax, .rcx, .rbp });
4112 defer self.register_manager.unfreezeRegs(&.{ .rax, .rcx, .rbp });
4584 self.register_manager.freezeRegs(&.{ .rax, .rcx });
4585 defer self.register_manager.unfreezeRegs(&.{ .rax, .rcx });
4586
4587 if (opts.source_stack_base) |reg| self.register_manager.freezeRegs(&.{reg});
4588 defer if (opts.source_stack_base) |reg| self.register_manager.unfreezeRegs(&.{reg});
4589
4590 if (opts.dest_stack_base) |reg| self.register_manager.freezeRegs(&.{reg});
4591 defer if (opts.dest_stack_base) |reg| self.register_manager.unfreezeRegs(&.{reg});
41134592
41144593 const addr_reg: Register = blk: {
41154594 switch (val) {
......@@ -4119,13 +4598,13 @@ fn genInlineMemcpy(self: *Self, stack_offset: i32, stack_reg: Register, ty: Type
41194598 => {
41204599 break :blk try self.loadMemPtrIntoRegister(Type.usize, val);
41214600 },
4122 .stack_offset => |off| {
4601 .ptr_stack_offset, .stack_offset => |off| {
41234602 const addr_reg = (try self.register_manager.allocReg(null)).to64();
41244603 _ = try self.addInst(.{
41254604 .tag = .lea,
41264605 .ops = (Mir.Ops{
41274606 .reg1 = addr_reg,
4128 .reg2 = .rbp,
4607 .reg2 = opts.source_stack_base orelse .rbp,
41294608 }).encode(),
41304609 .data = .{ .imm = @bitCast(u32, -off) },
41314610 });
......@@ -4207,7 +4686,7 @@ fn genInlineMemcpy(self: *Self, stack_offset: i32, stack_reg: Register, ty: Type
42074686 _ = try self.addInst(.{
42084687 .tag = .mov_scale_dst,
42094688 .ops = (Mir.Ops{
4210 .reg1 = stack_reg,
4689 .reg1 = opts.dest_stack_base orelse .rbp,
42114690 .reg2 = tmp_reg.to8(),
42124691 }).encode(),
42134692 .data = .{ .imm = @bitCast(u32, -stack_offset) },
......@@ -4254,9 +4733,9 @@ fn genInlineMemcpy(self: *Self, stack_offset: i32, stack_reg: Register, ty: Type
42544733fn genInlineMemset(
42554734 self: *Self,
42564735 stack_offset: i32,
4257 stack_register: Register,
42584736 ty: Type,
42594737 value: MCValue,
4738 opts: InlineMemcpyOpts,
42604739) InnerError!void {
42614740 try self.register_manager.getReg(.rax, null);
42624741
......@@ -4321,7 +4800,7 @@ fn genInlineMemset(
43214800 _ = try self.addInst(.{
43224801 .tag = .mov_mem_index_imm,
43234802 .ops = (Mir.Ops{
4324 .reg1 = stack_register.to64(),
4803 .reg1 = opts.dest_stack_base orelse .rbp,
43254804 }).encode(),
43264805 .data = .{ .payload = payload },
43274806 });
......@@ -4653,8 +5132,8 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
46535132 const array_len = array_ty.arrayLenIncludingSentinel();
46545133 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else blk: {
46555134 const stack_offset = @intCast(i32, try self.allocMem(inst, 16, 16));
4656 try self.genSetStack(ptr_ty, stack_offset, ptr);
4657 try self.genSetStack(Type.initTag(.u64), stack_offset - 8, .{ .immediate = array_len });
5135 try self.genSetStack(ptr_ty, stack_offset, ptr, .{});
5136 try self.genSetStack(Type.initTag(.u64), stack_offset - 8, .{ .immediate = array_len }, .{});
46585137 break :blk .{ .stack_offset = stack_offset };
46595138 };
46605139 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
......@@ -4808,7 +5287,8 @@ fn getResolvedInstValue(self: *Self, inst: Air.Inst.Index) MCValue {
48085287 while (true) {
48095288 i -= 1;
48105289 if (self.branch_stack.items[i].inst_table.get(inst)) |mcv| {
4811 assert(mcv != .dead);
5290 // TODO see comment in `airCondBr` and `airSwitch`
5291 // assert(mcv != .dead);
48125292 return mcv;
48135293 }
48145294 }
......@@ -4979,22 +5459,18 @@ fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue {
49795459 const error_type = typed_value.ty.errorUnionSet();
49805460 const payload_type = typed_value.ty.errorUnionPayload();
49815461
4982 if (typed_value.val.castTag(.eu_payload)) |pl| {
5462 if (typed_value.val.castTag(.eu_payload)) |_| {
49835463 if (!payload_type.hasRuntimeBits()) {
49845464 // We use the error type directly as the type.
49855465 return MCValue{ .immediate = 0 };
49865466 }
4987
4988 _ = pl;
4989 return self.fail("TODO implement error union const of type '{}' (non-error)", .{typed_value.ty});
49905467 } else {
49915468 if (!payload_type.hasRuntimeBits()) {
49925469 // We use the error type directly as the type.
49935470 return self.genTypedValue(.{ .ty = error_type, .val = typed_value.val });
49945471 }
49955472 }
4996
4997 return self.fail("TODO implement error union const of type '{}' (error)", .{typed_value.ty});
5473 return self.lowerUnnamedConst(typed_value);
49985474 },
49995475 .Struct => {
50005476 return self.lowerUnnamedConst(typed_value);
......@@ -5041,6 +5517,25 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
50415517 return result;
50425518 },
50435519 .Unspecified, .C => {
5520 // Return values
5521 if (ret_ty.zigTypeTag() == .NoReturn) {
5522 result.return_value = .{ .unreach = {} };
5523 } else if (!ret_ty.hasRuntimeBits()) {
5524 result.return_value = .{ .none = {} };
5525 } else {
5526 const ret_ty_size = @intCast(u32, ret_ty.abiSize(self.target.*));
5527 if (ret_ty_size <= 8) {
5528 const aliased_reg = registerAlias(c_abi_int_return_regs[0], ret_ty_size);
5529 result.return_value = .{ .register = aliased_reg };
5530 } else {
5531 // We simply make the return MCValue a stack offset. However, the actual value
5532 // for the offset will be populated later. We will also push the stack offset
5533 // value into .rdi register when we resolve the offset.
5534 result.return_value = .{ .stack_offset = 0 };
5535 }
5536 }
5537
5538 // Input params
50445539 // First, split into args that can be passed via registers.
50455540 // This will make it easier to then push the rest of args in reverse
50465541 // order on the stack.
......@@ -5084,7 +5579,10 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
50845579 }
50855580 }
50865581
5087 var next_stack_offset: u32 = 0;
5582 var next_stack_offset: u32 = switch (result.return_value) {
5583 .stack_offset => |off| @intCast(u32, off),
5584 else => 0,
5585 };
50885586 var count: usize = param_types.len;
50895587 while (count > 0) : (count -= 1) {
50905588 const i = count - 1;
......@@ -5108,28 +5606,15 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
51085606 }
51095607
51105608 result.stack_align = 16;
5609 // TODO fix this so that the 16byte alignment padding is at the current value of $rsp, and push
5610 // the args onto the stack so that there is no padding between the first argument and
5611 // the standard preamble.
5612 // alignment padding | args ... | ret addr | $rbp |
51115613 result.stack_byte_count = mem.alignForwardGeneric(u32, next_stack_offset, result.stack_align);
51125614 },
5113 else => return self.fail("TODO implement function parameters for {} on x86_64", .{cc}),
5615 else => return self.fail("TODO implement function parameters and return values for {} on x86_64", .{cc}),
51145616 }
51155617
5116 if (ret_ty.zigTypeTag() == .NoReturn) {
5117 result.return_value = .{ .unreach = {} };
5118 } else if (!ret_ty.hasRuntimeBits()) {
5119 result.return_value = .{ .none = {} };
5120 } else switch (cc) {
5121 .Naked => unreachable,
5122 .Unspecified, .C => {
5123 const ret_ty_size = @intCast(u32, ret_ty.abiSize(self.target.*));
5124 if (ret_ty_size <= 8) {
5125 const aliased_reg = registerAlias(c_abi_int_return_regs[0], ret_ty_size);
5126 result.return_value = .{ .register = aliased_reg };
5127 } else {
5128 return self.fail("TODO support more return types for x86_64 backend", .{});
5129 }
5130 },
5131 else => return self.fail("TODO implement function return values for {}", .{cc}),
5132 }
51335618 return result;
51345619}
51355620
src/arch/x86_64/Emit.zig+8
......@@ -162,6 +162,8 @@ pub fn lowerMir(emit: *Emit) InnerError!void {
162162 => try emit.mirCondSetByte(tag, inst),
163163
164164 .cond_mov_eq => try emit.mirCondMov(.cmove, inst),
165 .cond_mov_lt => try emit.mirCondMov(.cmovl, inst),
166 .cond_mov_below => try emit.mirCondMov(.cmovb, inst),
165167
166168 .ret => try emit.mirRet(inst),
167169
......@@ -1180,6 +1182,10 @@ const Tag = enum {
11801182 cqo,
11811183 cmove,
11821184 cmovz,
1185 cmovl,
1186 cmovng,
1187 cmovb,
1188 cmovnae,
11831189
11841190 fn isSetCC(tag: Tag) bool {
11851191 return switch (tag) {
......@@ -1406,6 +1412,8 @@ inline fn getOpCode(tag: Tag, enc: Encoding, is_one_byte: bool) ?OpCode {
14061412 .lea => OpCode.oneByte(if (is_one_byte) 0x8c else 0x8d),
14071413 .imul => OpCode.twoByte(0x0f, 0xaf),
14081414 .cmove, .cmovz => OpCode.twoByte(0x0f, 0x44),
1415 .cmovb, .cmovnae => OpCode.twoByte(0x0f, 0x42),
1416 .cmovl, .cmovng => OpCode.twoByte(0x0f, 0x4c),
14091417 else => null,
14101418 },
14111419 .oi => return switch (tag) {
src/arch/x86_64/Mir.zig+4-1
......@@ -292,6 +292,8 @@ pub const Inst = struct {
292292 /// 0b10 reg1, dword ptr [reg2 + imm]
293293 /// 0b11 reg1, qword ptr [reg2 + imm]
294294 cond_mov_eq,
295 cond_mov_lt,
296 cond_mov_below,
295297
296298 /// ops flags: form:
297299 /// 0b00 reg1
......@@ -314,7 +316,8 @@ pub const Inst = struct {
314316 syscall,
315317
316318 /// ops flags: form:
317 /// 0b00 reg1, imm32
319 /// 0b00 reg1, imm32 if reg2 == .none
320 /// 0b00 reg1, reg2
318321 /// TODO handle more cases
319322 @"test",
320323
src/codegen.zig+119-1
......@@ -205,13 +205,62 @@ pub fn generateSymbol(
205205 .appended => {},
206206 .externally_managed => |slice| {
207207 code.appendSliceAssumeCapacity(slice);
208 return Result{ .appended = {} };
209208 },
210209 .fail => |em| return Result{ .fail = em },
211210 }
212211 }
213212 return Result{ .appended = {} };
214213 },
214 .repeated => {
215 const array = typed_value.val.castTag(.repeated).?.data;
216 const elem_ty = typed_value.ty.childType();
217 const sentinel = typed_value.ty.sentinel();
218 const len = typed_value.ty.arrayLen();
219
220 var index: u64 = 0;
221 while (index < len) : (index += 1) {
222 switch (try generateSymbol(bin_file, parent_atom_index, src_loc, .{
223 .ty = elem_ty,
224 .val = array,
225 }, code, debug_output)) {
226 .appended => {},
227 .externally_managed => |slice| {
228 code.appendSliceAssumeCapacity(slice);
229 },
230 .fail => |em| return Result{ .fail = em },
231 }
232 }
233
234 if (sentinel) |sentinel_val| {
235 switch (try generateSymbol(bin_file, parent_atom_index, src_loc, .{
236 .ty = elem_ty,
237 .val = sentinel_val,
238 }, code, debug_output)) {
239 .appended => {},
240 .externally_managed => |slice| {
241 code.appendSliceAssumeCapacity(slice);
242 },
243 .fail => |em| return Result{ .fail = em },
244 }
245 }
246
247 return Result{ .appended = {} };
248 },
249 .empty_array_sentinel => {
250 const elem_ty = typed_value.ty.childType();
251 const sentinel_val = typed_value.ty.sentinel().?;
252 switch (try generateSymbol(bin_file, parent_atom_index, src_loc, .{
253 .ty = elem_ty,
254 .val = sentinel_val,
255 }, code, debug_output)) {
256 .appended => {},
257 .externally_managed => |slice| {
258 code.appendSliceAssumeCapacity(slice);
259 },
260 .fail => |em| return Result{ .fail = em },
261 }
262 return Result{ .appended = {} };
263 },
215264 else => return Result{
216265 .fail = try ErrorMsg.create(
217266 bin_file.allocator,
......@@ -432,6 +481,75 @@ pub fn generateSymbol(
432481
433482 return Result{ .appended = {} };
434483 },
484 .ErrorUnion => {
485 const error_ty = typed_value.ty.errorUnionSet();
486 const payload_ty = typed_value.ty.errorUnionPayload();
487 const is_payload = typed_value.val.errorUnionIsPayload();
488
489 const target = bin_file.options.target;
490 const abi_align = typed_value.ty.abiAlignment(target);
491
492 {
493 const error_val = if (!is_payload) typed_value.val else Value.initTag(.zero);
494 const begin = code.items.len;
495 switch (try generateSymbol(bin_file, parent_atom_index, src_loc, .{
496 .ty = error_ty,
497 .val = error_val,
498 }, code, debug_output)) {
499 .appended => {},
500 .externally_managed => |external_slice| {
501 code.appendSliceAssumeCapacity(external_slice);
502 },
503 .fail => |em| return Result{ .fail = em },
504 }
505 const unpadded_end = code.items.len - begin;
506 const padded_end = mem.alignForwardGeneric(u64, unpadded_end, abi_align);
507 const padding = try math.cast(usize, padded_end - unpadded_end);
508
509 if (padding > 0) {
510 try code.writer().writeByteNTimes(0, padding);
511 }
512 }
513
514 if (payload_ty.hasRuntimeBits()) {
515 const payload_val = if (typed_value.val.castTag(.eu_payload)) |val| val.data else Value.initTag(.undef);
516 const begin = code.items.len;
517 switch (try generateSymbol(bin_file, parent_atom_index, src_loc, .{
518 .ty = payload_ty,
519 .val = payload_val,
520 }, code, debug_output)) {
521 .appended => {},
522 .externally_managed => |external_slice| {
523 code.appendSliceAssumeCapacity(external_slice);
524 },
525 .fail => |em| return Result{ .fail = em },
526 }
527 const unpadded_end = code.items.len - begin;
528 const padded_end = mem.alignForwardGeneric(u64, unpadded_end, abi_align);
529 const padding = try math.cast(usize, padded_end - unpadded_end);
530
531 if (padding > 0) {
532 try code.writer().writeByteNTimes(0, padding);
533 }
534 }
535
536 return Result{ .appended = {} };
537 },
538 .ErrorSet => {
539 const target = bin_file.options.target;
540 switch (typed_value.val.tag()) {
541 .@"error" => {
542 const name = typed_value.val.getError().?;
543 const kv = try bin_file.options.module.?.getErrorValue(name);
544 const endian = target.cpu.arch.endian();
545 try code.writer().writeInt(u32, kv.value, endian);
546 },
547 else => {
548 try code.writer().writeByteNTimes(0, @intCast(usize, typed_value.ty.abiSize(target)));
549 },
550 }
551 return Result{ .appended = {} };
552 },
435553 else => |t| {
436554 return Result{
437555 .fail = try ErrorMsg.create(
src/link/Elf.zig+1
......@@ -3127,6 +3127,7 @@ pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl: *Module.Decl
31273127 .fail => |em| {
31283128 decl.analysis = .codegen_failure;
31293129 try module.failed_decls.put(module.gpa, decl, em);
3130 log.err("{s}", .{em.msg});
31303131 return error.AnalysisFail;
31313132 },
31323133 };
test/behavior.zig+111-111
......@@ -6,14 +6,19 @@ test {
66 _ = @import("behavior/array.zig");
77 _ = @import("behavior/basic.zig");
88 _ = @import("behavior/bit_shifting.zig");
9 _ = @import("behavior/bitcast.zig");
910 _ = @import("behavior/bitreverse.zig");
1011 _ = @import("behavior/byteswap.zig");
12 _ = @import("behavior/byval_arg_var.zig");
1113 _ = @import("behavior/bool.zig");
1214 _ = @import("behavior/bugs/394.zig");
15 _ = @import("behavior/bugs/624.zig");
1316 _ = @import("behavior/bugs/655.zig");
1417 _ = @import("behavior/bugs/656.zig");
1518 _ = @import("behavior/bugs/679.zig");
19 _ = @import("behavior/bugs/704.zig");
1620 _ = @import("behavior/bugs/1025.zig");
21 _ = @import("behavior/bugs/1076.zig");
1722 _ = @import("behavior/bugs/1111.zig");
1823 _ = @import("behavior/bugs/1277.zig");
1924 _ = @import("behavior/bugs/1310.zig");
......@@ -26,150 +31,145 @@ test {
2631 _ = @import("behavior/bugs/2006.zig");
2732 _ = @import("behavior/bugs/2346.zig");
2833 _ = @import("behavior/bugs/2578.zig");
34 _ = @import("behavior/bugs/2692.zig");
35 _ = @import("behavior/bugs/2889.zig");
2936 _ = @import("behavior/bugs/3007.zig");
37 _ = @import("behavior/bugs/3046.zig");
3038 _ = @import("behavior/bugs/3112.zig");
3139 _ = @import("behavior/bugs/3367.zig");
40 _ = @import("behavior/bugs/3586.zig");
41 _ = @import("behavior/bugs/4560.zig");
42 _ = @import("behavior/bugs/4769_a.zig");
43 _ = @import("behavior/bugs/4769_b.zig");
44 _ = @import("behavior/bugs/4954.zig");
3245 _ = @import("behavior/bugs/6850.zig");
3346 _ = @import("behavior/bugs/7250.zig");
47 _ = @import("behavior/call.zig");
3448 _ = @import("behavior/cast.zig");
3549 _ = @import("behavior/comptime_memory.zig");
50 _ = @import("behavior/defer.zig");
51 _ = @import("behavior/enum.zig");
52 _ = @import("behavior/error.zig");
53 _ = @import("behavior/fn.zig");
3654 _ = @import("behavior/fn_delegation.zig");
3755 _ = @import("behavior/fn_in_struct_in_comptime.zig");
56 _ = @import("behavior/for.zig");
57 _ = @import("behavior/generics.zig");
3858 _ = @import("behavior/hasdecl.zig");
3959 _ = @import("behavior/hasfield.zig");
60 _ = @import("behavior/if.zig");
61 _ = @import("behavior/import.zig");
62 _ = @import("behavior/incomplete_struct_param_tld.zig");
63 _ = @import("behavior/int_div.zig");
64 _ = @import("behavior/inttoptr.zig");
4065 _ = @import("behavior/ir_block_deps.zig");
66 _ = @import("behavior/member_func.zig");
4167 _ = @import("behavior/namespace_depends_on_compile_var.zig");
68 _ = @import("behavior/null.zig");
4269 _ = @import("behavior/optional.zig");
4370 _ = @import("behavior/prefetch.zig");
71 _ = @import("behavior/pointers.zig");
4472 _ = @import("behavior/pub_enum.zig");
73 _ = @import("behavior/ptrcast.zig");
4574 _ = @import("behavior/reflection.zig");
75 _ = @import("behavior/ref_var_in_if_after_if_2nd_switch_prong.zig");
4676 _ = @import("behavior/slice.zig");
4777 _ = @import("behavior/slice_sentinel_comptime.zig");
4878 _ = @import("behavior/struct.zig");
79 _ = @import("behavior/src.zig");
80 _ = @import("behavior/this.zig");
4981 _ = @import("behavior/truncate.zig");
82 _ = @import("behavior/try.zig");
5083 _ = @import("behavior/tuple.zig");
5184 _ = @import("behavior/type.zig");
85 _ = @import("behavior/type_info.zig");
86 _ = @import("behavior/undefined.zig");
87 _ = @import("behavior/underscore.zig");
88 _ = @import("behavior/union.zig");
89 _ = @import("behavior/usingnamespace.zig");
5290 _ = @import("behavior/var_args.zig");
53 _ = @import("behavior/int_div.zig");
91 _ = @import("behavior/void.zig");
92 _ = @import("behavior/while.zig");
5493
5594 // tests that don't pass for stage1
5695 if (builtin.zig_backend != .stage1) {
5796 _ = @import("behavior/decltest.zig");
5897 }
5998
60 if (builtin.zig_backend != .stage2_arm and builtin.zig_backend != .stage2_x86_64 and builtin.zig_backend != .stage2_aarch64) {
61 // Tests that pass (partly) for stage1, llvm backend, C backend, wasm backend.
62 _ = @import("behavior/bitcast.zig");
63 _ = @import("behavior/bugs/624.zig");
64 _ = @import("behavior/bugs/704.zig");
65 _ = @import("behavior/bugs/1076.zig");
66 _ = @import("behavior/bugs/2692.zig");
67 _ = @import("behavior/bugs/2889.zig");
68 _ = @import("behavior/bugs/3046.zig");
69 _ = @import("behavior/bugs/3586.zig");
70 _ = @import("behavior/bugs/4560.zig");
71 _ = @import("behavior/bugs/4769_a.zig");
72 _ = @import("behavior/bugs/4769_b.zig");
73 _ = @import("behavior/bugs/4954.zig");
74 _ = @import("behavior/byval_arg_var.zig");
75 _ = @import("behavior/call.zig");
76 _ = @import("behavior/defer.zig");
77 _ = @import("behavior/enum.zig");
78 _ = @import("behavior/error.zig");
79 _ = @import("behavior/fn.zig");
80 _ = @import("behavior/for.zig");
81 _ = @import("behavior/generics.zig");
82 _ = @import("behavior/if.zig");
83 _ = @import("behavior/import.zig");
84 _ = @import("behavior/incomplete_struct_param_tld.zig");
85 _ = @import("behavior/inttoptr.zig");
86 _ = @import("behavior/member_func.zig");
87 _ = @import("behavior/null.zig");
88 _ = @import("behavior/pointers.zig");
89 _ = @import("behavior/ptrcast.zig");
90 _ = @import("behavior/ref_var_in_if_after_if_2nd_switch_prong.zig");
91 _ = @import("behavior/src.zig");
92 _ = @import("behavior/this.zig");
93 _ = @import("behavior/try.zig");
94 _ = @import("behavior/type_info.zig");
95 _ = @import("behavior/undefined.zig");
96 _ = @import("behavior/underscore.zig");
97 _ = @import("behavior/union.zig");
98 _ = @import("behavior/usingnamespace.zig");
99 _ = @import("behavior/void.zig");
100 _ = @import("behavior/while.zig");
99 if (builtin.zig_backend != .stage2_arm and
100 builtin.zig_backend != .stage2_x86_64 and
101 builtin.zig_backend != .stage2_aarch64 and
102 builtin.zig_backend != .stage2_wasm)
103 {
104 // Tests that pass for stage1, llvm backend, C backend
105 _ = @import("behavior/bugs/9584.zig");
106 _ = @import("behavior/cast_int.zig");
107 _ = @import("behavior/eval.zig");
108 _ = @import("behavior/int128.zig");
109 _ = @import("behavior/merge_error_sets.zig");
110 _ = @import("behavior/translate_c_macros.zig");
101111
102 if (builtin.zig_backend != .stage2_wasm) {
103 // Tests that pass for stage1, llvm backend, C backend
104 _ = @import("behavior/bugs/9584.zig");
105 _ = @import("behavior/cast_int.zig");
106 _ = @import("behavior/eval.zig");
107 _ = @import("behavior/int128.zig");
108 _ = @import("behavior/merge_error_sets.zig");
109 _ = @import("behavior/translate_c_macros.zig");
112 if (builtin.zig_backend != .stage2_c) {
113 // Tests that pass for stage1 and the llvm backend.
114 _ = @import("behavior/atomics.zig");
115 _ = @import("behavior/floatop.zig");
116 _ = @import("behavior/math.zig");
117 _ = @import("behavior/maximum_minimum.zig");
118 _ = @import("behavior/popcount.zig");
119 _ = @import("behavior/saturating_arithmetic.zig");
120 _ = @import("behavior/sizeof_and_typeof.zig");
121 _ = @import("behavior/switch.zig");
122 _ = @import("behavior/widening.zig");
110123
111 if (builtin.zig_backend != .stage2_c) {
112 // Tests that pass for stage1 and the llvm backend.
113 _ = @import("behavior/atomics.zig");
114 _ = @import("behavior/floatop.zig");
115 _ = @import("behavior/math.zig");
116 _ = @import("behavior/maximum_minimum.zig");
117 _ = @import("behavior/popcount.zig");
118 _ = @import("behavior/saturating_arithmetic.zig");
119 _ = @import("behavior/sizeof_and_typeof.zig");
120 _ = @import("behavior/switch.zig");
121 _ = @import("behavior/widening.zig");
124 if (builtin.zig_backend == .stage1) {
125 // Tests that only pass for the stage1 backend.
126 if (builtin.os.tag != .wasi) {
127 _ = @import("behavior/asm.zig");
128 _ = @import("behavior/async_fn.zig");
129 }
130 _ = @import("behavior/await_struct.zig");
131 _ = @import("behavior/bugs/421.zig");
132 _ = @import("behavior/bugs/529.zig");
133 _ = @import("behavior/bugs/718.zig");
134 _ = @import("behavior/bugs/726.zig");
135 _ = @import("behavior/bugs/828.zig");
136 _ = @import("behavior/bugs/920.zig");
137 _ = @import("behavior/bugs/1120.zig");
138 _ = @import("behavior/bugs/1421.zig");
122139 _ = @import("behavior/bugs/1442.zig");
123
124 if (builtin.zig_backend == .stage1) {
125 // Tests that only pass for the stage1 backend.
126 if (builtin.os.tag != .wasi) {
127 _ = @import("behavior/asm.zig");
128 _ = @import("behavior/async_fn.zig");
129 }
130 _ = @import("behavior/await_struct.zig");
131 _ = @import("behavior/bugs/421.zig");
132 _ = @import("behavior/bugs/529.zig");
133 _ = @import("behavior/bugs/718.zig");
134 _ = @import("behavior/bugs/726.zig");
135 _ = @import("behavior/bugs/828.zig");
136 _ = @import("behavior/bugs/920.zig");
137 _ = @import("behavior/bugs/1120.zig");
138 _ = @import("behavior/bugs/1421.zig");
139 _ = @import("behavior/bugs/1607.zig");
140 _ = @import("behavior/bugs/1851.zig");
141 _ = @import("behavior/bugs/2114.zig");
142 _ = @import("behavior/bugs/3384.zig");
143 _ = @import("behavior/bugs/3742.zig");
144 _ = @import("behavior/bugs/3779.zig");
145 _ = @import("behavior/bugs/4328.zig");
146 _ = @import("behavior/bugs/5398.zig");
147 _ = @import("behavior/bugs/5413.zig");
148 _ = @import("behavior/bugs/5474.zig");
149 _ = @import("behavior/bugs/5487.zig");
150 _ = @import("behavior/bugs/6456.zig");
151 _ = @import("behavior/bugs/6781.zig");
152 _ = @import("behavior/bugs/7003.zig");
153 _ = @import("behavior/bugs/7027.zig");
154 _ = @import("behavior/bugs/7047.zig");
155 _ = @import("behavior/bugs/10147.zig");
156 _ = @import("behavior/const_slice_child.zig");
157 _ = @import("behavior/export_self_referential_type_info.zig");
158 _ = @import("behavior/field_parent_ptr.zig");
159 _ = @import("behavior/misc.zig");
160 _ = @import("behavior/muladd.zig");
161 _ = @import("behavior/select.zig");
162 _ = @import("behavior/shuffle.zig");
163 _ = @import("behavior/struct_contains_null_ptr_itself.zig");
164 _ = @import("behavior/struct_contains_slice_of_itself.zig");
165 _ = @import("behavior/switch_prong_err_enum.zig");
166 _ = @import("behavior/switch_prong_implicit_cast.zig");
167 _ = @import("behavior/typename.zig");
168 _ = @import("behavior/union_with_members.zig");
169 _ = @import("behavior/vector.zig");
170 if (builtin.target.cpu.arch == .wasm32) {
171 _ = @import("behavior/wasm.zig");
172 }
140 _ = @import("behavior/bugs/1607.zig");
141 _ = @import("behavior/bugs/1851.zig");
142 _ = @import("behavior/bugs/2114.zig");
143 _ = @import("behavior/bugs/3384.zig");
144 _ = @import("behavior/bugs/3742.zig");
145 _ = @import("behavior/bugs/3779.zig");
146 _ = @import("behavior/bugs/4328.zig");
147 _ = @import("behavior/bugs/5398.zig");
148 _ = @import("behavior/bugs/5413.zig");
149 _ = @import("behavior/bugs/5474.zig");
150 _ = @import("behavior/bugs/5487.zig");
151 _ = @import("behavior/bugs/6456.zig");
152 _ = @import("behavior/bugs/6781.zig");
153 _ = @import("behavior/bugs/7003.zig");
154 _ = @import("behavior/bugs/7027.zig");
155 _ = @import("behavior/bugs/7047.zig");
156 _ = @import("behavior/bugs/10147.zig");
157 _ = @import("behavior/const_slice_child.zig");
158 _ = @import("behavior/export_self_referential_type_info.zig");
159 _ = @import("behavior/field_parent_ptr.zig");
160 _ = @import("behavior/misc.zig");
161 _ = @import("behavior/muladd.zig");
162 _ = @import("behavior/select.zig");
163 _ = @import("behavior/shuffle.zig");
164 _ = @import("behavior/struct_contains_null_ptr_itself.zig");
165 _ = @import("behavior/struct_contains_slice_of_itself.zig");
166 _ = @import("behavior/switch_prong_err_enum.zig");
167 _ = @import("behavior/switch_prong_implicit_cast.zig");
168 _ = @import("behavior/typename.zig");
169 _ = @import("behavior/union_with_members.zig");
170 _ = @import("behavior/vector.zig");
171 if (builtin.target.cpu.arch == .wasm32) {
172 _ = @import("behavior/wasm.zig");
173173 }
174174 }
175175 }
test/behavior/align.zig-6
......@@ -180,8 +180,6 @@ fn noop4() align(4) void {}
180180test "function alignment" {
181181 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
182182 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
183 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
184 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
185183 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
186184
187185 // function alignment is a compile error on wasm32/wasm64
......@@ -199,7 +197,6 @@ test "implicitly decreasing fn alignment" {
199197 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
200198 if (builtin.zig_backend == .stage2_llvm) return error.SkipZigTest;
201199 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
202 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
203200 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
204201 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
205202
......@@ -226,8 +223,6 @@ test "@alignCast functions" {
226223 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
227224 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
228225 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
229 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
230 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
231226 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
232227
233228 // function alignment is a compile error on wasm32/wasm64
......@@ -250,7 +245,6 @@ test "generic function with align param" {
250245 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
251246 if (builtin.zig_backend == .stage2_llvm) return error.SkipZigTest;
252247 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
253 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
254248 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
255249 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
256250
test/behavior/array.zig+6-4
......@@ -49,7 +49,7 @@ fn getArrayLen(a: []const u32) usize {
4949
5050test "array init with mult" {
5151 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
52 if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
52 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
5353
5454 const a = 'a';
5555 var i: [8]u8 = [2]u8{ a, 'b' } ** 4;
......@@ -112,7 +112,7 @@ test "array len field" {
112112
113113test "array with sentinels" {
114114 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
115 if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
115 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
116116
117117 const S = struct {
118118 fn doTheTest(is_ct: bool) !void {
......@@ -179,7 +179,8 @@ fn plusOne(x: u32) u32 {
179179
180180test "single-item pointer to array indexing and slicing" {
181181 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
182 if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
182 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
183 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
183184
184185 try testSingleItemPtrArrayIndexSlice();
185186 comptime try testSingleItemPtrArrayIndexSlice();
......@@ -205,7 +206,8 @@ fn doSomeMangling(array: *[4]u8) void {
205206
206207test "implicit cast zero sized array ptr to slice" {
207208 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
208 if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
209 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
210 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
209211
210212 {
211213 var b = "".*;
test/behavior/basic.zig-6
......@@ -117,7 +117,6 @@ fn first4KeysOfHomeRow() []const u8 {
117117test "return string from function" {
118118 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
119119 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
120 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
121120
122121 try expect(mem.eql(u8, first4KeysOfHomeRow(), "aoeu"));
123122}
......@@ -231,7 +230,6 @@ test "compile time global reinterpret" {
231230
232231test "cast undefined" {
233232 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
234 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
235233
236234 const array: [100]u8 = undefined;
237235 const slice = @as([]const u8, &array);
......@@ -303,7 +301,6 @@ test "call function pointer in struct" {
303301 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
304302 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
305303 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
306
307304 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
308305
309306 try expect(mem.eql(u8, f3(true), "a"));
......@@ -382,7 +379,6 @@ fn testMemcpyMemset() !void {
382379test "variable is allowed to be a pointer to an opaque type" {
383380 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
384381 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
385 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
386382 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
387383
388384 var x: i32 = 1234;
......@@ -425,7 +421,6 @@ test "array 2D const double ptr" {
425421 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
426422 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
427423 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
428
429424 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
430425
431426 const rect_2d_vertexes = [_][1]f32{
......@@ -476,7 +471,6 @@ fn testArray2DConstDoublePtr(ptr: *const f32) !void {
476471test "double implicit cast in same expression" {
477472 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
478473 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
479 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
480474
481475 var x = @as(i32, @as(u16, nine()));
482476 try expect(x == 9);
test/behavior/bitcast.zig+38
......@@ -7,6 +7,9 @@ const minInt = std.math.minInt;
77const native_endian = builtin.target.cpu.arch.endian();
88
99test "@bitCast iX -> uX (32, 64)" {
10 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
11 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
12
1013 const bit_values = [_]usize{ 32, 64 };
1114
1215 inline for (bit_values) |bits| {
......@@ -17,6 +20,10 @@ test "@bitCast iX -> uX (32, 64)" {
1720
1821test "@bitCast iX -> uX (8, 16, 128)" {
1922 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
23 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
24 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
25 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
26
2027 const bit_values = [_]usize{ 8, 16, 128 };
2128
2229 inline for (bit_values) |bits| {
......@@ -29,6 +36,8 @@ test "@bitCast iX -> uX exotic integers" {
2936 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
3037 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
3138 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
39 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
40 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
3241
3342 const bit_values = [_]usize{ 1, 48, 27, 512, 493, 293, 125, 204, 112 };
3443
......@@ -66,6 +75,9 @@ fn conv_uN(comptime N: usize, x: std.meta.Int(.unsigned, N)) std.meta.Int(.signe
6675}
6776
6877test "nested bitcast" {
78 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
79 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
80
6981 const S = struct {
7082 fn moo(x: isize) !void {
7183 try expect(@intCast(isize, 42) == x);
......@@ -83,6 +95,9 @@ test "nested bitcast" {
8395}
8496
8597test "@bitCast enum to its integer type" {
98 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
99 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
100
86101 const SOCK = enum(c_int) {
87102 A,
88103 B,
......@@ -100,11 +115,17 @@ test "@bitCast enum to its integer type" {
100115
101116// issue #3010: compiler segfault
102117test "bitcast literal [4]u8 param to u32" {
118 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
119 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
120
103121 const ip = @bitCast(u32, [_]u8{ 255, 255, 255, 255 });
104122 try expect(ip == maxInt(u32));
105123}
106124
107125test "bitcast generates a temporary value" {
126 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
127 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
128
108129 var y = @as(u16, 0x55AA);
109130 const x = @bitCast(u16, @bitCast([2]u8, y));
110131 try expect(y == x);
......@@ -115,6 +136,8 @@ test "@bitCast packed structs at runtime and comptime" {
115136 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
116137 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
117138 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
139 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
140 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
118141
119142 const Full = packed struct {
120143 number: u16,
......@@ -151,6 +174,8 @@ test "@bitCast extern structs at runtime and comptime" {
151174 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
152175 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
153176 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
177 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
178 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
154179
155180 const Full = extern struct {
156181 number: u16,
......@@ -184,6 +209,8 @@ test "bitcast packed struct to integer and back" {
184209 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
185210 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
186211 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
212 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
213 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
187214
188215 const LevelUpMove = packed struct {
189216 move_id: u9,
......@@ -203,6 +230,9 @@ test "bitcast packed struct to integer and back" {
203230}
204231
205232test "implicit cast to error union by returning" {
233 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
234 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
235
206236 const S = struct {
207237 fn entry() !void {
208238 try expect((func(-1) catch unreachable) == maxInt(u64));
......@@ -220,6 +250,8 @@ test "bitcast packed struct literal to byte" {
220250 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
221251 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
222252 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
253 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
254 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
223255
224256 const Foo = packed struct {
225257 value: u8,
......@@ -233,6 +265,8 @@ test "comptime bitcast used in expression has the correct type" {
233265 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
234266 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
235267 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
268 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
269 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
236270
237271 const Foo = packed struct {
238272 value: u8,
......@@ -245,6 +279,8 @@ test "bitcast passed as tuple element" {
245279 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
246280 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
247281 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
282 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
283 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
248284
249285 const S = struct {
250286 fn foo(args: anytype) !void {
......@@ -257,6 +293,8 @@ test "bitcast passed as tuple element" {
257293
258294test "triple level result location with bitcast sandwich passed as tuple element" {
259295 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
296 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
297 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
260298
261299 const S = struct {
262300 fn foo(args: anytype) !void {
test/behavior/bugs/1076.zig+5
......@@ -1,8 +1,13 @@
11const std = @import("std");
2const builtin = @import("builtin");
23const mem = std.mem;
34const expect = std.testing.expect;
45
56test "comptime code should not modify constant data" {
7 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
8 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
9 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
10
611 try testCastPtrOfArrayToSliceAndPtr();
712 comptime try testCastPtrOfArrayToSliceAndPtr();
813}
test/behavior/bugs/1442.zig+3
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const builtin = @import("builtin");
23
34const Union = union(enum) {
45 Text: []const u8,
......@@ -6,6 +7,8 @@ const Union = union(enum) {
67};
78
89test "const error union field alignment" {
10 if (builtin.zig_backend != .stage1) return error.SkipZigTest;
11
912 var union_or_err: anyerror!Union = Union{ .Color = 1234 };
1013 try std.testing.expect((union_or_err catch unreachable).Color == 1234);
1114}
test/behavior/bugs/2692.zig+5
......@@ -1,8 +1,13 @@
1const builtin = @import("builtin");
2
13fn foo(a: []u8) void {
24 _ = a;
35}
46
57test "address of 0 length array" {
8 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
9 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
10
611 var pt: [0]u8 = undefined;
712 foo(&pt);
813}
test/behavior/bugs/2889.zig+5
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const builtin = @import("builtin");
23
34const source = "A-";
45
......@@ -26,6 +27,10 @@ fn parseNote() ?i32 {
2627}
2728
2829test "fixed" {
30 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
31 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
32 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
33
2934 const result = parseNote();
3035 try std.testing.expect(result.? == 9);
3136}
test/behavior/bugs/3046.zig+5-1
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const builtin = @import("builtin");
23const expect = std.testing.expect;
34
45const SomeStruct = struct {
......@@ -12,7 +13,10 @@ fn couldFail() anyerror!i32 {
1213var some_struct: SomeStruct = undefined;
1314
1415test "fixed" {
15 if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
16 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
17 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
18 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
19 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
1620
1721 some_struct = SomeStruct{
1822 .field = couldFail() catch @as(i32, 0),
test/behavior/bugs/3586.zig+5
......@@ -1,3 +1,5 @@
1const builtin = @import("builtin");
2
13const NoteParams = struct {};
24
35const Container = struct {
......@@ -5,6 +7,9 @@ const Container = struct {
57};
68
79test "fixed" {
10 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
11 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
12
813 var ctr = Container{
914 .params = NoteParams{},
1015 };
test/behavior/bugs/4560.zig+4
......@@ -1,6 +1,10 @@
11const std = @import("std");
2const builtin = @import("builtin");
23
34test "fixed" {
5 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
6 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
7
48 var s: S = .{
59 .a = 1,
610 .b = .{
test/behavior/bugs/4954.zig+6
......@@ -1,8 +1,14 @@
1const builtin = @import("builtin");
2
13fn f(buf: []u8) void {
24 _ = &buf[@sizeOf(u32)];
35}
46
57test "crash" {
8 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
9 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
10 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
11
612 var buf: [4096]u8 = undefined;
713 f(&buf);
814}
test/behavior/bugs/624.zig+4
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const builtin = @import("builtin");
23const expect = std.testing.expect;
34
45const TestContext = struct {
......@@ -19,6 +20,9 @@ fn MemoryPool(comptime T: type) type {
1920}
2021
2122test "foo" {
23 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
24 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
25
2226 var allocator = ContextAllocator{ .n = 10 };
2327 try expect(allocator.n == 10);
2428}
test/behavior/bugs/704.zig+5
......@@ -1,9 +1,14 @@
1const builtin = @import("builtin");
2
13const xxx = struct {
24 pub fn bar(self: *xxx) void {
35 _ = self;
46 }
57};
68test "bug 704" {
9 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
10 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
11
712 var x: xxx = undefined;
813 x.bar();
914}
test/behavior/byval_arg_var.zig+5
......@@ -1,8 +1,13 @@
11const std = @import("std");
2const builtin = @import("builtin");
23
34var result: []const u8 = "wrong";
45
56test "pass string literal byvalue to a generic var param" {
7 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
8 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
9 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
10
611 start();
712 blowUpStack(10);
813
test/behavior/defer.zig+13
......@@ -5,6 +5,9 @@ const expectEqual = std.testing.expectEqual;
55const expectError = std.testing.expectError;
66
77test "break and continue inside loop inside defer expression" {
8 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
9 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
10
811 testBreakContInDefer(10);
912 comptime testBreakContInDefer(10);
1013}
......@@ -21,6 +24,9 @@ fn testBreakContInDefer(x: usize) void {
2124}
2225
2326test "defer and labeled break" {
27 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
28 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
29
2430 var i = @as(usize, 0);
2531
2632 blk: {
......@@ -32,6 +38,9 @@ test "defer and labeled break" {
3238}
3339
3440test "errdefer does not apply to fn inside fn" {
41 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
42 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
43
3544 if (testNestedFnErrDefer()) |_| @panic("expected error") else |e| try expect(e == error.Bad);
3645}
3746
......@@ -47,6 +56,10 @@ fn testNestedFnErrDefer() anyerror!void {
4756}
4857
4958test "return variable while defer expression in scope to modify it" {
59 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
60 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
61 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
62
5063 const S = struct {
5164 fn doTheTest() !void {
5265 try expect(notNull().? == 1);
test/behavior/enum.zig+114
......@@ -11,6 +11,9 @@ fn shouldEqual(n: Number, expected: u3) !void {
1111}
1212
1313test "enum to int" {
14 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
15 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
16
1417 try shouldEqual(Number.Zero, 0);
1518 try shouldEqual(Number.One, 1);
1619 try shouldEqual(Number.Two, 2);
......@@ -24,6 +27,9 @@ fn testIntToEnumEval(x: i32) !void {
2427const IntToEnumNumber = enum { Zero, One, Two, Three, Four };
2528
2629test "int to enum" {
30 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
31 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
32
2733 try testIntToEnumEval(3);
2834}
2935
......@@ -553,6 +559,9 @@ const ValueCount257 = enum {
553559};
554560
555561test "enum sizes" {
562 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
563 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
564
556565 comptime {
557566 try expect(@sizeOf(ValueCount1) == 0);
558567 try expect(@sizeOf(ValueCount2) == 1);
......@@ -562,6 +571,9 @@ test "enum sizes" {
562571}
563572
564573test "enum literal equality" {
574 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
575 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
576
565577 const x = .hi;
566578 const y = .ok;
567579 const z = .hi;
......@@ -571,6 +583,9 @@ test "enum literal equality" {
571583}
572584
573585test "enum literal cast to enum" {
586 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
587 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
588
574589 const Color = enum { Auto, Off, On };
575590
576591 var color1: Color = .Auto;
......@@ -579,6 +594,9 @@ test "enum literal cast to enum" {
579594}
580595
581596test "peer type resolution with enum literal" {
597 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
598 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
599
582600 const Items = enum { one, two };
583601
584602 try expect(Items.two == .two);
......@@ -603,11 +621,19 @@ fn testEnumWithSpecifiedTagValues(x: MultipleChoice) !void {
603621}
604622
605623test "enum with specified tag values" {
624 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
625 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
626 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
627
606628 try testEnumWithSpecifiedTagValues(MultipleChoice.C);
607629 comptime try testEnumWithSpecifiedTagValues(MultipleChoice.C);
608630}
609631
610632test "non-exhaustive enum" {
633 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
634 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
635 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
636
611637 const S = struct {
612638 const E = enum(u8) { a, b, _ };
613639
......@@ -649,6 +675,9 @@ test "non-exhaustive enum" {
649675}
650676
651677test "empty non-exhaustive enum" {
678 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
679 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
680
652681 const S = struct {
653682 const E = enum(u8) { _ };
654683
......@@ -668,6 +697,10 @@ test "empty non-exhaustive enum" {
668697}
669698
670699test "single field non-exhaustive enum" {
700 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
701 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
702 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
703
671704 const S = struct {
672705 const E = enum(u8) { a, _ };
673706 fn doTheTest(y: u8) !void {
......@@ -708,6 +741,9 @@ const EnumWithTagValues = enum(u4) {
708741 D = 1 << 3,
709742};
710743test "enum with tag values don't require parens" {
744 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
745 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
746
711747 try expect(@enumToInt(EnumWithTagValues.C) == 0b0100);
712748}
713749
......@@ -724,11 +760,18 @@ const MultipleChoice2 = enum(u32) {
724760};
725761
726762test "cast integer literal to enum" {
763 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
764 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
765
727766 try expect(@intToEnum(MultipleChoice2, 0) == MultipleChoice2.Unspecified1);
728767 try expect(@intToEnum(MultipleChoice2, 40) == MultipleChoice2.B);
729768}
730769
731770test "enum with specified and unspecified tag values" {
771 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
772 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
773 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
774
732775 try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D);
733776 comptime try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D);
734777}
......@@ -752,6 +795,9 @@ const Small2 = enum(u2) { One, Two };
752795const Small = enum(u2) { One, Two, Three, Four };
753796
754797test "set enum tag type" {
798 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
799 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
800
755801 {
756802 var x = Small.One;
757803 x = Small.Two;
......@@ -765,6 +811,9 @@ test "set enum tag type" {
765811}
766812
767813test "casting enum to its tag type" {
814 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
815 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
816
768817 try testCastEnumTag(Small2.Two);
769818 comptime try testCastEnumTag(Small2.Two);
770819}
......@@ -774,6 +823,9 @@ fn testCastEnumTag(value: Small2) !void {
774823}
775824
776825test "enum with 1 field but explicit tag type should still have the tag type" {
826 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
827 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
828
777829 const Enum = enum(u8) {
778830 B = 2,
779831 };
......@@ -781,6 +833,9 @@ test "enum with 1 field but explicit tag type should still have the tag type" {
781833}
782834
783835test "signed integer as enum tag" {
836 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
837 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
838
784839 const SignedEnum = enum(i2) {
785840 A0 = -1,
786841 A1 = 0,
......@@ -793,6 +848,9 @@ test "signed integer as enum tag" {
793848}
794849
795850test "enum with one member and custom tag type" {
851 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
852 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
853
796854 const E = enum(u2) {
797855 One,
798856 };
......@@ -804,6 +862,9 @@ test "enum with one member and custom tag type" {
804862}
805863
806864test "enum with one member and u1 tag type @enumToInt" {
865 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
866 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
867
807868 const Enum = enum(u1) {
808869 Test,
809870 };
......@@ -811,6 +872,9 @@ test "enum with one member and u1 tag type @enumToInt" {
811872}
812873
813874test "enum with comptime_int tag type" {
875 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
876 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
877
814878 const Enum = enum(comptime_int) {
815879 One = 3,
816880 Two = 2,
......@@ -820,6 +884,9 @@ test "enum with comptime_int tag type" {
820884}
821885
822886test "enum with one member default to u0 tag type" {
887 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
888 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
889
823890 const E0 = enum { X };
824891 comptime try expect(Tag(E0) == u0);
825892}
......@@ -836,11 +903,17 @@ fn doALoopThing(id: EnumWithOneMember) void {
836903}
837904
838905test "comparison operator on enum with one member is comptime known" {
906 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
907 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
908
839909 doALoopThing(EnumWithOneMember.Eof);
840910}
841911
842912const State = enum { Start };
843913test "switch on enum with one member is comptime known" {
914 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
915 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
916
844917 var state = State.Start;
845918 switch (state) {
846919 State.Start => return,
......@@ -849,6 +922,9 @@ test "switch on enum with one member is comptime known" {
849922}
850923
851924test "method call on an enum" {
925 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
926 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
927
852928 const S = struct {
853929 const E = enum {
854930 one,
......@@ -885,6 +961,10 @@ test "enum value allocation" {
885961}
886962
887963test "enum literal casting to tagged union" {
964 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
965 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
966 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
967
888968 const Arch = union(enum) {
889969 x86_64,
890970 arm: Arm32,
......@@ -907,6 +987,10 @@ test "enum literal casting to tagged union" {
907987const Bar = enum { A, B, C, D };
908988
909989test "enum literal casting to error union with payload enum" {
990 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
991 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
992 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
993
910994 var bar: error{B}!Bar = undefined;
911995 bar = .B; // should never cast to the error set
912996
......@@ -930,6 +1014,11 @@ test "exporting enum type and value" {
9301014}
9311015
9321016test "constant enum initialization with differing sizes" {
1017 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1018 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
1019 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
1020 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
1021
9331022 try test3_1(test3_foo);
9341023 try test3_2(test3_bar);
9351024}
......@@ -970,6 +1059,9 @@ fn test3_2(f: Test3Foo) !void {
9701059test "@tagName" {
9711060 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
9721061 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
1062 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1063 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
1064 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
9731065
9741066 try expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
9751067 comptime try expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
......@@ -984,6 +1076,9 @@ const BareNumber = enum { One, Two, Three };
9841076test "@tagName non-exhaustive enum" {
9851077 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
9861078 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
1079 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1080 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
1081 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
9871082
9881083 try expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));
9891084 comptime try expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));
......@@ -993,6 +1088,9 @@ const NonExhaustive = enum(u8) { A, B, _ };
9931088test "@tagName is null-terminated" {
9941089 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
9951090 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
1091 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1092 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
1093 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
9961094
9971095 const S = struct {
9981096 fn doTheTest(n: BareNumber) !void {
......@@ -1006,6 +1104,9 @@ test "@tagName is null-terminated" {
10061104test "tag name with assigned enum values" {
10071105 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
10081106 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
1107 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1108 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
1109 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
10091110
10101111 const LocalFoo = enum(u8) {
10111112 A = 1,
......@@ -1016,11 +1117,18 @@ test "tag name with assigned enum values" {
10161117}
10171118
10181119test "@tagName on enum literals" {
1120 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
1121 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
1122
10191123 try expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
10201124 comptime try expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
10211125}
10221126
10231127test "enum literal casting to optional" {
1128 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1129 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
1130 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
1131
10241132 var bar: ?Bar = undefined;
10251133 bar = .B;
10261134
......@@ -1045,6 +1153,9 @@ const bit_field_1 = BitFieldOfEnums{
10451153
10461154test "bit field access with enum fields" {
10471155 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
1156 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1157 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
1158 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
10481159
10491160 var data = bit_field_1;
10501161 try expect(getA(&data) == A.Two);
......@@ -1073,6 +1184,9 @@ fn getC(data: *const BitFieldOfEnums) C {
10731184}
10741185
10751186test "enum literal in array literal" {
1187 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
1188 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
1189
10761190 const Items = enum { one, two };
10771191 const array = [_]Items{ .one, .two };
10781192
test/behavior/error.zig+48
......@@ -6,12 +6,18 @@ const expectEqual = std.testing.expectEqual;
66const mem = std.mem;
77
88test "error values" {
9 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
10 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
11
912 const a = @errorToInt(error.err1);
1013 const b = @errorToInt(error.err2);
1114 try expect(a != b);
1215}
1316
1417test "redefinition of error values allowed" {
18 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
19 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
20
1521 shouldBeNotEqual(error.AnError, error.SecondError);
1622}
1723fn shouldBeNotEqual(a: anyerror, b: anyerror) void {
......@@ -19,6 +25,10 @@ fn shouldBeNotEqual(a: anyerror, b: anyerror) void {
1925}
2026
2127test "error binary operator" {
28 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
29 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
30 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
31
2232 const a = errBinaryOperatorG(true) catch 3;
2333 const b = errBinaryOperatorG(false) catch 3;
2434 try expect(a == 3);
......@@ -29,6 +39,9 @@ fn errBinaryOperatorG(x: bool) anyerror!isize {
2939}
3040
3141test "empty error union" {
42 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
43 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
44
3245 const x = error{} || error{};
3346 _ = x;
3447}
......@@ -48,10 +61,18 @@ pub fn baz() anyerror!i32 {
4861}
4962
5063test "error wrapping" {
64 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
65 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
66 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
67
5168 try expect((baz() catch unreachable) == 15);
5269}
5370
5471test "unwrap simple value from error" {
72 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
73 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
74 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
75
5576 const i = unwrapSimpleValueFromErrorDo() catch unreachable;
5677 try expect(i == 13);
5778}
......@@ -60,6 +81,10 @@ fn unwrapSimpleValueFromErrorDo() anyerror!isize {
6081}
6182
6283test "error return in assignment" {
84 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
85 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
86 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
87
6388 doErrReturnInAssignment() catch unreachable;
6489}
6590
......@@ -73,12 +98,19 @@ fn makeANonErr() anyerror!i32 {
7398}
7499
75100test "syntax: optional operator in front of error union operator" {
101 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
102 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
103
76104 comptime {
77105 try expect(?(anyerror!i32) == ?(anyerror!i32));
78106 }
79107}
80108
81109test "widen cast integer payload of error union function call" {
110 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
111 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
112 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
113
82114 const S = struct {
83115 fn errorable() !u64 {
84116 var x = @as(u64, try number());
......@@ -93,12 +125,19 @@ test "widen cast integer payload of error union function call" {
93125}
94126
95127test "debug info for optional error set" {
128 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
129 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
130 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
131
96132 const SomeError = error{Hello};
97133 var a_local_variable: ?SomeError = null;
98134 _ = a_local_variable;
99135}
100136
101137test "implicit cast to optional to error union to return result loc" {
138 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
139 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
140
102141 const S = struct {
103142 fn entry() !void {
104143 var x: Foo = undefined;
......@@ -118,6 +157,9 @@ test "implicit cast to optional to error union to return result loc" {
118157}
119158
120159test "error: fn returning empty error set can be passed as fn returning any error" {
160 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
161 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
162
121163 entry();
122164 comptime entry();
123165}
......@@ -482,6 +524,9 @@ test "error union comptime caching" {
482524test "@errorName" {
483525 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
484526 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
527 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
528 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
529 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
485530
486531 try expect(mem.eql(u8, @errorName(error.AnError), "AnError"));
487532 try expect(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName"));
......@@ -494,6 +539,9 @@ fn gimmeItBroke() anyerror {
494539test "@errorName sentinel length matches slice length" {
495540 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
496541 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
542 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
543 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
544 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
497545
498546 const name = testBuiltinErrorName(error.FooBar);
499547 const length: usize = 6;
test/behavior/fn.zig+71
......@@ -5,6 +5,9 @@ const expect = testing.expect;
55const expectEqual = testing.expectEqual;
66
77test "params" {
8 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
9 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
10
811 try expect(testParamsAdd(22, 11) == 33);
912}
1013fn testParamsAdd(a: i32, b: i32) i32 {
......@@ -12,6 +15,9 @@ fn testParamsAdd(a: i32, b: i32) i32 {
1215}
1316
1417test "local variables" {
18 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
19 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
20
1521 testLocVars(2);
1622}
1723fn testLocVars(b: i32) void {
......@@ -20,6 +26,9 @@ fn testLocVars(b: i32) void {
2026}
2127
2228test "mutable local variables" {
29 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
30 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
31
2332 var zero: i32 = 0;
2433 try expect(zero == 0);
2534
......@@ -31,6 +40,9 @@ test "mutable local variables" {
3140}
3241
3342test "separate block scopes" {
43 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
44 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
45
3446 {
3547 const no_conflict: i32 = 5;
3648 try expect(no_conflict == 5);
......@@ -47,10 +59,16 @@ fn @"weird function name"() i32 {
4759 return 1234;
4860}
4961test "weird function name" {
62 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
63 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
64
5065 try expect(@"weird function name"() == 1234);
5166}
5267
5368test "assign inline fn to const variable" {
69 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
70 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
71
5472 const a = inlineFn;
5573 a();
5674}
......@@ -68,6 +86,9 @@ fn outer(y: u32) *const fn (u32) u32 {
6886}
6987
7088test "return inner function which references comptime variable of outer function" {
89 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
90 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
91
7192 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
7293
7394 var func = outer(10);
......@@ -76,6 +97,9 @@ test "return inner function which references comptime variable of outer function
7697
7798test "discard the result of a function that returns a struct" {
7899 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
100 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
101 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
102
79103 const S = struct {
80104 fn entry() void {
81105 _ = func();
......@@ -97,6 +121,9 @@ test "discard the result of a function that returns a struct" {
97121test "inline function call that calls optional function pointer, return pointer at callsite interacts correctly with callsite return type" {
98122 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
99123 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
124 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
125 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
126 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
100127
101128 const S = struct {
102129 field: u32,
......@@ -129,6 +156,9 @@ test "inline function call that calls optional function pointer, return pointer
129156}
130157
131158test "implicit cast function unreachable return" {
159 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
160 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
161
132162 wantsFnWithVoid(fnWithUnreachable);
133163}
134164
......@@ -143,6 +173,8 @@ fn fnWithUnreachable() noreturn {
143173test "extern struct with stdcallcc fn pointer" {
144174 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
145175 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
176 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
177 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
146178
147179 const S = extern struct {
148180 ptr: *const fn () callconv(if (builtin.target.cpu.arch == .i386) .Stdcall else .C) i32,
......@@ -170,10 +202,16 @@ fn fComplexCallconvRet(x: u32) callconv(blk: {
170202}
171203
172204test "function with complex callconv and return type expressions" {
205 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
206 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
207
173208 try expect(fComplexCallconvRet(3).x == 9);
174209}
175210
176211test "pass by non-copying value" {
212 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
213 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
214
177215 try expect(addPointCoords(Point{ .x = 1, .y = 2 }) == 3);
178216}
179217
......@@ -187,6 +225,10 @@ fn addPointCoords(pt: Point) i32 {
187225}
188226
189227test "pass by non-copying value through var arg" {
228 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
229 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
230 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
231
190232 try expect((try addPointCoordsVar(Point{ .x = 1, .y = 2 })) == 3);
191233}
192234
......@@ -196,6 +238,9 @@ fn addPointCoordsVar(pt: anytype) !i32 {
196238}
197239
198240test "pass by non-copying value as method" {
241 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
242 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
243
199244 var pt = Point2{ .x = 1, .y = 2 };
200245 try expect(pt.addPointCoords() == 3);
201246}
......@@ -210,6 +255,9 @@ const Point2 = struct {
210255};
211256
212257test "pass by non-copying value as method, which is generic" {
258 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
259 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
260
213261 var pt = Point3{ .x = 1, .y = 2 };
214262 try expect(pt.addPointCoords(i32) == 3);
215263}
......@@ -225,6 +273,9 @@ const Point3 = struct {
225273};
226274
227275test "pass by non-copying value as method, at comptime" {
276 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
277 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
278
228279 comptime {
229280 var pt = Point2{ .x = 1, .y = 2 };
230281 try expect(pt.addPointCoords() == 3);
......@@ -232,6 +283,9 @@ test "pass by non-copying value as method, at comptime" {
232283}
233284
234285test "implicit cast fn call result to optional in field result" {
286 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
287 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
288
235289 const S = struct {
236290 fn entry() !void {
237291 var x = Foo{
......@@ -255,6 +309,10 @@ test "implicit cast fn call result to optional in field result" {
255309}
256310
257311test "void parameters" {
312 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
313 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
314 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
315
258316 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
259317 try voidFun(1, void{}, 2, {});
260318}
......@@ -267,6 +325,9 @@ fn voidFun(a: i32, b: void, c: i32, d: void) !void {
267325}
268326
269327test "call function with empty string" {
328 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
329 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
330
270331 acceptsString("");
271332}
272333
......@@ -301,6 +362,9 @@ fn fn4() u32 {
301362}
302363
303364test "number literal as an argument" {
365 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
366 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
367
304368 try numberLiteralArg(3);
305369 comptime try numberLiteralArg(3);
306370}
......@@ -311,6 +375,10 @@ fn numberLiteralArg(a: anytype) !void {
311375
312376test "function call with anon list literal" {
313377 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
378 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
379 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
380 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
381
314382 const S = struct {
315383 fn doTheTest() !void {
316384 try consumeVec(.{ 9, 8, 7 });
......@@ -327,6 +395,9 @@ test "function call with anon list literal" {
327395}
328396
329397test "ability to give comptime types and non comptime types to same parameter" {
398 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
399 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
400
330401 const S = struct {
331402 fn doTheTest() !void {
332403 var x: i32 = 1;
test/behavior/for.zig+23-1
......@@ -5,6 +5,9 @@ const expectEqual = std.testing.expectEqual;
55const mem = std.mem;
66
77test "continue in for loop" {
8 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
9 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
10
811 const array = [_]i32{ 1, 2, 3, 4, 5 };
912 var sum: i32 = 0;
1013 for (array) |x| {
......@@ -18,6 +21,9 @@ test "continue in for loop" {
1821}
1922
2023test "break from outer for loop" {
24 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
25 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
26
2127 try testBreakOuter();
2228 comptime try testBreakOuter();
2329}
......@@ -35,6 +41,9 @@ fn testBreakOuter() !void {
3541}
3642
3743test "continue outer for loop" {
44 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
45 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
46
3847 try testContinueOuter();
3948 comptime try testContinueOuter();
4049}
......@@ -52,6 +61,9 @@ fn testContinueOuter() !void {
5261}
5362
5463test "ignore lval with underscore (for loop)" {
64 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
65 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
66
5567 for ([_]void{}) |_, i| {
5668 _ = i;
5769 for ([_]void{}) |_, j| {
......@@ -63,7 +75,10 @@ test "ignore lval with underscore (for loop)" {
6375}
6476
6577test "basic for loop" {
66 if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
78 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
79 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
80 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
81 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
6782
6883 const expected_result = [_]u8{ 9, 8, 7, 6, 0, 1, 2, 3 } ** 3;
6984
......@@ -104,6 +119,10 @@ test "basic for loop" {
104119}
105120
106121test "for with null and T peer types and inferred result location type" {
122 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
123 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
124 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
125
107126 const S = struct {
108127 fn doTheTest(slice: []const u8) !void {
109128 if (for (slice) |item| {
......@@ -121,6 +140,9 @@ test "for with null and T peer types and inferred result location type" {
121140}
122141
123142test "2 break statements and an else" {
143 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
144 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
145
124146 const S = struct {
125147 fn entry(t: bool, f: bool) !void {
126148 var buf: [10]u8 = undefined;
test/behavior/generics.zig+41-2
......@@ -5,6 +5,9 @@ const expect = testing.expect;
55const expectEqual = testing.expectEqual;
66
77test "one param, explicit comptime" {
8 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
9 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
10
811 var x: usize = 0;
912 x += checkSize(i32);
1013 x += checkSize(bool);
......@@ -17,6 +20,9 @@ fn checkSize(comptime T: type) usize {
1720}
1821
1922test "simple generic fn" {
23 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
24 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
25
2026 try expect(max(i32, 3, -1) == 3);
2127 try expect(max(u8, 1, 100) == 100);
2228 if (builtin.zig_backend == .stage1) {
......@@ -37,6 +43,9 @@ fn add(comptime a: i32, b: i32) i32 {
3743
3844const the_max = max(u32, 1234, 5678);
3945test "compile time generic eval" {
46 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
47 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
48
4049 try expect(the_max == 5678);
4150}
4251
......@@ -53,12 +62,20 @@ fn sameButWithFloats(a: f64, b: f64) f64 {
5362}
5463
5564test "fn with comptime args" {
65 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
66 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
67 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
68
5669 try expect(gimmeTheBigOne(1234, 5678) == 5678);
5770 try expect(shouldCallSameInstance(34, 12) == 34);
5871 try expect(sameButWithFloats(0.43, 0.49) == 0.49);
5972}
6073
6174test "anytype params" {
75 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
76 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
77 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
78
6279 try expect(max_i32(12, 34) == 34);
6380 try expect(max_f64(1.2, 3.4) == 3.4);
6481 comptime {
......@@ -80,6 +97,10 @@ fn max_f64(a: f64, b: f64) f64 {
8097}
8198
8299test "type constructed by comptime function call" {
100 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
101 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
102 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
103
83104 var l: SimpleList(10) = undefined;
84105 l.array[0] = 10;
85106 l.array[1] = 11;
......@@ -99,6 +120,9 @@ fn SimpleList(comptime L: usize) type {
99120}
100121
101122test "function with return type type" {
123 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
124 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
125
102126 var list: List(i32) = undefined;
103127 var list2: List(i32) = undefined;
104128 list.length = 10;
......@@ -120,6 +144,9 @@ pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) type {
120144}
121145
122146test "const decls in struct" {
147 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
148 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
149
123150 try expect(GenericDataThing(3).count_plus_one == 4);
124151}
125152fn GenericDataThing(comptime count: isize) type {
......@@ -129,6 +156,9 @@ fn GenericDataThing(comptime count: isize) type {
129156}
130157
131158test "use generic param in generic param" {
159 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
160 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
161
132162 try expect(aGenericFn(i32, 3, 4) == 7);
133163}
134164fn aGenericFn(comptime T: type, comptime a: T, b: T) T {
......@@ -136,6 +166,9 @@ fn aGenericFn(comptime T: type, comptime a: T, b: T) T {
136166}
137167
138168test "generic fn with implicit cast" {
169 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
170 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
171
139172 try expect(getFirstByte(u8, &[_]u8{13}) == 13);
140173 try expect(getFirstByte(u16, &[_]u16{
141174 0,
......@@ -150,6 +183,9 @@ fn getFirstByte(comptime T: type, mem: []const T) u8 {
150183}
151184
152185test "generic fn keeps non-generic parameter types" {
186 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
187 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
188
153189 const A = 128;
154190
155191 const S = struct {
......@@ -165,8 +201,10 @@ test "generic fn keeps non-generic parameter types" {
165201}
166202
167203test "array of generic fns" {
204 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
205 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
168206 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
169 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
207
170208 try expect(foos[0](true));
171209 try expect(!foos[1](true));
172210}
......@@ -185,7 +223,8 @@ fn foo2(arg: anytype) bool {
185223
186224test "generic struct" {
187225 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
188 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
226 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
227 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
189228 var a1 = GenNode(i32){
190229 .value = 13,
191230 .next = null,
test/behavior/if.zig+20
......@@ -4,6 +4,9 @@ const expect = std.testing.expect;
44const expectEqual = std.testing.expectEqual;
55
66test "if statements" {
7 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
8 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
9
710 shouldBeEqual(1, 1);
811 firstEqlThird(2, 1, 2);
912}
......@@ -27,6 +30,9 @@ fn firstEqlThird(a: i32, b: i32, c: i32) void {
2730}
2831
2932test "else if expression" {
33 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
34 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
35
3036 try expect(elseIfExpressionF(1) == 1);
3137}
3238fn elseIfExpressionF(c: u8) u8 {
......@@ -44,6 +50,10 @@ var global_with_val: anyerror!u32 = 0;
4450var global_with_err: anyerror!u32 = error.SomeError;
4551
4652test "unwrap mutable global var" {
53 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
54 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
55 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
56
4757 if (global_with_val) |v| {
4858 try expect(v == 0);
4959 } else |_| {
......@@ -57,6 +67,9 @@ test "unwrap mutable global var" {
5767}
5868
5969test "labeled break inside comptime if inside runtime if" {
70 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
71 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
72
6073 var answer: i32 = 0;
6174 var c = true;
6275 if (c) {
......@@ -68,6 +81,9 @@ test "labeled break inside comptime if inside runtime if" {
6881}
6982
7083test "const result loc, runtime if cond, else unreachable" {
84 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
85 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
86
7187 const Num = enum { One, Two };
7288
7389 var t = true;
......@@ -76,6 +92,10 @@ test "const result loc, runtime if cond, else unreachable" {
7692}
7793
7894test "if copies its payload" {
95 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
96 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
97 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
98
7999 const S = struct {
80100 fn doTheTest() !void {
81101 var tmp: ?i32 = 10;
test/behavior/incomplete_struct_param_tld.zig+3
......@@ -1,3 +1,4 @@
1const builtin = @import("builtin");
12const expect = @import("std").testing.expect;
23
34const A = struct {
......@@ -21,6 +22,8 @@ fn foo(a: A) i32 {
2122}
2223
2324test "incomplete struct param top level declaration" {
25 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
26 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
2427 const a = A{
2528 .b = B{
2629 .c = C{ .x = 13 },
test/behavior/inttoptr.zig+6
......@@ -3,6 +3,8 @@ const builtin = @import("builtin");
33test "casting integer address to function pointer" {
44 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
55 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) return error.SkipZigTest; // TODO
6 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
7 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
68
79 addressToFunction();
810 comptime addressToFunction();
......@@ -14,6 +16,10 @@ fn addressToFunction() void {
1416}
1517
1618test "mutate through ptr initialized with constant intToPtr value" {
19 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
20 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
21 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
22
1723 forceCompilerAnalyzeBranchHardCodedPtrDereference(false);
1824}
1925
test/behavior/member_func.zig+6
......@@ -28,6 +28,9 @@ const HasFuncs = struct {
2828
2929test "standard field calls" {
3030 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
31 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
32 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
33 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
3134
3235 try expect(HasFuncs.one(0) == 1);
3336 try expect(HasFuncs.two(0) == 2);
......@@ -69,6 +72,9 @@ test "standard field calls" {
6972
7073test "@field field calls" {
7174 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
75 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
76 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
77 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
7278
7379 try expect(@field(HasFuncs, "one")(0) == 1);
7480 try expect(@field(HasFuncs, "two")(0) == 2);
test/behavior/null.zig+29
......@@ -29,6 +29,10 @@ test "optional type" {
2929}
3030
3131test "test maybe object and get a pointer to the inner value" {
32 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
33 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
34 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
35
3236 var maybe_bool: ?bool = true;
3337
3438 if (maybe_bool) |*b| {
......@@ -45,6 +49,10 @@ test "rhs maybe unwrap return" {
4549}
4650
4751test "maybe return" {
52 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
53 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
54 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
55
4856 try maybeReturnImpl();
4957 comptime try maybeReturnImpl();
5058}
......@@ -61,6 +69,10 @@ fn foo(x: ?i32) ?bool {
6169}
6270
6371test "test null runtime" {
72 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
73 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
74 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
75
6476 try testTestNullRuntime(null);
6577}
6678fn testTestNullRuntime(x: ?i32) !void {
......@@ -69,6 +81,9 @@ fn testTestNullRuntime(x: ?i32) !void {
6981}
7082
7183test "optional void" {
84 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
85 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
86
7287 try optionalVoidImpl();
7388 comptime try optionalVoidImpl();
7489}
......@@ -89,6 +104,9 @@ fn bar(x: ?void) ?void {
89104const Empty = struct {};
90105
91106test "optional struct{}" {
107 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
108 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
109
92110 _ = try optionalEmptyStructImpl();
93111 _ = comptime try optionalEmptyStructImpl();
94112}
......@@ -107,17 +125,25 @@ fn baz(x: ?Empty) ?Empty {
107125}
108126
109127test "null with default unwrap" {
128 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
129
110130 const x: i32 = null orelse 1;
111131 try expect(x == 1);
112132}
113133
114134test "optional pointer to 0 bit type null value at runtime" {
135 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
136
115137 const EmptyStruct = struct {};
116138 var x: ?*EmptyStruct = null;
117139 try expect(x == null);
118140}
119141
120142test "if var maybe pointer" {
143 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
144 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
145 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
146
121147 try expect(shouldBeAPlus1(Particle{
122148 .a = 14,
123149 .b = 1,
......@@ -159,6 +185,9 @@ const here_is_a_null_literal = SillyStruct{ .context = null };
159185test "unwrap optional which is field of global var" {
160186 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
161187 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
188 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
189 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
190 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
162191
163192 struct_with_optional.field = null;
164193 if (struct_with_optional.field) |payload| {
test/behavior/pointers.zig+19
......@@ -17,6 +17,10 @@ fn testDerefPtr() !void {
1717}
1818
1919test "pointer arithmetic" {
20 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
21 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
22 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
23
2024 var ptr: [*]const u8 = "abcd";
2125
2226 try expect(ptr[0] == 'a');
......@@ -61,6 +65,10 @@ test "initialize const optional C pointer to null" {
6165}
6266
6367test "assigning integer to C pointer" {
68 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
69 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
70 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
71
6472 var x: i32 = 0;
6573 var y: i32 = 1;
6674 var ptr: [*c]u8 = 0;
......@@ -75,6 +83,10 @@ test "assigning integer to C pointer" {
7583}
7684
7785test "C pointer comparison and arithmetic" {
86 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
87 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
88 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
89
7890 const S = struct {
7991 fn doTheTest() !void {
8092 var ptr1: [*c]u32 = 0;
......@@ -133,6 +145,10 @@ test "peer type resolution with C pointers" {
133145}
134146
135147test "implicit casting between C pointer and optional non-C pointer" {
148 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
149 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
150 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
151
136152 var slice: []const u8 = "aoeu";
137153 const opt_many_ptr: ?[*]const u8 = slice.ptr;
138154 var ptr_opt_many_ptr = &opt_many_ptr;
......@@ -172,6 +188,9 @@ test "compare equality of optional and non-optional pointer" {
172188test "allowzero pointer and slice" {
173189 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
174190 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
191 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
192 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
193 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
175194
176195 var ptr = @intToPtr([*]allowzero i32, 0);
177196 var opt_ptr: ?[*]allowzero i32 = ptr;
test/behavior/ref_var_in_if_after_if_2nd_switch_prong.zig+5
......@@ -1,9 +1,14 @@
11const std = @import("std");
2const builtin = @import("builtin");
23const expect = std.testing.expect;
34const mem = std.mem;
45
56var ok: bool = false;
67test "reference a variable in an if after an if in the 2nd switch prong" {
8 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
9 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
10 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
11
712 try foo(true, Num.Two, false, "aoeu");
813 try expect(!ok);
914 try foo(false, Num.One, false, "aoeu");
test/behavior/slice.zig-1
......@@ -248,7 +248,6 @@ test "result location zero sized array inside struct field implicit cast to slic
248248test "runtime safety lets us slice from len..len" {
249249 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
250250 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
251 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
252251
253252 var an_array = [_]u8{ 1, 2, 3 };
254253 try expect(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), ""));
test/behavior/src.zig+5-1
......@@ -1,8 +1,12 @@
11const std = @import("std");
2const builtin = @import("builtin");
23const expect = std.testing.expect;
34
45test "@src" {
5 try doTheTest();
6 // TODO why is this failing on stage1?
7 return error.SkipZigTest;
8
9 // try doTheTest();
610}
711
812fn doTheTest() !void {
test/behavior/struct.zig+4-8
......@@ -86,7 +86,8 @@ const StructFoo = struct {
8686
8787test "structs" {
8888 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
89 if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
89 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
90 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
9091
9192 var foo: StructFoo = undefined;
9293 @memset(@ptrCast([*]u8, &foo), 0, @sizeOf(StructFoo));
......@@ -248,7 +249,8 @@ test "usingnamespace within struct scope" {
248249
249250test "struct field init with catch" {
250251 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
251 if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
252 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
253 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
252254
253255 const S = struct {
254256 fn doTheTest() !void {
......@@ -310,7 +312,6 @@ test "struct point to self" {
310312 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
311313 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
312314 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
313 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
314315
315316 var root: Node = undefined;
316317 root.val.x = 1;
......@@ -350,7 +351,6 @@ test "return empty struct from fn" {
350351 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
351352 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
352353 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
353 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
354354
355355 _ = testReturnEmptyStructFromFn();
356356}
......@@ -364,7 +364,6 @@ test "pass slice of empty struct to fn" {
364364 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
365365 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
366366 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
367 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
368367
369368 try expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1);
370369}
......@@ -409,7 +408,6 @@ test "align 1 field before self referential align 8 field as slice return type"
409408 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
410409 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
411410 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
412 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
413411
414412 const result = alloc(Expr);
415413 try expect(result.len == 0);
......@@ -670,7 +668,6 @@ test "default struct initialization fields" {
670668 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
671669 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
672670 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
673 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
674671
675672 const S = struct {
676673 a: i32 = 1234,
......@@ -936,7 +933,6 @@ test "anonymous struct literal syntax" {
936933 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
937934 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
938935 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
939 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
940936
941937 const S = struct {
942938 const Point = struct {
test/behavior/this.zig+7
......@@ -1,4 +1,5 @@
11const expect = @import("std").testing.expect;
2const builtin = @import("builtin");
23
34const module = @This();
45
......@@ -20,10 +21,16 @@ fn add(x: i32, y: i32) i32 {
2021}
2122
2223test "this refer to module call private fn" {
24 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
25 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
26
2327 try expect(module.add(1, 2) == 3);
2428}
2529
2630test "this refer to container" {
31 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
32 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
33
2734 var pt: Point(i32) = undefined;
2835 pt.x = 12;
2936 pt.y = 34;
test/behavior/try.zig+13-1
......@@ -1,6 +1,12 @@
1const expect = @import("std").testing.expect;
1const std = @import("std");
2const builtin = @import("builtin");
3const expect = std.testing.expect;
24
35test "try on error union" {
6 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
7 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
8 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
9
410 try tryOnErrorUnionImpl();
511 comptime try tryOnErrorUnionImpl();
612}
......@@ -19,6 +25,9 @@ fn returnsTen() anyerror!i32 {
1925}
2026
2127test "try without vars" {
28 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
29 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
30
2231 const result1 = if (failIfTrue(true)) 1 else |_| @as(i32, 2);
2332 try expect(result1 == 2);
2433
......@@ -35,6 +44,9 @@ fn failIfTrue(ok: bool) anyerror!void {
3544}
3645
3746test "try then not executed with assignment" {
47 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
48 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
49
3850 if (failIfTrue(true)) {
3951 unreachable;
4052 } else |err| {
test/behavior/type_info.zig+11
......@@ -186,6 +186,10 @@ fn testErrorSet() !void {
186186}
187187
188188test "type info: enum info" {
189 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
190 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
191 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
192
189193 try testEnum();
190194 comptime try testEnum();
191195}
......@@ -249,6 +253,9 @@ fn testUnion() !void {
249253}
250254
251255test "type info: struct info" {
256 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
257 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
258
252259 try testStruct();
253260 comptime try testStruct();
254261}
......@@ -439,6 +446,10 @@ test "type info for async frames" {
439446}
440447
441448test "Declarations are returned in declaration order" {
449 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
450 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
451 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
452
442453 const S = struct {
443454 const a = 1;
444455 const b = 2;
test/behavior/undefined.zig+11
......@@ -16,6 +16,8 @@ test "init static array to undefined" {
1616 // This test causes `initStaticArray()` to be codegen'd, and the
1717 // C backend does not yet support returning arrays, so it fails
1818 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
19 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
20 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
1921
2022 try expect(static_array[0] == 1);
2123 try expect(static_array[4] == 2);
......@@ -43,6 +45,9 @@ fn setFooX(foo: *Foo) void {
4345}
4446
4547test "assign undefined to struct" {
48 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
49 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
50
4651 comptime {
4752 var foo: Foo = undefined;
4853 setFooX(&foo);
......@@ -56,6 +61,9 @@ test "assign undefined to struct" {
5661}
5762
5863test "assign undefined to struct with method" {
64 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
65 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
66
5967 comptime {
6068 var foo: Foo = undefined;
6169 foo.setFooXMethod();
......@@ -69,6 +77,9 @@ test "assign undefined to struct with method" {
6977}
7078
7179test "type name of undefined" {
80 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
81 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
82
7283 const x = undefined;
7384 try expect(mem.eql(u8, @typeName(@TypeOf(x)), "@Type(.Undefined)"));
7485}
test/behavior/underscore.zig+5
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const builtin = @import("builtin");
23const expect = std.testing.expect;
34
45test "ignore lval with underscore" {
......@@ -6,6 +7,10 @@ test "ignore lval with underscore" {
67}
78
89test "ignore lval with underscore (while loop)" {
10 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
11 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
12 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
13
914 while (optionalReturnError()) |_| {
1015 while (optionalReturnError()) |_| {
1116 break;
test/behavior/union.zig+140
......@@ -10,6 +10,10 @@ const Foo = union {
1010};
1111
1212test "basic unions" {
13 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
14 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
15 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
16
1317 var foo = Foo{ .int = 1 };
1418 try expect(foo.int == 1);
1519 foo = Foo{ .float = 12.34 };
......@@ -17,6 +21,10 @@ test "basic unions" {
1721}
1822
1923test "init union with runtime value" {
24 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
25 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
26 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
27
2028 var foo: Foo = undefined;
2129
2230 setFloat(&foo, 12.34);
......@@ -35,6 +43,9 @@ fn setInt(foo: *Foo, x: i32) void {
3543}
3644
3745test "comptime union field access" {
46 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
47 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
48
3849 comptime {
3950 var foo = Foo{ .int = 0 };
4051 try expect(foo.int == 0);
......@@ -50,6 +61,10 @@ const FooExtern = extern union {
5061};
5162
5263test "basic extern unions" {
64 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
65 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
66 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
67
5368 var foo = FooExtern{ .int = 1 };
5469 try expect(foo.int == 1);
5570 foo.float = 12.34;
......@@ -61,10 +76,16 @@ const ExternPtrOrInt = extern union {
6176 int: u64,
6277};
6378test "extern union size" {
79 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
80 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
81
6482 comptime try expect(@sizeOf(ExternPtrOrInt) == 8);
6583}
6684
6785test "0-sized extern union definition" {
86 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
87 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
88
6889 const U = extern union {
6990 a: void,
7091 const f = 1;
......@@ -94,6 +115,10 @@ const err = @as(anyerror!Agg, Agg{
94115const array = [_]Value{ v1, v2, v1, v2 };
95116
96117test "unions embedded in aggregate types" {
118 if (builtin.zig_backend == .stage2_x86_64 and builtin.os.tag == .macos) return error.SkipZigTest;
119 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
120 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
121
97122 switch (array[1]) {
98123 Value.Array => |arr| try expect(arr[4] == 3),
99124 else => unreachable,
......@@ -105,6 +130,9 @@ test "unions embedded in aggregate types" {
105130}
106131
107132test "access a member of tagged union with conflicting enum tag name" {
133 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
134 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
135
108136 const Bar = union(enum) {
109137 A: A,
110138 B: B,
......@@ -117,6 +145,10 @@ test "access a member of tagged union with conflicting enum tag name" {
117145}
118146
119147test "constant tagged union with payload" {
148 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
149 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
150 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
151
120152 var empty = TaggedUnionWithPayload{ .Empty = {} };
121153 var full = TaggedUnionWithPayload{ .Full = 13 };
122154 shouldBeEmpty(empty);
......@@ -143,6 +175,9 @@ const TaggedUnionWithPayload = union(enum) {
143175};
144176
145177test "union alignment" {
178 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
179 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
180
146181 comptime {
147182 try expect(@alignOf(AlignTestTaggedUnion) >= @alignOf([9]u8));
148183 try expect(@alignOf(AlignTestTaggedUnion) >= @alignOf(u64));
......@@ -162,11 +197,18 @@ const Payload = union(Letter) {
162197};
163198
164199test "union with specified enum tag" {
200 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
201 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
202 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
203
165204 try doTest();
166205 comptime try doTest();
167206}
168207
169208test "packed union generates correctly aligned LLVM type" {
209 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
210 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
211 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
170212 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
171213
172214 const U = packed union {
......@@ -204,6 +246,10 @@ fn testComparison() !void {
204246}
205247
206248test "comparison between union and enum literal" {
249 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
250 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
251 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
252
207253 try testComparison();
208254 comptime try testComparison();
209255}
......@@ -215,6 +261,10 @@ const TheUnion = union(TheTag) {
215261 C: i32,
216262};
217263test "cast union to tag type of union" {
264 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
265 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
266 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
267
218268 try testCastUnionToTag();
219269 comptime try testCastUnionToTag();
220270}
......@@ -225,12 +275,19 @@ fn testCastUnionToTag() !void {
225275}
226276
227277test "union field access gives the enum values" {
278 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
279 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
280
228281 try expect(TheUnion.A == TheTag.A);
229282 try expect(TheUnion.B == TheTag.B);
230283 try expect(TheUnion.C == TheTag.C);
231284}
232285
233286test "cast tag type of union to union" {
287 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
288 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
289 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
290
234291 var x: Value2 = Letter2.B;
235292 try expect(@as(Letter2, x) == Letter2.B);
236293}
......@@ -242,6 +299,10 @@ const Value2 = union(Letter2) {
242299};
243300
244301test "implicit cast union to its tag type" {
302 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
303 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
304 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
305
245306 var x: Value2 = Letter2.B;
246307 try expect(x == Letter2.B);
247308 try giveMeLetterB(x);
......@@ -258,6 +319,10 @@ pub const PackThis = union(enum) {
258319};
259320
260321test "constant packed union" {
322 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
323 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
324 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
325
261326 try testConstPackedUnion(&[_]PackThis{PackThis{ .StringLiteral = 1 }});
262327}
263328
......@@ -272,6 +337,10 @@ const MultipleChoice = union(enum(u32)) {
272337 D = 1000,
273338};
274339test "simple union(enum(u32))" {
340 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
341 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
342 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
343
275344 var x = MultipleChoice.C;
276345 try expect(x == MultipleChoice.C);
277346 try expect(@enumToInt(@as(Tag(MultipleChoice), x)) == 60);
......@@ -282,6 +351,9 @@ const PackedPtrOrInt = packed union {
282351 int: u64,
283352};
284353test "packed union size" {
354 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
355 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
356
285357 comptime try expect(@sizeOf(PackedPtrOrInt) == 8);
286358}
287359
......@@ -289,10 +361,17 @@ const ZeroBits = union {
289361 OnlyField: void,
290362};
291363test "union with only 1 field which is void should be zero bits" {
364 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
365 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
366
292367 comptime try expect(@sizeOf(ZeroBits) == 0);
293368}
294369
295370test "tagged union initialization with runtime void" {
371 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
372 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
373 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
374
296375 try expect(testTaggedUnionInit({}));
297376}
298377
......@@ -309,6 +388,10 @@ fn testTaggedUnionInit(x: anytype) bool {
309388pub const UnionEnumNoPayloads = union(enum) { A, B };
310389
311390test "tagged union with no payloads" {
391 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
392 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
393 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
394
312395 const a = UnionEnumNoPayloads{ .B = {} };
313396 switch (a) {
314397 Tag(UnionEnumNoPayloads).A => @panic("wrong"),
......@@ -317,6 +400,10 @@ test "tagged union with no payloads" {
317400}
318401
319402test "union with only 1 field casted to its enum type" {
403 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
404 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
405 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
406
320407 const Literal = union(enum) {
321408 Number: f64,
322409 Bool: bool,
......@@ -334,6 +421,9 @@ test "union with only 1 field casted to its enum type" {
334421}
335422
336423test "union with one member defaults to u0 tag type" {
424 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
425 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
426
337427 const U0 = union(enum) {
338428 X: u32,
339429 };
......@@ -348,6 +438,10 @@ const Foo1 = union(enum) {
348438var glbl: Foo1 = undefined;
349439
350440test "global union with single field is correctly initialized" {
441 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
442 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
443 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
444
351445 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
352446 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
353447
......@@ -365,6 +459,10 @@ pub const FooUnion = union(enum) {
365459var glbl_array: [2]FooUnion = undefined;
366460
367461test "initialize global array of union" {
462 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
463 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
464 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
465
368466 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
369467 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
370468
......@@ -375,6 +473,10 @@ test "initialize global array of union" {
375473}
376474
377475test "update the tag value for zero-sized unions" {
476 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
477 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
478 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
479
378480 const S = union(enum) {
379481 U0: void,
380482 U1: void,
......@@ -386,6 +488,10 @@ test "update the tag value for zero-sized unions" {
386488}
387489
388490test "union initializer generates padding only if needed" {
491 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
492 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
493 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
494
389495 const U = union(enum) {
390496 A: u24,
391497 };
......@@ -395,6 +501,10 @@ test "union initializer generates padding only if needed" {
395501}
396502
397503test "runtime tag name with single field" {
504 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
505 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
506 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
507
398508 const U = union(enum) {
399509 A: i32,
400510 };
......@@ -404,6 +514,10 @@ test "runtime tag name with single field" {
404514}
405515
406516test "method call on an empty union" {
517 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
518 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
519 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
520
407521 const S = struct {
408522 const MyUnion = union(MyUnionTag) {
409523 pub const MyUnionTag = enum { X1, X2 };
......@@ -441,6 +555,10 @@ const FooNoVoid = union(enum) {
441555const Baz = enum { A, B, C, D };
442556
443557test "tagged union type" {
558 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
559 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
560 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
561
444562 const foo1 = TaggedFoo{ .One = 13 };
445563 const foo2 = TaggedFoo{
446564 .Two = Point{
......@@ -460,6 +578,10 @@ test "tagged union type" {
460578}
461579
462580test "tagged union as return value" {
581 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
582 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
583 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
584
463585 switch (returnAnInt(13)) {
464586 TaggedFoo.One => |value| try expect(value == 13),
465587 else => unreachable,
......@@ -471,6 +593,10 @@ fn returnAnInt(x: i32) TaggedFoo {
471593}
472594
473595test "tagged union with all void fields but a meaningful tag" {
596 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
597 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
598 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
599
474600 const S = struct {
475601 const B = union(enum) {
476602 c: C,
......@@ -496,6 +622,9 @@ test "tagged union with all void fields but a meaningful tag" {
496622
497623test "union(enum(u32)) with specified and unspecified tag values" {
498624 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
625 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
626 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
627 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
499628
500629 comptime try expect(Tag(Tag(MultipleChoice2)) == u32);
501630 try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
......@@ -558,6 +687,10 @@ const PartialInstWithPayload = union(enum) {
558687};
559688
560689test "union with only 1 field casted to its enum type which has enum value specified" {
690 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
691 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
692 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
693
561694 const Literal = union(enum) {
562695 Number: f64,
563696 Bool: bool,
......@@ -638,6 +771,10 @@ fn Setter(attr: Attribute) type {
638771}
639772
640773test "return union init with void payload" {
774 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
775 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
776 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
777
641778 const S = struct {
642779 fn entry() !void {
643780 try expect(func().state == State.one);
......@@ -948,6 +1085,9 @@ test "union enum type gets a separate scope" {
9481085test "global variable struct contains union initialized to non-most-aligned field" {
9491086 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
9501087 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
1088 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1089 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
1090 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
9511091
9521092 const T = struct {
9531093 const U = union(enum) {
test/behavior/usingnamespace.zig+19
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const builtin = @import("builtin");
23const expect = std.testing.expect;
34
45const A = struct {
......@@ -10,6 +11,9 @@ const C = struct {
1011};
1112
1213test "basic usingnamespace" {
14 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
15 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
16
1317 try std.testing.expect(C.B == bool);
1418}
1519
......@@ -20,6 +24,9 @@ fn Foo(comptime T: type) type {
2024}
2125
2226test "usingnamespace inside a generic struct" {
27 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
28 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
29
2330 const std2 = Foo(std);
2431 const testing2 = Foo(std.testing);
2532 try std2.testing.expect(true);
......@@ -31,11 +38,17 @@ usingnamespace struct {
3138};
3239
3340test "usingnamespace does not redeclare an imported variable" {
41 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
42 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
43
3444 comptime try std.testing.expect(@This().foo == 42);
3545}
3646
3747usingnamespace @import("usingnamespace/foo.zig");
3848test "usingnamespace omits mixing in private functions" {
49 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
50 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
51
3952 try expect(@This().privateFunction());
4053 try expect(!@This().printText());
4154}
......@@ -44,10 +57,16 @@ fn privateFunction() bool {
4457}
4558
4659test {
60 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
61 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
62
4763 _ = @import("usingnamespace/import_segregation.zig");
4864}
4965
5066usingnamespace @import("usingnamespace/a.zig");
5167test "two files usingnamespace import each other" {
68 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
69 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
70
5271 try expect(@This().ok());
5372}
test/behavior/void.zig+11
......@@ -1,4 +1,5 @@
11const expect = @import("std").testing.expect;
2const builtin = @import("builtin");
23
34const Foo = struct {
45 a: void,
......@@ -18,6 +19,9 @@ test "compare void with void compile time known" {
1819}
1920
2021test "iterate over a void slice" {
22 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
23 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
24
2125 var j: usize = 0;
2226 for (times(10)) |_, i| {
2327 try expect(i == j);
......@@ -30,11 +34,18 @@ fn times(n: usize) []const void {
3034}
3135
3236test "void optional" {
37 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
38 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
39 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
40
3341 var x: ?void = {};
3442 try expect(x != null);
3543}
3644
3745test "void array as a local variable initializer" {
46 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
47 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
48
3849 var x = [_]void{{}} ** 1004;
3950 _ = x[0];
4051}
test/behavior/while.zig+49
......@@ -1,7 +1,11 @@
11const std = @import("std");
2const builtin = @import("builtin");
23const expect = std.testing.expect;
34
45test "while loop" {
6 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
7 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
8
59 var i: i32 = 0;
610 while (i < 4) {
711 i += 1;
......@@ -19,6 +23,9 @@ fn whileLoop2() i32 {
1923}
2024
2125test "static eval while" {
26 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
27 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
28
2229 try expect(static_eval_while_number == 1);
2330}
2431const static_eval_while_number = staticWhileLoop1();
......@@ -98,6 +105,10 @@ fn testBreakOuter() void {
98105}
99106
100107test "while copies its payload" {
108 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
109 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
110 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
111
101112 const S = struct {
102113 fn doTheTest() !void {
103114 var tmp: ?i32 = 10;
......@@ -113,6 +124,8 @@ test "while copies its payload" {
113124}
114125
115126test "continue and break" {
127 if (builtin.zig_backend == .stage2_aarch64 and builtin.os.tag == .macos) return error.SkipZigTest;
128
116129 try runContinueAndBreakTest();
117130 try expect(continue_and_break_counter == 8);
118131}
......@@ -131,6 +144,10 @@ fn runContinueAndBreakTest() !void {
131144}
132145
133146test "while with optional as condition" {
147 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
148 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
149 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
150
134151 numbers_left = 10;
135152 var sum: i32 = 0;
136153 while (getNumberOrNull()) |value| {
......@@ -140,6 +157,10 @@ test "while with optional as condition" {
140157}
141158
142159test "while with optional as condition with else" {
160 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
161 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
162 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
163
143164 numbers_left = 10;
144165 var sum: i32 = 0;
145166 var got_else: i32 = 0;
......@@ -154,6 +175,10 @@ test "while with optional as condition with else" {
154175}
155176
156177test "while with error union condition" {
178 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
179 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
180 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
181
157182 numbers_left = 10;
158183 var sum: i32 = 0;
159184 var got_else: i32 = 0;
......@@ -182,6 +207,10 @@ test "while on bool with else result follow break prong" {
182207}
183208
184209test "while on optional with else result follow else prong" {
210 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
211 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
212 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
213
185214 const result = while (returnNull()) |value| {
186215 break value;
187216 } else @as(i32, 2);
......@@ -189,6 +218,10 @@ test "while on optional with else result follow else prong" {
189218}
190219
191220test "while on optional with else result follow break prong" {
221 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
222 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
223 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
224
192225 const result = while (returnOptional(10)) |value| {
193226 break value;
194227 } else @as(i32, 2);
......@@ -215,6 +248,10 @@ fn returnTrue() bool {
215248}
216249
217250test "return with implicit cast from while loop" {
251 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
252 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
253 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
254
218255 returnWithImplicitCastFromWhileLoopTest() catch unreachable;
219256}
220257fn returnWithImplicitCastFromWhileLoopTest() anyerror!void {
......@@ -224,6 +261,10 @@ fn returnWithImplicitCastFromWhileLoopTest() anyerror!void {
224261}
225262
226263test "while on error union with else result follow else prong" {
264 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
265 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
266 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
267
227268 const result = while (returnError()) |value| {
228269 break value;
229270 } else |_| @as(i32, 2);
......@@ -231,6 +272,10 @@ test "while on error union with else result follow else prong" {
231272}
232273
233274test "while on error union with else result follow break prong" {
275 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
276 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
277 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
278
234279 const result = while (returnSuccess(10)) |value| {
235280 break value;
236281 } else |_| @as(i32, 2);
......@@ -253,6 +298,10 @@ test "while bool 2 break statements and an else" {
253298}
254299
255300test "while optional 2 break statements and an else" {
301 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
302 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
303 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
304
256305 const S = struct {
257306 fn entry(opt_t: ?bool, f: bool) !void {
258307 var ok = false;