authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-02-03 22:25:46+01:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-02-03 22:31:29+01:00
log588b88b98753f02061e562a9c15c2396bcd95dee
tree2d7a80c842558608392926cf1ddd244fcdf2cd6c
parente35414bf5c356798f201be85303101f59220326c
signaturelock-open Commit is signed but in an unrecognized format.

Move passing behavior tests

Singular tests (such as in the bug ones) are moved to top level with exclusions for non-passing backends. The big behavior tests such as array_llvm and slice are moved to the inner scope with the C backend disabled. They all pass for the wasm backend now

7 files changed, 52 insertions(+), 7 deletions(-)

src/arch/wasm/CodeGen.zig+1-1
......@@ -1198,7 +1198,7 @@ pub const DeclGen = struct {
11981198 const elem_ptr = val.castTag(.elem_ptr).?.data;
11991199 const elem_size = ty.childType().abiSize(self.target());
12001200 const offset = elem_ptr.index * elem_size;
1201 return self.lowerParentPtr(elem_ptr.array_ptr, offset);
1201 return self.lowerParentPtr(elem_ptr.array_ptr, @intCast(usize, offset));
12021202 },
12031203 .int_u64 => return self.genTypedValue(Type.usize, val),
12041204 else => return self.fail("TODO: Implement zig decl gen for pointer type value: '{s}'", .{@tagName(val.tag())}),
test/behavior.zig+6-6
......@@ -10,6 +10,7 @@ test {
1010 _ = @import("behavior/bugs/655.zig");
1111 _ = @import("behavior/bugs/656.zig");
1212 _ = @import("behavior/bugs/679.zig");
13 _ = @import("behavior/bugs/1025.zig");
1314 _ = @import("behavior/bugs/1111.zig");
1415 _ = @import("behavior/bugs/1277.zig");
1516 _ = @import("behavior/bugs/1310.zig");
......@@ -17,6 +18,8 @@ test {
1718 _ = @import("behavior/bugs/1486.zig");
1819 _ = @import("behavior/bugs/1500.zig");
1920 _ = @import("behavior/bugs/1735.zig");
21 _ = @import("behavior/bugs/1741.zig");
22 _ = @import("behavior/bugs/1914.zig");
2023 _ = @import("behavior/bugs/2006.zig");
2124 _ = @import("behavior/bugs/2346.zig");
2225 _ = @import("behavior/bugs/3112.zig");
......@@ -38,7 +41,8 @@ test {
3841 _ = @import("behavior/struct.zig");
3942
4043 if (builtin.zig_backend != .stage2_arm and builtin.zig_backend != .stage2_x86_64) {
41 // Tests that pass for stage1, llvm backend, C backend, wasm backend.
44 // Tests that pass (partly) for stage1, llvm backend, C backend, wasm backend.
45 _ = @import("behavior/array_llvm.zig");
4246 _ = @import("behavior/basic.zig");
4347 _ = @import("behavior/bitcast.zig");
4448 _ = @import("behavior/bugs/624.zig");
......@@ -69,6 +73,7 @@ test {
6973 _ = @import("behavior/pointers.zig");
7074 _ = @import("behavior/ptrcast.zig");
7175 _ = @import("behavior/ref_var_in_if_after_if_2nd_switch_prong.zig");
76 _ = @import("behavior/slice.zig");
7277 _ = @import("behavior/src.zig");
7378 _ = @import("behavior/this.zig");
7479 _ = @import("behavior/try.zig");
......@@ -88,11 +93,7 @@ test {
8893
8994 if (builtin.zig_backend != .stage2_c) {
9095 // Tests that pass for stage1 and the llvm backend.
91 _ = @import("behavior/array_llvm.zig");
9296 _ = @import("behavior/atomics.zig");
93 _ = @import("behavior/bugs/1025.zig");
94 _ = @import("behavior/bugs/1741.zig");
95 _ = @import("behavior/bugs/1914.zig");
9697 _ = @import("behavior/bugs/2578.zig");
9798 _ = @import("behavior/bugs/3007.zig");
9899 _ = @import("behavior/bugs/9584.zig");
......@@ -108,7 +109,6 @@ test {
108109 _ = @import("behavior/popcount.zig");
109110 _ = @import("behavior/saturating_arithmetic.zig");
110111 _ = @import("behavior/sizeof_and_typeof.zig");
111 _ = @import("behavior/slice.zig");
112112 _ = @import("behavior/struct_llvm.zig");
113113 _ = @import("behavior/switch.zig");
114114 _ = @import("behavior/widening.zig");
test/behavior/array_llvm.zig+18
......@@ -7,6 +7,7 @@ var s_array: [8]Sub = undefined;
77const Sub = struct { b: u8 };
88const Str = struct { a: []Sub };
99test "set global var array via slice embedded in struct" {
10 if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
1011 var s = Str{ .a = s_array[0..] };
1112
1213 s.a[0].b = 1;
......@@ -19,6 +20,7 @@ test "set global var array via slice embedded in struct" {
1920}
2021
2122test "read/write through global variable array of struct fields initialized via array mult" {
23 if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
2224 const S = struct {
2325 fn doTheTest() !void {
2426 try expect(storage[0].term == 1);
......@@ -36,6 +38,7 @@ test "read/write through global variable array of struct fields initialized via
3638}
3739
3840test "implicit cast single-item pointer" {
41 if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
3942 try testImplicitCastSingleItemPtr();
4043 comptime try testImplicitCastSingleItemPtr();
4144}
......@@ -52,6 +55,7 @@ fn testArrayByValAtComptime(b: [2]u8) u8 {
5255}
5356
5457test "comptime evaluating function that takes array by value" {
58 if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
5559 const arr = [_]u8{ 1, 2 };
5660 const x = comptime testArrayByValAtComptime(arr);
5761 const y = comptime testArrayByValAtComptime(arr);
......@@ -60,12 +64,14 @@ test "comptime evaluating function that takes array by value" {
6064}
6165
6266test "runtime initialize array elem and then implicit cast to slice" {
67 if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
6368 var two: i32 = 2;
6469 const x: []const i32 = &[_]i32{two};
6570 try expect(x[0] == 2);
6671}
6772
6873test "array literal as argument to function" {
74 if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
6975 const S = struct {
7076 fn entry(two: i32) !void {
7177 try foo(&[_]i32{ 1, 2, 3 });
......@@ -90,6 +96,7 @@ test "array literal as argument to function" {
9096}
9197
9298test "double nested array to const slice cast in array literal" {
99 if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
93100 const S = struct {
94101 fn entry(two: i32) !void {
95102 const cases = [_][]const []const i32{
......@@ -147,6 +154,7 @@ test "double nested array to const slice cast in array literal" {
147154}
148155
149156test "anonymous literal in array" {
157 if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
150158 const S = struct {
151159 const Foo = struct {
152160 a: usize = 2,
......@@ -168,6 +176,7 @@ test "anonymous literal in array" {
168176}
169177
170178test "access the null element of a null terminated array" {
179 if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
171180 const S = struct {
172181 fn doTheTest() !void {
173182 var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' };
......@@ -181,6 +190,7 @@ test "access the null element of a null terminated array" {
181190}
182191
183192test "type deduction for array subscript expression" {
193 if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
184194 const S = struct {
185195 fn doTheTest() !void {
186196 var array = [_]u8{ 0x55, 0xAA };
......@@ -196,6 +206,8 @@ test "type deduction for array subscript expression" {
196206
197207test "sentinel element count towards the ABI size calculation" {
198208 if (@import("builtin").zig_backend == .stage2_llvm) return error.SkipZigTest; // TODO
209 if (@import("builtin").zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
210 if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
199211
200212 const S = struct {
201213 fn doTheTest() !void {
......@@ -218,6 +230,8 @@ test "sentinel element count towards the ABI size calculation" {
218230
219231test "zero-sized array with recursive type definition" {
220232 if (@import("builtin").zig_backend == .stage2_llvm) return error.SkipZigTest; // TODO
233 if (@import("builtin").zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
234 if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
221235
222236 const U = struct {
223237 fn foo(comptime T: type, comptime n: usize) type {
......@@ -237,6 +251,7 @@ test "zero-sized array with recursive type definition" {
237251}
238252
239253test "type coercion of anon struct literal to array" {
254 if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
240255 const S = struct {
241256 const U = union {
242257 a: u32,
......@@ -253,6 +268,7 @@ test "type coercion of anon struct literal to array" {
253268 try expect(arr1[2] == 54);
254269
255270 if (@import("builtin").zig_backend == .stage2_llvm) return error.SkipZigTest; // TODO
271 if (@import("builtin").zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
256272
257273 var x2: U = .{ .a = 42 };
258274 const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } };
......@@ -268,6 +284,8 @@ test "type coercion of anon struct literal to array" {
268284
269285test "type coercion of pointer to anon struct literal to pointer to array" {
270286 if (@import("builtin").zig_backend == .stage2_llvm) return error.SkipZigTest; // TODO
287 if (@import("builtin").zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
288 if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
271289
272290 const S = struct {
273291 const U = union {
test/behavior/bugs/1025.zig+4
......@@ -1,3 +1,5 @@
1const builtin = @import("builtin");
2
13const A = struct {
24 B: type,
35};
......@@ -7,6 +9,8 @@ fn getA() A {
79}
810
911test "bug 1025" {
12 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
13 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
1014 const a = getA();
1115 try @import("std").testing.expect(a.B == u8);
1216}
test/behavior/bugs/1741.zig+3
......@@ -1,6 +1,9 @@
11const std = @import("std");
2const builtin = @import("builtin");
23
34test "fixed" {
5 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
6 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
47 const x: f32 align(128) = 12.34;
58 try std.testing.expect(@ptrToInt(&x) % 128 == 0);
69}
test/behavior/bugs/1914.zig+7
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const builtin = @import("builtin");
23
34const A = struct {
45 b_list_pointer: *const []B,
......@@ -11,6 +12,9 @@ const b_list: []B = &[_]B{};
1112const a = A{ .b_list_pointer = &b_list };
1213
1314test "segfault bug" {
15 if (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;
1418 const assert = std.debug.assert;
1519 const obj = B{ .a_pointer = &a };
1620 assert(obj.a_pointer == &a); // this makes zig crash
......@@ -27,5 +31,8 @@ pub const B2 = struct {
2731var b_value = B2{ .pointer_array = &[_]*A2{} };
2832
2933test "basic stuff" {
34 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
35 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
36 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
3037 std.debug.assert(&b_value == &b_value);
3138}
test/behavior/slice.zig+13
......@@ -27,6 +27,7 @@ comptime {
2727}
2828
2929test "slicing" {
30 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
3031 var array: [20]i32 = undefined;
3132
3233 array[5] = 1234;
......@@ -43,6 +44,7 @@ test "slicing" {
4344}
4445
4546test "const slice" {
47 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
4648 comptime {
4749 const a = "1234567890";
4850 try expect(a.len == 10);
......@@ -53,6 +55,7 @@ test "const slice" {
5355}
5456
5557test "comptime slice of undefined pointer of length 0" {
58 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
5659 const slice1 = @as([*]i32, undefined)[0..0];
5760 try expect(slice1.len == 0);
5861 const slice2 = @as([*]i32, undefined)[100..100];
......@@ -60,6 +63,7 @@ test "comptime slice of undefined pointer of length 0" {
6063}
6164
6265test "implicitly cast array of size 0 to slice" {
66 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
6367 var msg = [_]u8{};
6468 try assertLenIsZero(&msg);
6569}
......@@ -69,6 +73,7 @@ fn assertLenIsZero(msg: []const u8) !void {
6973}
7074
7175test "access len index of sentinel-terminated slice" {
76 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
7277 const S = struct {
7378 fn doTheTest() !void {
7479 var slice: [:0]const u8 = "hello";
......@@ -82,6 +87,7 @@ test "access len index of sentinel-terminated slice" {
8287}
8388
8489test "comptime slice of slice preserves comptime var" {
90 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
8591 comptime {
8692 var buff: [10]u8 = undefined;
8793 buff[0..][0..][0] = 1;
......@@ -90,6 +96,7 @@ test "comptime slice of slice preserves comptime var" {
9096}
9197
9298test "slice of type" {
99 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
93100 comptime {
94101 var types_array = [_]type{ i32, f64, type };
95102 for (types_array) |T, i| {
......@@ -112,6 +119,7 @@ test "slice of type" {
112119}
113120
114121test "generic malloc free" {
122 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
115123 const a = memAlloc(u8, 10) catch unreachable;
116124 memFree(u8, a);
117125}
......@@ -124,6 +132,7 @@ fn memFree(comptime T: type, memory: []T) void {
124132}
125133
126134test "slice of hardcoded address to pointer" {
135 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
127136 const S = struct {
128137 fn doTheTest() !void {
129138 const pointer = @intToPtr([*]u8, 0x04)[0..2];
......@@ -138,6 +147,7 @@ test "slice of hardcoded address to pointer" {
138147}
139148
140149test "comptime slice of pointer preserves comptime var" {
150 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
141151 comptime {
142152 var buff: [10]u8 = undefined;
143153 var a = @ptrCast([*]u8, &buff);
......@@ -147,6 +157,7 @@ test "comptime slice of pointer preserves comptime var" {
147157}
148158
149159test "comptime pointer cast array and then slice" {
160 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
150161 const array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 };
151162
152163 const ptrA: [*]const u8 = @ptrCast([*]const u8, &array);
......@@ -160,6 +171,7 @@ test "comptime pointer cast array and then slice" {
160171}
161172
162173test "slicing zero length array" {
174 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
163175 const s1 = ""[0..];
164176 const s2 = ([_]u32{})[0..];
165177 try expect(s1.len == 0);
......@@ -171,6 +183,7 @@ test "slicing zero length array" {
171183const x = @intToPtr([*]i32, 0x1000)[0..0x500];
172184const y = x[0x100..];
173185test "compile time slice of pointer to hard coded address" {
186 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
174187 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
175188
176189 try expect(@ptrToInt(x) == 0x1000);