authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-25 16:51:57-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-01-25 16:51:57-05:00
logf2835c6a286c9e6bb033cbf04a2ed3463e206bf3
tree1a657f52b1ad7d6bee917e2246ad98505cdf69bd
parent366c76744429cb9c2fcd60abad191b7ef40ed5db
parent0682c9ac3351b1c7159fd123dc226188918579e6
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #10679 from Luukdegram/wasm-unions

Stage2: wasm - Implement unions

21 files changed, 211 insertions(+), 64 deletions(-)

src/arch/wasm/CodeGen.zig+118-46
......@@ -722,9 +722,9 @@ fn typeToValtype(ty: Type, target: std.Target) wasm.Valtype {
722722 if (info.bits > 32 and info.bits <= 64) break :blk wasm.Valtype.i64;
723723 break :blk wasm.Valtype.i32; // represented as pointer to stack
724724 },
725 .Enum => switch (ty.tag()) {
726 .enum_simple => wasm.Valtype.i32,
727 else => typeToValtype(ty.cast(Type.Payload.EnumFull).?.data.tag_ty, target),
725 .Enum => {
726 var buf: Type.Payload.Bits = undefined;
727 return typeToValtype(ty.intTagType(&buf), target);
728728 },
729729 else => wasm.Valtype.i32, // all represented as reference/immediate
730730 };
......@@ -1033,14 +1033,21 @@ pub const DeclGen = struct {
10331033 return Result{ .appended = {} };
10341034 },
10351035 .Enum => {
1036 try writer.writeByteNTimes(0xaa, @intCast(usize, ty.abiSize(self.target())));
1037 return Result{ .appended = {} };
1036 var int_buffer: Value.Payload.U64 = undefined;
1037 const int_val = val.enumToInt(ty, &int_buffer);
1038 var buf: Type.Payload.Bits = undefined;
1039 const int_ty = ty.intTagType(&buf);
1040 return self.genTypedValue(int_ty, int_val, writer);
10381041 },
10391042 .Bool => {
10401043 try writer.writeByte(@boolToInt(val.toBool()));
10411044 return Result{ .appended = {} };
10421045 },
10431046 .Struct => {
1047 const struct_ty = ty.castTag(.@"struct").?.data;
1048 if (struct_ty.layout == .Packed) {
1049 return self.fail("TODO: Packed structs for wasm", .{});
1050 }
10441051 const field_vals = val.castTag(.@"struct").?.data;
10451052 for (field_vals) |field_val, index| {
10461053 const field_ty = ty.structFieldType(index);
......@@ -1053,9 +1060,45 @@ pub const DeclGen = struct {
10531060 return Result{ .appended = {} };
10541061 },
10551062 .Union => {
1056 // TODO: Implement Union declarations
1057 try writer.writeByteNTimes(0xaa, @intCast(usize, ty.abiSize(self.target())));
1058 return Result{ .appended = {} };
1063 const union_val = val.castTag(.@"union").?.data;
1064 const layout = ty.unionGetLayout(self.target());
1065
1066 if (layout.payload_size == 0) {
1067 return self.genTypedValue(ty.unionTagType().?, union_val.tag, writer);
1068 }
1069
1070 // Check if we should store the tag first, in which case, do so now:
1071 if (layout.tag_align >= layout.payload_align) {
1072 switch (try self.genTypedValue(ty.unionTagType().?, union_val.tag, writer)) {
1073 .appended => {},
1074 .externally_managed => |payload| try writer.writeAll(payload),
1075 }
1076 }
1077
1078 const union_ty = ty.cast(Type.Payload.Union).?.data;
1079 const field_index = union_ty.tag_ty.enumTagFieldIndex(union_val.tag).?;
1080 assert(union_ty.haveFieldTypes());
1081 const field_ty = union_ty.fields.values()[field_index].ty;
1082 if (!field_ty.hasRuntimeBits()) {
1083 try writer.writeByteNTimes(0xaa, @intCast(usize, layout.payload_size));
1084 } else {
1085 switch (try self.genTypedValue(field_ty, union_val.val, writer)) {
1086 .appended => {},
1087 .externally_managed => |payload| try writer.writeAll(payload),
1088 }
1089
1090 // Unions have the size of the largest field, so we must pad
1091 // whenever the active field has a smaller size.
1092 const diff = layout.payload_size - field_ty.abiSize(self.target());
1093 if (diff > 0) {
1094 try writer.writeByteNTimes(0xaa, @intCast(usize, diff));
1095 }
1096 }
1097
1098 if (layout.tag_size == 0) {
1099 return Result{ .appended = {} };
1100 }
1101 return self.genTypedValue(union_ty.tag_ty, union_val.tag, writer);
10591102 },
10601103 .Pointer => switch (val.tag()) {
10611104 .variable => {
......@@ -1080,6 +1123,10 @@ pub const DeclGen = struct {
10801123 }
10811124 return Result{ .appended = {} };
10821125 },
1126 .zero => {
1127 try writer.writeByteNTimes(0, @divExact(self.target().cpu.arch.ptrBitWidth(), 8));
1128 return Result{ .appended = {} };
1129 },
10831130 else => return self.fail("TODO: Implement zig decl gen for pointer type value: '{s}'", .{@tagName(val.tag())}),
10841131 },
10851132 .ErrorUnion => {
......@@ -1334,7 +1381,7 @@ fn isByRef(ty: Type, target: std.Target) bool {
13341381 },
13351382 .Pointer => {
13361383 // Slices act like struct and will be passed by reference
1337 if (ty.isSlice()) return ty.hasRuntimeBits();
1384 if (ty.isSlice()) return true;
13381385 return false;
13391386 },
13401387 }
......@@ -1394,6 +1441,7 @@ fn genInst(self: *Self, inst: Air.Inst.Index) !WValue {
13941441 .bit_or => self.airBinOp(inst, .@"or"),
13951442 .bool_and => self.airBinOp(inst, .@"and"),
13961443 .bool_or => self.airBinOp(inst, .@"or"),
1444 .rem => self.airBinOp(inst, .rem),
13971445 .shl => self.airBinOp(inst, .shl),
13981446 .shr => self.airBinOp(inst, .shr),
13991447 .xor => self.airBinOp(inst, .xor),
......@@ -1419,6 +1467,7 @@ fn genInst(self: *Self, inst: Air.Inst.Index) !WValue {
14191467 .dbg_stmt => WValue.none,
14201468 .intcast => self.airIntcast(inst),
14211469 .float_to_int => self.airFloatToInt(inst),
1470 .get_union_tag => self.airGetUnionTag(inst),
14221471
14231472 .is_err => self.airIsErr(inst, .i32_ne),
14241473 .is_non_err => self.airIsErr(inst, .i32_eq),
......@@ -1454,6 +1503,7 @@ fn genInst(self: *Self, inst: Air.Inst.Index) !WValue {
14541503 .slice_ptr => self.airSlicePtr(inst),
14551504 .store => self.airStore(inst),
14561505
1506 .set_union_tag => self.airSetUnionTag(inst),
14571507 .struct_field_ptr => self.airStructFieldPtr(inst),
14581508 .struct_field_ptr_index_0 => self.airStructFieldPtrIndex(inst, 0),
14591509 .struct_field_ptr_index_1 => self.airStructFieldPtrIndex(inst, 1),
......@@ -1477,7 +1527,6 @@ fn genInst(self: *Self, inst: Air.Inst.Index) !WValue {
14771527 .div_float,
14781528 .div_floor,
14791529 .div_exact,
1480 .rem,
14811530 .mod,
14821531 .max,
14831532 .min,
......@@ -1494,8 +1543,7 @@ fn genInst(self: *Self, inst: Air.Inst.Index) !WValue {
14941543 .fpext,
14951544 .unwrap_errunion_payload_ptr,
14961545 .unwrap_errunion_err_ptr,
1497 .set_union_tag,
1498 .get_union_tag,
1546
14991547 .ptr_slice_len_ptr,
15001548 .ptr_slice_ptr_ptr,
15011549 .int_to_float,
......@@ -1518,7 +1566,7 @@ fn genInst(self: *Self, inst: Air.Inst.Index) !WValue {
15181566 .sub_with_overflow,
15191567 .mul_with_overflow,
15201568 .shl_with_overflow,
1521 => |tag| self.fail("TODO: Implement wasm inst: {s}", .{@tagName(tag)}),
1569 => |tag| return self.fail("TODO: Implement wasm inst: {s}", .{@tagName(tag)}),
15221570 };
15231571}
15241572
......@@ -1596,6 +1644,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
15961644 break :blk func.data.owner_decl;
15971645 } else if (func_val.castTag(.extern_fn)) |ext_fn| {
15981646 break :blk ext_fn.data;
1647 } else if (func_val.castTag(.decl_ref)) |decl_ref| {
1648 break :blk decl_ref.data;
15991649 }
16001650 return self.fail("Expected a function, but instead found type '{s}'", .{func_val.tag()});
16011651 };
......@@ -1697,7 +1747,7 @@ fn store(self: *Self, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerErro
16971747
16981748 return self.memCopy(ty, lhs, rhs);
16991749 },
1700 .Struct, .Array => {
1750 .Struct, .Array, .Union => {
17011751 return try self.memCopy(ty, lhs, rhs);
17021752 },
17031753 .Pointer => {
......@@ -1720,18 +1770,8 @@ fn store(self: *Self, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerErro
17201770 try self.emitWValue(lhs);
17211771 try self.emitWValue(rhs);
17221772 const valtype = typeToValtype(ty, self.target);
1723 // check if we should pass by pointer or value based on ABI size
1724 // TODO: Implement a way to get ABI values from a given type,
1725 // that is portable across the backend, rather than copying logic.
1726 const abi_size = switch (ty.zigTypeTag()) {
1727 .Int,
1728 .Float,
1729 .ErrorSet,
1730 .Enum,
1731 .Bool,
1732 => @intCast(u8, ty.abiSize(self.target)),
1733 else => @as(u8, 4),
1734 };
1773 const abi_size = @intCast(u8, ty.abiSize(self.target));
1774
17351775 const opcode = buildOpcode(.{
17361776 .valtype1 = valtype,
17371777 .width = abi_size * 8, // use bitsize instead of byte size
......@@ -1771,22 +1811,9 @@ fn load(self: *Self, operand: WValue, ty: Type, offset: u32) InnerError!WValue {
17711811 .unsigned
17721812 else
17731813 .signed;
1774 // TODO: Implement a way to get ABI values from a given type,
1775 // that is portable across the backend, rather than copying logic.
1776 const abi_size = switch (ty.zigTypeTag()) {
1777 .Int,
1778 .Float,
1779 .ErrorSet,
1780 .Enum,
1781 .Bool,
1782 .ErrorUnion,
1783 => @intCast(u8, ty.abiSize(self.target)),
1784 .Optional => blk: {
1785 if (ty.isPtrLikeOptional()) break :blk @intCast(u8, self.ptrSize());
1786 break :blk @intCast(u8, ty.abiSize(self.target));
1787 },
1788 else => @as(u8, 4),
1789 };
1814
1815 // TODO: Revisit below to determine if optional zero-sized pointers should still have abi-size 4.
1816 const abi_size = if (ty.isPtrLikeOptional()) @as(u8, 4) else @intCast(u8, ty.abiSize(self.target));
17901817
17911818 const opcode = buildOpcode(.{
17921819 .valtype1 = typeToValtype(ty, self.target),
......@@ -1952,7 +1979,13 @@ fn lowerConstant(self: *Self, val: Value, ty: Type) InnerError!WValue {
19521979 return WValue{ .imm32 = field_index.data };
19531980 }
19541981 },
1955 else => unreachable,
1982 .enum_numbered => {
1983 const index = field_index.data;
1984 const enum_data = ty.castTag(.enum_numbered).?.data;
1985 const enum_val = enum_data.values.keys()[index];
1986 return self.lowerConstant(enum_val, enum_data.tag_ty);
1987 },
1988 else => return self.fail("TODO: lowerConstant for enum tag: {}", .{ty.tag()}),
19561989 }
19571990 } else {
19581991 var int_tag_buffer: Type.Payload.Bits = undefined;
......@@ -2724,7 +2757,7 @@ fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
27242757 const elem_size = elem_ty.abiSize(self.target);
27252758
27262759 // load pointer onto stack
2727 const slice_ptr = try self.load(slice, slice_ty, 0);
2760 const slice_ptr = try self.load(slice, Type.usize, 0);
27282761 try self.addLabel(.local_get, slice_ptr.local);
27292762
27302763 // calculate index into slice
......@@ -2746,14 +2779,13 @@ fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
27462779 if (self.liveness.isUnused(inst)) return WValue.none;
27472780 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
27482781 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
2749 const slice_ty = self.air.typeOf(bin_op.lhs);
27502782 const elem_ty = self.air.getRefType(ty_pl.ty).childType();
27512783 const elem_size = elem_ty.abiSize(self.target);
27522784
27532785 const slice = try self.resolveInst(bin_op.lhs);
27542786 const index = try self.resolveInst(bin_op.rhs);
27552787
2756 const slice_ptr = try self.load(slice, slice_ty, 0);
2788 const slice_ptr = try self.load(slice, Type.usize, 0);
27572789 try self.addLabel(.local_get, slice_ptr.local);
27582790
27592791 // calculate index into slice
......@@ -3177,3 +3209,43 @@ fn cmpBigInt(self: *Self, lhs: WValue, rhs: WValue, operand_ty: Type, op: std.ma
31773209 try self.addLabel(.local_set, result.local);
31783210 return result;
31793211}
3212
3213fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
3214 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
3215 const un_ty = self.air.typeOf(bin_op.lhs).childType();
3216 const tag_ty = self.air.typeOf(bin_op.rhs);
3217 const layout = un_ty.unionGetLayout(self.target);
3218 if (layout.tag_size == 0) return WValue{ .none = {} };
3219 const union_ptr = try self.resolveInst(bin_op.lhs);
3220 const new_tag = try self.resolveInst(bin_op.rhs);
3221 if (layout.payload_size == 0) {
3222 try self.store(union_ptr, new_tag, tag_ty, 0);
3223 return WValue{ .none = {} };
3224 }
3225
3226 // when the tag alignment is smaller than the payload, the field will be stored
3227 // after the payload.
3228 const offset = if (layout.tag_align < layout.payload_align) blk: {
3229 break :blk @intCast(u32, layout.payload_size);
3230 } else @as(u32, 0);
3231 try self.store(union_ptr, new_tag, tag_ty, offset);
3232 return WValue{ .none = {} };
3233}
3234
3235fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
3236 if (self.liveness.isUnused(inst)) return WValue{ .none = {} };
3237
3238 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
3239 const un_ty = self.air.typeOf(ty_op.operand);
3240 const tag_ty = self.air.typeOfIndex(inst);
3241 const layout = un_ty.unionGetLayout(self.target);
3242 if (layout.tag_size == 0) return WValue{ .none = {} };
3243 const operand = try self.resolveInst(ty_op.operand);
3244
3245 // when the tag alignment is smaller than the payload, the field will be stored
3246 // after the payload.
3247 const offset = if (layout.tag_align < layout.payload_align) blk: {
3248 break :blk @intCast(u32, layout.payload_size);
3249 } else @as(u32, 0);
3250 return self.load(operand, tag_ty, offset);
3251}
src/arch/wasm/Emit.zig+4
......@@ -173,6 +173,10 @@ pub fn emitMir(emit: *Emit) InnerError!void {
173173 .i64_trunc_f32_u => try emit.emitTag(tag),
174174 .i64_trunc_f64_s => try emit.emitTag(tag),
175175 .i64_trunc_f64_u => try emit.emitTag(tag),
176 .i32_rem_s => try emit.emitTag(tag),
177 .i32_rem_u => try emit.emitTag(tag),
178 .i64_rem_s => try emit.emitTag(tag),
179 .i64_rem_u => try emit.emitTag(tag),
176180
177181 .extended => try emit.emitExtended(inst),
178182 }
src/arch/wasm/Mir.zig+8
......@@ -327,6 +327,10 @@ pub const Inst = struct {
327327 /// Uses `tag`
328328 i32_div_u = 0x6E,
329329 /// Uses `tag`
330 i32_rem_s = 0x6F,
331 /// Uses `tag`
332 i32_rem_u = 0x70,
333 /// Uses `tag`
330334 i32_and = 0x71,
331335 /// Uses `tag`
332336 i32_or = 0x72,
......@@ -349,6 +353,10 @@ pub const Inst = struct {
349353 /// Uses `tag`
350354 i64_div_u = 0x80,
351355 /// Uses `tag`
356 i64_rem_s = 0x81,
357 /// Uses `tag`
358 i64_rem_u = 0x82,
359 /// Uses `tag`
352360 i64_and = 0x83,
353361 /// Uses `tag`
354362 i64_or = 0x84,
test/behavior.zig+17-17
......@@ -3,18 +3,34 @@ const builtin = @import("builtin");
33test {
44 // Tests that pass for stage1, llvm backend, C backend, wasm backend, arm backend and x86_64 backend.
55 _ = @import("behavior/align.zig");
6 _ = @import("behavior/alignof.zig");
67 _ = @import("behavior/array.zig");
8 _ = @import("behavior/bit_shifting.zig");
79 _ = @import("behavior/bool.zig");
10 _ = @import("behavior/bugs/394.zig");
811 _ = @import("behavior/bugs/655.zig");
12 _ = @import("behavior/bugs/656.zig");
913 _ = @import("behavior/bugs/679.zig");
1014 _ = @import("behavior/bugs/1111.zig");
15 _ = @import("behavior/bugs/1277.zig");
16 _ = @import("behavior/bugs/1310.zig");
17 _ = @import("behavior/bugs/1381.zig");
18 _ = @import("behavior/bugs/1500.zig");
19 _ = @import("behavior/bugs/1735.zig");
20 _ = @import("behavior/bugs/2006.zig");
1121 _ = @import("behavior/bugs/2346.zig");
22 _ = @import("behavior/bugs/3112.zig");
23 _ = @import("behavior/bugs/3367.zig");
1224 _ = @import("behavior/bugs/6850.zig");
25 _ = @import("behavior/bugs/7250.zig");
1326 _ = @import("behavior/cast.zig");
1427 _ = @import("behavior/comptime_memory.zig");
1528 _ = @import("behavior/fn_in_struct_in_comptime.zig");
29 _ = @import("behavior/generics_llvm.zig");
1630 _ = @import("behavior/hasdecl.zig");
1731 _ = @import("behavior/hasfield.zig");
32 _ = @import("behavior/namespace_depends_on_compile_var.zig");
33 _ = @import("behavior/optional_llvm.zig");
1834 _ = @import("behavior/prefetch.zig");
1935 _ = @import("behavior/pub_enum.zig");
2036 _ = @import("behavior/slice_sentinel_comptime.zig");
......@@ -60,6 +76,7 @@ test {
6076 _ = @import("behavior/type_info.zig");
6177 _ = @import("behavior/undefined.zig");
6278 _ = @import("behavior/underscore.zig");
79 _ = @import("behavior/union.zig");
6380 _ = @import("behavior/usingnamespace.zig");
6481 _ = @import("behavior/void.zig");
6582 _ = @import("behavior/while.zig");
......@@ -68,30 +85,16 @@ test {
6885 // Tests that pass for stage1, llvm backend, C backend
6986 _ = @import("behavior/cast_int.zig");
7087 _ = @import("behavior/int128.zig");
71 _ = @import("behavior/union.zig");
7288 _ = @import("behavior/translate_c_macros.zig");
7389
7490 if (builtin.zig_backend != .stage2_c) {
7591 // Tests that pass for stage1 and the llvm backend.
76 _ = @import("behavior/alignof.zig");
7792 _ = @import("behavior/array_llvm.zig");
7893 _ = @import("behavior/atomics.zig");
7994 _ = @import("behavior/basic_llvm.zig");
80 _ = @import("behavior/bit_shifting.zig");
81 _ = @import("behavior/bugs/394.zig");
82 _ = @import("behavior/bugs/656.zig");
83 _ = @import("behavior/bugs/1277.zig");
84 _ = @import("behavior/bugs/1310.zig");
85 _ = @import("behavior/bugs/1381.zig");
86 _ = @import("behavior/bugs/1500.zig");
87 _ = @import("behavior/bugs/1735.zig");
8895 _ = @import("behavior/bugs/1741.zig");
89 _ = @import("behavior/bugs/2006.zig");
9096 _ = @import("behavior/bugs/2578.zig");
9197 _ = @import("behavior/bugs/3007.zig");
92 _ = @import("behavior/bugs/3112.zig");
93 _ = @import("behavior/bugs/3367.zig");
94 _ = @import("behavior/bugs/7250.zig");
9598 _ = @import("behavior/bugs/9584.zig");
9699 _ = @import("behavior/cast_llvm.zig");
97100 _ = @import("behavior/enum_llvm.zig");
......@@ -99,13 +102,10 @@ test {
99102 _ = @import("behavior/eval.zig");
100103 _ = @import("behavior/floatop.zig");
101104 _ = @import("behavior/fn.zig");
102 _ = @import("behavior/generics_llvm.zig");
103105 _ = @import("behavior/math.zig");
104106 _ = @import("behavior/maximum_minimum.zig");
105107 _ = @import("behavior/merge_error_sets.zig");
106 _ = @import("behavior/namespace_depends_on_compile_var.zig");
107108 _ = @import("behavior/null_llvm.zig");
108 _ = @import("behavior/optional_llvm.zig");
109109 _ = @import("behavior/popcount.zig");
110110 _ = @import("behavior/saturating_arithmetic.zig");
111111 _ = @import("behavior/sizeof_and_typeof.zig");
test/behavior/alignof.zig+6
......@@ -11,6 +11,9 @@ const Foo = struct {
1111};
1212
1313test "@alignOf(T) before referencing T" {
14 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
15 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
16 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1417 comptime try expect(@alignOf(Foo) != maxInt(usize));
1518 if (native_arch == .x86_64) {
1619 comptime try expect(@alignOf(Foo) == 4);
......@@ -18,6 +21,9 @@ test "@alignOf(T) before referencing T" {
1821}
1922
2023test "comparison of @alignOf(T) against zero" {
24 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
25 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
26 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
2127 {
2228 const T = struct { x: u32 };
2329 try expect(!(@alignOf(T) == 0));
test/behavior/bit_shifting.zig+4
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const expect = std.testing.expect;
3const builtin = @import("builtin");
34
45fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime V: type) type {
56 const key_bits = @typeInfo(Key).Int.bits;
......@@ -60,6 +61,9 @@ fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, compt
6061}
6162
6263test "sharded table" {
64 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
65 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
66 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
6367 // realistic 16-way sharding
6468 try testShardedTable(u32, 4, 8);
6569
test/behavior/bugs/1277.zig+3
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const builtin = @import("builtin");
23
34const S = struct {
45 f: ?fn () i32,
......@@ -11,5 +12,7 @@ fn f() i32 {
1112}
1213
1314test "don't emit an LLVM global for a const function when it's in an optional in a struct" {
15 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
16 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1417 try std.testing.expect(s.f.?() == 1234);
1518}
test/behavior/bugs/1310.zig+3
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const expect = std.testing.expect;
3const builtin = @import("builtin");
34
45pub const VM = ?[*]const struct_InvocationTable_;
56pub const struct_InvocationTable_ = extern struct {
......@@ -22,5 +23,7 @@ fn agent_callback(_vm: [*]VM, options: [*]u8) callconv(.C) i32 {
2223}
2324
2425test "fixed" {
26 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
27 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
2528 try expect(agent_callback(undefined, undefined) == 11);
2629}
test/behavior/bugs/1381.zig+3
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const builtin = @import("builtin");
23
34const B = union(enum) {
45 D: u8,
......@@ -11,6 +12,8 @@ const A = union(enum) {
1112};
1213
1314test "union that needs padding bytes inside an array" {
15 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
16 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1417 var as = [_]A{
1518 A{ .B = B{ .D = 1 } },
1619 A{ .B = B{ .D = 1 } },
test/behavior/bugs/1500.zig+4
......@@ -1,3 +1,4 @@
1const builtin = @import("builtin");
12const A = struct {
23 b: B,
34};
......@@ -5,6 +6,9 @@ const A = struct {
56const B = *const fn (A) void;
67
78test "allow these dependencies" {
9 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
10 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
11 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
812 var a: A = undefined;
913 var b: B = undefined;
1014 if (false) {
test/behavior/bugs/1735.zig+4
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const builtin = @import("builtin");
23
34const mystruct = struct {
45 pending: ?listofstructs,
......@@ -41,6 +42,9 @@ const a = struct {
4142};
4243
4344test "initialization" {
45 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
46 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
47 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
4448 var t = a.init();
4549 try std.testing.expect(t.foo.len == 0);
4650}
test/behavior/bugs/2006.zig+4
......@@ -1,10 +1,14 @@
11const std = @import("std");
22const expect = std.testing.expect;
3const builtin = @import("builtin");
34
45const S = struct {
56 p: *S,
67};
78test "bug 2006" {
9 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
10 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
11 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
812 var a: S = undefined;
913 a = S{ .p = undefined };
1014 try expect(@sizeOf(S) != 0);
test/behavior/bugs/3112.zig+3-1
......@@ -13,7 +13,9 @@ fn prev(p: ?State) void {
1313
1414test "zig test crash" {
1515 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
16
16 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
17 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
18 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1719 var global: State = undefined;
1820 global.enter = prev;
1921 global.enter(null);
test/behavior/bugs/3367.zig+4
......@@ -1,3 +1,4 @@
1const builtin = @import("builtin");
12const Foo = struct {
23 usingnamespace Mixin;
34};
......@@ -9,6 +10,9 @@ const Mixin = struct {
910};
1011
1112test "container member access usingnamespace decls" {
13 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
14 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
15 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1216 var foo = Foo{};
1317 foo.two();
1418}
test/behavior/bugs/394.zig+3
......@@ -8,8 +8,11 @@ const S = struct {
88};
99
1010const expect = @import("std").testing.expect;
11const builtin = @import("builtin");
1112
1213test "bug 394 fixed" {
14 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
15 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1316 const x = S{
1417 .x = 3,
1518 .y = E{ .B = 1 },
test/behavior/bugs/656.zig+3
......@@ -1,4 +1,5 @@
11const expect = @import("std").testing.expect;
2const builtin = @import("builtin");
23
34const PrefixOp = union(enum) {
45 Return,
......@@ -10,6 +11,8 @@ const Value = struct {
1011};
1112
1213test "optional if after an if in a switch prong of a switch with 2 prongs in an else" {
14 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
15 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1316 try foo(false, true);
1417}
1518
test/behavior/bugs/7250.zig+4
......@@ -1,3 +1,4 @@
1const builtin = @import("builtin");
12const nrfx_uart_t = extern struct {
23 p_reg: [*c]u32,
34 drv_inst_idx: u8,
......@@ -13,5 +14,8 @@ threadlocal var g_uart0 = nrfx_uart_t{
1314};
1415
1516test "reference a global threadlocal variable" {
17 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
18 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
19 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1620 _ = nrfx_uart_rx(&g_uart0);
1721}
test/behavior/generics_llvm.zig+7
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const expect = std.testing.expect;
3const builtin = @import("builtin");
34
45const foos = [_]fn (anytype) bool{
56 foo1,
......@@ -14,11 +15,17 @@ fn foo2(arg: anytype) bool {
1415}
1516
1617test "array of generic fns" {
18 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_x86_64) return error.SkipZigTest;
1721 try expect(foos[0](true));
1822 try expect(!foos[1](true));
1923}
2024
2125test "generic struct" {
26 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
27 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
28 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
2229 var a1 = GenNode(i32){
2330 .value = 13,
2431 .next = null,
test/behavior/namespace_depends_on_compile_var.zig+3
......@@ -3,6 +3,9 @@ const builtin = @import("builtin");
33const expect = std.testing.expect;
44
55test "namespace depends on compile var" {
6 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
7 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
8 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
69 if (some_namespace.a_bool) {
710 try expect(some_namespace.a_bool);
811 } else {
test/behavior/optional_llvm.zig+4
......@@ -2,8 +2,12 @@ const std = @import("std");
22const testing = std.testing;
33const expect = testing.expect;
44const expectEqual = testing.expectEqual;
5const builtin = @import("builtin");
56
67test "self-referential struct through a slice of optional" {
8 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
9 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
10 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
711 const S = struct {
812 const Node = struct {
913 children: []?Node,
test/behavior/union.zig+2
......@@ -362,6 +362,8 @@ pub const FooUnion = union(enum) {
362362var glbl_array: [2]FooUnion = undefined;
363363
364364test "initialize global array of union" {
365 if (@import("builtin").zig_backend == .stage2_wasm) return error.SkipZigTest;
366
365367 glbl_array[1] = FooUnion{ .U1 = 2 };
366368 glbl_array[0] = FooUnion{ .U0 = 1 };
367369 try expect(glbl_array[0].U0 == 1);