diff options
Diffstat (limited to 'test/behavior')
| -rw-r--r-- | test/behavior/align.zig | 20 | ||||
| -rw-r--r-- | test/behavior/align_stage1.zig | 17 | ||||
| -rw-r--r-- | test/behavior/basic.zig | 4 | ||||
| -rw-r--r-- | test/behavior/basic_llvm.zig | 4 | ||||
| -rw-r--r-- | test/behavior/bugs/1500.zig | 2 | ||||
| -rw-r--r-- | test/behavior/bugs/3112.zig | 5 | ||||
| -rw-r--r-- | test/behavior/cast_llvm.zig | 6 | ||||
| -rw-r--r-- | test/behavior/comptime_memory.zig | 99 | ||||
| -rw-r--r-- | test/behavior/error.zig | 1 | ||||
| -rw-r--r-- | test/behavior/fn.zig | 12 | ||||
| -rw-r--r-- | test/behavior/inttoptr.zig | 12 | ||||
| -rw-r--r-- | test/behavior/member_func.zig | 10 | ||||
| -rw-r--r-- | test/behavior/slice.zig | 13 | ||||
| -rw-r--r-- | test/behavior/slice_stage2.zig | 12 | ||||
| -rw-r--r-- | test/behavior/union.zig | 5 |
15 files changed, 175 insertions, 47 deletions
diff --git a/test/behavior/align.zig b/test/behavior/align.zig index 26a914576c..19b8c902af 100644 --- a/test/behavior/align.zig +++ b/test/behavior/align.zig @@ -181,3 +181,23 @@ test "page aligned array on stack" { try expect(number1 == 42); try expect(number2 == 43); } + +fn derp() align(@sizeOf(usize) * 2) i32 { + return 1234; +} +fn noop1() align(1) void {} +fn noop4() align(4) void {} + +test "function alignment" { + // function alignment is a compile error on wasm32/wasm64 + if (native_arch == .wasm32 or native_arch == .wasm64) return error.SkipZigTest; + + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; + + try expect(derp() == 1234); + try expect(@TypeOf(noop1) == fn () align(1) void); + try expect(@TypeOf(noop4) == fn () align(4) void); + noop1(); + noop4(); +} diff --git a/test/behavior/align_stage1.zig b/test/behavior/align_stage1.zig index 30d08abb38..71a8c87e82 100644 --- a/test/behavior/align_stage1.zig +++ b/test/behavior/align_stage1.zig @@ -3,23 +3,6 @@ const expect = std.testing.expect; const builtin = @import("builtin"); const native_arch = builtin.target.cpu.arch; -fn derp() align(@sizeOf(usize) * 2) i32 { - return 1234; -} -fn noop1() align(1) void {} -fn noop4() align(4) void {} - -test "function alignment" { - // function alignment is a compile error on wasm32/wasm64 - if (native_arch == .wasm32 or native_arch == .wasm64) return error.SkipZigTest; - - try expect(derp() == 1234); - try expect(@TypeOf(noop1) == fn () align(1) void); - try expect(@TypeOf(noop4) == fn () align(4) void); - noop1(); - noop4(); -} - test "implicitly decreasing fn alignment" { // function alignment is a compile error on wasm32/wasm64 if (native_arch == .wasm32 or native_arch == .wasm64) return error.SkipZigTest; diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index 9064339877..3a7d95457e 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -259,6 +259,8 @@ fn fB() []const u8 { } test "call function pointer in struct" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + try expect(mem.eql(u8, f3(true), "a")); try expect(mem.eql(u8, f3(false), "b")); } @@ -276,7 +278,7 @@ fn f3(x: bool) []const u8 { } const FnPtrWrapper = struct { - fn_ptr: fn () []const u8, + fn_ptr: *const fn () []const u8, }; test "const ptr from var variable" { diff --git a/test/behavior/basic_llvm.zig b/test/behavior/basic_llvm.zig index 32b35bef0a..29cad01567 100644 --- a/test/behavior/basic_llvm.zig +++ b/test/behavior/basic_llvm.zig @@ -205,9 +205,11 @@ test "multiline string literal is null terminated" { } test "self reference through fn ptr field" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + const S = struct { const A = struct { - f: fn (A) u8, + f: *const fn (A) u8, }; fn foo(a: A) u8 { diff --git a/test/behavior/bugs/1500.zig b/test/behavior/bugs/1500.zig index 5683d53721..18fd40cef2 100644 --- a/test/behavior/bugs/1500.zig +++ b/test/behavior/bugs/1500.zig @@ -2,7 +2,7 @@ const A = struct { b: B, }; -const B = fn (A) void; +const B = *const fn (A) void; test "allow these dependencies" { var a: A = undefined; diff --git a/test/behavior/bugs/3112.zig b/test/behavior/bugs/3112.zig index 68e86c7fcb..ea2197eef1 100644 --- a/test/behavior/bugs/3112.zig +++ b/test/behavior/bugs/3112.zig @@ -1,9 +1,10 @@ +const builtin = @import("builtin"); const std = @import("std"); const expect = std.testing.expect; const State = struct { const Self = @This(); - enter: fn (previous: ?Self) void, + enter: *const fn (previous: ?Self) void, }; fn prev(p: ?State) void { @@ -11,6 +12,8 @@ fn prev(p: ?State) void { } test "zig test crash" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + var global: State = undefined; global.enter = prev; global.enter(null); diff --git a/test/behavior/cast_llvm.zig b/test/behavior/cast_llvm.zig index 1b27d10d59..625d54ce3c 100644 --- a/test/behavior/cast_llvm.zig +++ b/test/behavior/cast_llvm.zig @@ -47,12 +47,14 @@ fn incrementVoidPtrArray(array: ?*anyopaque, len: usize) void { } test "compile time int to ptr of function" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) return error.SkipZigTest; // TODO + try foobar(FUNCTION_CONSTANT); } pub const FUNCTION_CONSTANT = @intToPtr(PFN_void, maxInt(usize)); -pub const PFN_void = fn (*anyopaque) callconv(.C) void; +pub const PFN_void = *const fn (*anyopaque) callconv(.C) void; fn foobar(func: PFN_void) !void { try std.testing.expect(@ptrToInt(func) == maxInt(usize)); @@ -154,7 +156,7 @@ test "implicit cast *[0]T to E![]const u8" { var global_array: [4]u8 = undefined; test "cast from array reference to fn" { - const f = @ptrCast(fn () callconv(.C) void, &global_array); + const f = @ptrCast(*const fn () callconv(.C) void, &global_array); try expect(@ptrToInt(f) == @ptrToInt(&global_array)); } diff --git a/test/behavior/comptime_memory.zig b/test/behavior/comptime_memory.zig index 5547b9fd89..24a774aeb6 100644 --- a/test/behavior/comptime_memory.zig +++ b/test/behavior/comptime_memory.zig @@ -1,8 +1,15 @@ -const endian = @import("builtin").cpu.arch.endian(); +const builtin = @import("builtin"); +const endian = builtin.cpu.arch.endian(); const testing = @import("std").testing; const ptr_size = @sizeOf(usize); test "type pun signed and unsigned as single pointer" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend != .stage1) { + // TODO https://github.com/ziglang/zig/issues/9646 + return error.SkipZigTest; + } + comptime { var x: u32 = 0; const y = @ptrCast(*i32, &x); @@ -12,6 +19,12 @@ test "type pun signed and unsigned as single pointer" { } test "type pun signed and unsigned as many pointer" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend != .stage1) { + // TODO https://github.com/ziglang/zig/issues/9646 + return error.SkipZigTest; + } + comptime { var x: u32 = 0; const y = @ptrCast([*]i32, &x); @@ -21,6 +34,12 @@ test "type pun signed and unsigned as many pointer" { } test "type pun signed and unsigned as array pointer" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend != .stage1) { + // TODO https://github.com/ziglang/zig/issues/9646 + return error.SkipZigTest; + } + comptime { var x: u32 = 0; const y = @ptrCast(*[1]i32, &x); @@ -30,6 +49,12 @@ test "type pun signed and unsigned as array pointer" { } test "type pun signed and unsigned as offset many pointer" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend != .stage1) { + // TODO https://github.com/ziglang/zig/issues/9646 + return error.SkipZigTest; + } + comptime { var x: u32 = 0; var y = @ptrCast([*]i32, &x); @@ -40,6 +65,12 @@ test "type pun signed and unsigned as offset many pointer" { } test "type pun signed and unsigned as array pointer" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend != .stage1) { + // TODO https://github.com/ziglang/zig/issues/9646 + return error.SkipZigTest; + } + comptime { var x: u32 = 0; const y = @ptrCast([*]i32, &x) - 10; @@ -50,6 +81,12 @@ test "type pun signed and unsigned as array pointer" { } test "type pun value and struct" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend != .stage1) { + // TODO https://github.com/ziglang/zig/issues/9646 + return error.SkipZigTest; + } + comptime { const StructOfU32 = extern struct { x: u32 }; var inst: StructOfU32 = .{ .x = 0 }; @@ -64,6 +101,12 @@ fn bigToNativeEndian(comptime T: type, v: T) T { return if (endian == .Big) v else @byteSwap(T, v); } test "type pun endianness" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend != .stage1) { + // TODO https://github.com/ziglang/zig/issues/9646 + return error.SkipZigTest; + } + comptime { const StructOfBytes = extern struct { x: [4]u8 }; var inst: StructOfBytes = .{ .x = [4]u8{ 0, 0, 0, 0 } }; @@ -155,6 +198,12 @@ fn doTypePunBitsTest(as_bits: *Bits) !void { } test "type pun bits" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend != .stage1) { + // TODO https://github.com/ziglang/zig/issues/9646 + return error.SkipZigTest; + } + comptime { var v: u32 = undefined; try doTypePunBitsTest(@ptrCast(*Bits, &v)); @@ -167,6 +216,12 @@ const imports = struct { // Make sure lazy values work on their own, before getting into more complex tests test "basic pointer preservation" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend != .stage1) { + // TODO https://github.com/ziglang/zig/issues/9646 + return error.SkipZigTest; + } + comptime { const lazy_address = @ptrToInt(&imports.global_u32); try testing.expectEqual(@ptrToInt(&imports.global_u32), lazy_address); @@ -175,6 +230,12 @@ test "basic pointer preservation" { } test "byte copy preserves linker value" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend != .stage1) { + // TODO https://github.com/ziglang/zig/issues/9646 + return error.SkipZigTest; + } + const ct_value = comptime blk: { const lazy = &imports.global_u32; var result: *u32 = undefined; @@ -193,6 +254,12 @@ test "byte copy preserves linker value" { } test "unordered byte copy preserves linker value" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend != .stage1) { + // TODO https://github.com/ziglang/zig/issues/9646 + return error.SkipZigTest; + } + const ct_value = comptime blk: { const lazy = &imports.global_u32; var result: *u32 = undefined; @@ -212,6 +279,12 @@ test "unordered byte copy preserves linker value" { } test "shuffle chunks of linker value" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend != .stage1) { + // TODO https://github.com/ziglang/zig/issues/9646 + return error.SkipZigTest; + } + const lazy_address = @ptrToInt(&imports.global_u32); const shuffled1_rt = shuffle(lazy_address, Bits, ShuffledBits); const unshuffled1_rt = shuffle(shuffled1_rt, ShuffledBits, Bits); @@ -225,6 +298,12 @@ test "shuffle chunks of linker value" { } test "dance on linker values" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend != .stage1) { + // TODO https://github.com/ziglang/zig/issues/9646 + return error.SkipZigTest; + } + comptime { var arr: [2]usize = undefined; arr[0] = @ptrToInt(&imports.global_u32); @@ -251,6 +330,12 @@ test "dance on linker values" { } test "offset array ptr by element size" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend != .stage1) { + // TODO https://github.com/ziglang/zig/issues/9646 + return error.SkipZigTest; + } + comptime { const VirtualStruct = struct { x: u32 }; var arr: [4]VirtualStruct = .{ @@ -273,6 +358,12 @@ test "offset array ptr by element size" { } test "offset instance by field size" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend != .stage1) { + // TODO https://github.com/ziglang/zig/issues/9646 + return error.SkipZigTest; + } + comptime { const VirtualStruct = struct { x: u32, y: u32, z: u32, w: u32 }; var inst = VirtualStruct{ .x = 0, .y = 1, .z = 2, .w = 3 }; @@ -293,6 +384,12 @@ test "offset instance by field size" { } test "offset field ptr by enclosing array element size" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend != .stage1) { + // TODO https://github.com/ziglang/zig/issues/9646 + return error.SkipZigTest; + } + comptime { const VirtualStruct = struct { x: u32 }; var arr: [4]VirtualStruct = .{ diff --git a/test/behavior/error.zig b/test/behavior/error.zig index b7d4511fe9..3cb1bcf43b 100644 --- a/test/behavior/error.zig +++ b/test/behavior/error.zig @@ -1,3 +1,4 @@ +const builtin = @import("builtin"); const std = @import("std"); const expect = std.testing.expect; const expectError = std.testing.expectError; diff --git a/test/behavior/fn.zig b/test/behavior/fn.zig index 3a1f3e0b35..8cf9fbfe48 100644 --- a/test/behavior/fn.zig +++ b/test/behavior/fn.zig @@ -57,7 +57,7 @@ test "assign inline fn to const variable" { inline fn inlineFn() void {} -fn outer(y: u32) fn (u32) u32 { +fn outer(y: u32) *const fn (u32) u32 { const Y = @TypeOf(y); const st = struct { fn get(z: u32) u32 { @@ -68,6 +68,8 @@ fn outer(y: u32) fn (u32) u32 { } test "return inner function which references comptime variable of outer function" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + var func = outer(10); try expect(func(3) == 7); } @@ -92,6 +94,8 @@ test "discard the result of a function that returns a struct" { } test "inline function call that calls optional function pointer, return pointer at callsite interacts correctly with callsite return type" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + const S = struct { field: u32, @@ -113,7 +117,7 @@ test "inline function call that calls optional function pointer, return pointer return bar2.?(); } - var bar2: ?fn () u32 = null; + var bar2: ?*const fn () u32 = null; fn actualFn() u32 { return 1234; @@ -135,8 +139,10 @@ fn fnWithUnreachable() noreturn { } test "extern struct with stdcallcc fn pointer" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + const S = extern struct { - ptr: fn () callconv(if (builtin.target.cpu.arch == .i386) .Stdcall else .C) i32, + ptr: *const fn () callconv(if (builtin.target.cpu.arch == .i386) .Stdcall else .C) i32, fn foo() callconv(if (builtin.target.cpu.arch == .i386) .Stdcall else .C) i32 { return 1234; diff --git a/test/behavior/inttoptr.zig b/test/behavior/inttoptr.zig index ec26a09699..5c1acf51cd 100644 --- a/test/behavior/inttoptr.zig +++ b/test/behavior/inttoptr.zig @@ -1,14 +1,16 @@ const builtin = @import("builtin"); -test "casting random address to function pointer" { +test "casting integer address to function pointer" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) return error.SkipZigTest; // TODO - randomAddressToFunction(); - comptime randomAddressToFunction(); + + addressToFunction(); + comptime addressToFunction(); } -fn randomAddressToFunction() void { +fn addressToFunction() void { var addr: usize = 0xdeadbeef; - _ = @intToPtr(fn () void, addr); + _ = @intToPtr(*const fn () void, addr); } test "mutate through ptr initialized with constant intToPtr value" { diff --git a/test/behavior/member_func.zig b/test/behavior/member_func.zig index 092a691901..3e4895e729 100644 --- a/test/behavior/member_func.zig +++ b/test/behavior/member_func.zig @@ -1,8 +1,10 @@ -const expect = @import("std").testing.expect; +const builtin = @import("builtin"); +const std = @import("std"); +const expect = std.testing.expect; const HasFuncs = struct { state: u32, - func_field: fn (u32) u32, + func_field: *const fn (u32) u32, fn inc(self: *HasFuncs) void { self.state += 1; @@ -25,6 +27,8 @@ const HasFuncs = struct { }; test "standard field calls" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + try expect(HasFuncs.one(0) == 1); try expect(HasFuncs.two(0) == 2); @@ -64,6 +68,8 @@ test "standard field calls" { } test "@field field calls" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + try expect(@field(HasFuncs, "one")(0) == 1); try expect(@field(HasFuncs, "two")(0) == 2); diff --git a/test/behavior/slice.zig b/test/behavior/slice.zig index 0332cff802..01ae10ee4e 100644 --- a/test/behavior/slice.zig +++ b/test/behavior/slice.zig @@ -1,3 +1,4 @@ +const builtin = @import("builtin"); const std = @import("std"); const expect = std.testing.expect; const expectEqualSlices = std.testing.expectEqualSlices; @@ -166,3 +167,15 @@ test "slicing zero length array" { try expect(mem.eql(u8, s1, "")); try expect(mem.eql(u32, s2, &[_]u32{})); } + +const x = @intToPtr([*]i32, 0x1000)[0..0x500]; +const y = x[0x100..]; +test "compile time slice of pointer to hard coded address" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + + try expect(@ptrToInt(x) == 0x1000); + try expect(x.len == 0x500); + + try expect(@ptrToInt(y) == 0x1400); + try expect(y.len == 0x400); +} diff --git a/test/behavior/slice_stage2.zig b/test/behavior/slice_stage2.zig deleted file mode 100644 index 360527e8ba..0000000000 --- a/test/behavior/slice_stage2.zig +++ /dev/null @@ -1,12 +0,0 @@ -const std = @import("std"); -const expect = std.testing.expect; - -const x = @intToPtr([*]i32, 0x1000)[0..0x500]; -const y = x[0x100..]; -test "compile time slice of pointer to hard coded address" { - try expect(@ptrToInt(x) == 0x1000); - try expect(x.len == 0x500); - - try expect(@ptrToInt(y) == 0x1400); - try expect(y.len == 0x400); -} diff --git a/test/behavior/union.zig b/test/behavior/union.zig index 12190e418c..3136646df5 100644 --- a/test/behavior/union.zig +++ b/test/behavior/union.zig @@ -1,3 +1,4 @@ +const builtin = @import("builtin"); const std = @import("std"); const expect = std.testing.expect; const expectEqual = std.testing.expectEqual; @@ -166,8 +167,10 @@ test "union with specified enum tag" { } test "packed union generates correctly aligned LLVM type" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + const U = packed union { - f1: fn () error{TestUnexpectedResult}!void, + f1: *const fn () error{TestUnexpectedResult}!void, f2: u32, }; var foo = [_]U{ |
