diff options
| author | fn ⌃ ⌥ <70830482+FnControlOption@users.noreply.github.com> | 2023-01-22 05:30:38 -0800 |
|---|---|---|
| committer | fn ⌃ ⌥ <70830482+FnControlOption@users.noreply.github.com> | 2023-01-22 05:30:38 -0800 |
| commit | 6089ed9ee77ed034a39c2b557f4608cd8d779d3f (patch) | |
| tree | 9eaf9d78ca73d8c2dc1654e1e8beacbed1551988 /test | |
| parent | be4468be371de34e90a86346b0f6da6f2d85bef4 (diff) | |
| parent | c0284e242f7d78955204dc8a627fecd45aa5e521 (diff) | |
| download | zig-6089ed9ee77ed034a39c2b557f4608cd8d779d3f.tar.gz zig-6089ed9ee77ed034a39c2b557f4608cd8d779d3f.zip | |
Merge branch 'master' into crc
Diffstat (limited to 'test')
| -rw-r--r-- | test/behavior.zig | 1 | ||||
| -rw-r--r-- | test/behavior/bugs/12488.zig | 13 | ||||
| -rw-r--r-- | test/behavior/fn.zig | 23 | ||||
| -rw-r--r-- | test/behavior/pointers.zig | 16 | ||||
| -rw-r--r-- | test/behavior/struct.zig | 5 | ||||
| -rw-r--r-- | test/behavior/vector.zig | 11 | ||||
| -rw-r--r-- | test/c_abi/cfuncs.c | 12 | ||||
| -rw-r--r-- | test/c_abi/main.zig | 16 | ||||
| -rw-r--r-- | test/cases/compile_errors/bad_member_access_on_tuple.zig | 9 | ||||
| -rw-r--r-- | test/link.zig | 5 | ||||
| -rw-r--r-- | test/link/macho/unwind_info/all.h | 41 | ||||
| -rw-r--r-- | test/link/macho/unwind_info/build.zig | 68 | ||||
| -rw-r--r-- | test/link/macho/unwind_info/main.cpp | 24 | ||||
| -rw-r--r-- | test/link/macho/unwind_info/simple_string.cpp | 30 | ||||
| -rw-r--r-- | test/link/macho/unwind_info/simple_string_owner.cpp | 12 | ||||
| -rw-r--r-- | test/link/macho/uuid/build.zig | 12 | ||||
| -rw-r--r-- | test/link/macho/weak_library/build.zig | 2 |
17 files changed, 280 insertions, 20 deletions
diff --git a/test/behavior.zig b/test/behavior.zig index 51a261cc5c..4f8ad67203 100644 --- a/test/behavior.zig +++ b/test/behavior.zig @@ -106,7 +106,6 @@ test { _ = @import("behavior/bugs/12430.zig"); _ = @import("behavior/bugs/12450.zig"); _ = @import("behavior/bugs/12486.zig"); - _ = @import("behavior/bugs/12488.zig"); _ = @import("behavior/bugs/12498.zig"); _ = @import("behavior/bugs/12551.zig"); _ = @import("behavior/bugs/12571.zig"); diff --git a/test/behavior/bugs/12488.zig b/test/behavior/bugs/12488.zig deleted file mode 100644 index b05197b24f..0000000000 --- a/test/behavior/bugs/12488.zig +++ /dev/null @@ -1,13 +0,0 @@ -const expect = @import("std").testing.expect; - -const A = struct { - a: u32, -}; - -fn foo(comptime a: anytype) !void { - try expect(a[0][0] == @sizeOf(A)); -} - -test { - try foo(.{[_]usize{@sizeOf(A)}}); -} diff --git a/test/behavior/fn.zig b/test/behavior/fn.zig index 8dca94a656..d5f959e507 100644 --- a/test/behavior/fn.zig +++ b/test/behavior/fn.zig @@ -517,3 +517,26 @@ test "peer type resolution of inferred error set with non-void payload" { }; try expect(try S.openDataFile(.read) == 1); } + +test "lazy values passed to anytype parameter" { + const A = struct { + a: u32, + fn foo(comptime a: anytype) !void { + try expect(a[0][0] == @sizeOf(@This())); + } + }; + try A.foo(.{[_]usize{@sizeOf(A)}}); + + const B = struct { + fn foo(comptime a: anytype) !void { + try expect(a.x == 0); + } + }; + try B.foo(.{ .x = @sizeOf(B) }); + + const C = struct {}; + try expect(@truncate(u32, @sizeOf(C)) == 0); + + const D = struct {}; + try expect(@sizeOf(D) << 1 == 0); +} diff --git a/test/behavior/pointers.zig b/test/behavior/pointers.zig index c8879453ad..2d55292916 100644 --- a/test/behavior/pointers.zig +++ b/test/behavior/pointers.zig @@ -509,6 +509,7 @@ test "ptrCast comptime known slice to C pointer" { test "ptrToInt on a generic function" { if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO @@ -532,3 +533,18 @@ test "pointer alignment and element type include call expression" { }; try expect(@alignOf(S.P) > 0); } + +test "pointer to array has explicit alignment" { + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + + const S = struct { + const Base = extern struct { a: u8 }; + const Base2 = extern struct { a: u8 }; + fn func(ptr: *[4]Base) *align(1) [4]Base2 { + return @alignCast(1, @ptrCast(*[4]Base2, ptr)); + } + }; + var bases = [_]S.Base{.{ .a = 2 }} ** 4; + const casted = S.func(&bases); + try expect(casted[0].a == 2); +} diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index a32a0ed495..ed3e1ce88f 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -1573,3 +1573,8 @@ test "struct fields get automatically reordered" { }; try expect(@sizeOf(S1) == @sizeOf(S2)); } + +test "directly initiating tuple like struct" { + const a = struct { u8 }{8}; + try expect(a[0] == 8); +} diff --git a/test/behavior/vector.zig b/test/behavior/vector.zig index ba3d98ee56..8bcae5fefc 100644 --- a/test/behavior/vector.zig +++ b/test/behavior/vector.zig @@ -1286,3 +1286,14 @@ test "store to vector in slice" { s[i] = s[0]; try expectEqual(v[1], v[0]); } + +test "addition of vectors represented as strings" { + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO + + const V = @Vector(3, u8); + const foo: V = "foo".*; + const bar: V = @typeName(u32).*; + try expectEqual(V{ 219, 162, 161 }, foo + bar); +} diff --git a/test/c_abi/cfuncs.c b/test/c_abi/cfuncs.c index bd249335c5..bdf58db335 100644 --- a/test/c_abi/cfuncs.c +++ b/test/c_abi/cfuncs.c @@ -1015,3 +1015,15 @@ void __attribute__((stdcall)) stdcall_big_union(union BigUnion x) { assert_or_panic(x.a.c == 3); assert_or_panic(x.a.d == 4); } + +#ifdef __x86_64__ +struct ByRef __attribute__((ms_abi)) c_explict_win64(struct ByRef in) { + in.val = 42; + return in; +} + +struct ByRef __attribute__((sysv_abi)) c_explict_sys_v(struct ByRef in) { + in.val = 42; + return in; +} +#endif diff --git a/test/c_abi/main.zig b/test/c_abi/main.zig index 358e15a929..db76697473 100644 --- a/test/c_abi/main.zig +++ b/test/c_abi/main.zig @@ -1190,3 +1190,19 @@ test "Stdcall ABI big union" { }; stdcall_big_union(x); } + +extern fn c_explict_win64(ByRef) callconv(.Win64) ByRef; +test "explicit SysV calling convention" { + if (builtin.cpu.arch != .x86_64) return error.SkipZigTest; + + const res = c_explict_win64(.{ .val = 1, .arr = undefined }); + try expect(res.val == 42); +} + +extern fn c_explict_sys_v(ByRef) callconv(.SysV) ByRef; +test "explicit Win64 calling convention" { + if (builtin.cpu.arch != .x86_64) return error.SkipZigTest; + + const res = c_explict_sys_v(.{ .val = 1, .arr = undefined }); + try expect(res.val == 42); +} diff --git a/test/cases/compile_errors/bad_member_access_on_tuple.zig b/test/cases/compile_errors/bad_member_access_on_tuple.zig new file mode 100644 index 0000000000..0f91655fc0 --- /dev/null +++ b/test/cases/compile_errors/bad_member_access_on_tuple.zig @@ -0,0 +1,9 @@ +comptime { + _ = @TypeOf(.{}).is_optional; +} + +// error +// backend=stage2 +// target=native +// +// :2:21: error: struct '@TypeOf(.{})' has no member named 'is_optional' diff --git a/test/link.zig b/test/link.zig index 5e26ae728d..c787e8b1ae 100644 --- a/test/link.zig +++ b/test/link.zig @@ -190,6 +190,11 @@ fn addMachOCases(cases: *tests.StandaloneContext) void { .requires_symlinks = true, }); + cases.addBuildFile("test/link/macho/unwind_info/build.zig", .{ + .build_modes = true, + .requires_symlinks = true, + }); + cases.addBuildFile("test/link/macho/uuid/build.zig", .{ .build_modes = false, .requires_symlinks = true, diff --git a/test/link/macho/unwind_info/all.h b/test/link/macho/unwind_info/all.h new file mode 100644 index 0000000000..15efba90d3 --- /dev/null +++ b/test/link/macho/unwind_info/all.h @@ -0,0 +1,41 @@ +#ifndef ALL +#define ALL + +#include <cstddef> +#include <string> +#include <stdexcept> + +struct SimpleString { + SimpleString(size_t max_size); + ~SimpleString(); + + void print(const char* tag) const; + bool append_line(const char* x); + +private: + size_t max_size; + char* buffer; + size_t length; +}; + +struct SimpleStringOwner { + SimpleStringOwner(const char* x); + ~SimpleStringOwner(); + +private: + SimpleString string; +}; + +class Error: public std::exception { +public: + explicit Error(const char* msg) : msg{ msg } {} + virtual ~Error() noexcept {} + virtual const char* what() const noexcept { + return msg.c_str(); + } + +protected: + std::string msg; +}; + +#endif diff --git a/test/link/macho/unwind_info/build.zig b/test/link/macho/unwind_info/build.zig new file mode 100644 index 0000000000..cc00854465 --- /dev/null +++ b/test/link/macho/unwind_info/build.zig @@ -0,0 +1,68 @@ +const std = @import("std"); +const builtin = @import("builtin"); +const Builder = std.build.Builder; +const LibExeObjectStep = std.build.LibExeObjStep; + +pub fn build(b: *Builder) void { + const mode = b.standardReleaseOptions(); + const target: std.zig.CrossTarget = .{ .os_tag = .macos }; + + const test_step = b.step("test", "Test the program"); + + testUnwindInfo(b, test_step, mode, target, false); + testUnwindInfo(b, test_step, mode, target, true); +} + +fn testUnwindInfo( + b: *Builder, + test_step: *std.build.Step, + mode: std.builtin.Mode, + target: std.zig.CrossTarget, + dead_strip: bool, +) void { + const exe = createScenario(b, mode, target); + exe.link_gc_sections = dead_strip; + + const check = exe.checkObject(.macho); + check.checkStart("segname __TEXT"); + check.checkNext("sectname __gcc_except_tab"); + check.checkNext("sectname __unwind_info"); + + switch (builtin.cpu.arch) { + .aarch64 => { + check.checkNext("sectname __eh_frame"); + }, + .x86_64 => {}, // We do not expect `__eh_frame` section on x86_64 in this case + else => unreachable, + } + + check.checkInSymtab(); + check.checkNext("{*} (__TEXT,__text) external ___gxx_personality_v0"); + + const run_cmd = check.runAndCompare(); + run_cmd.expectStdOutEqual( + \\Constructed: a + \\Constructed: b + \\About to destroy: b + \\About to destroy: a + \\Error: Not enough memory! + \\ + ); + + test_step.dependOn(&run_cmd.step); +} + +fn createScenario(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *LibExeObjectStep { + const exe = b.addExecutable("test", null); + b.default_step.dependOn(&exe.step); + exe.addIncludePath("."); + exe.addCSourceFiles(&[_][]const u8{ + "main.cpp", + "simple_string.cpp", + "simple_string_owner.cpp", + }, &[0][]const u8{}); + exe.setBuildMode(mode); + exe.setTarget(target); + exe.linkLibCpp(); + return exe; +} diff --git a/test/link/macho/unwind_info/main.cpp b/test/link/macho/unwind_info/main.cpp new file mode 100644 index 0000000000..8195f80b3c --- /dev/null +++ b/test/link/macho/unwind_info/main.cpp @@ -0,0 +1,24 @@ +#include "all.h" +#include <cstdio> + +void fn_c() { + SimpleStringOwner c{ "cccccccccc" }; +} + +void fn_b() { + SimpleStringOwner b{ "b" }; + fn_c(); +} + +int main() { + try { + SimpleStringOwner a{ "a" }; + fn_b(); + SimpleStringOwner d{ "d" }; + } catch (const Error& e) { + printf("Error: %s\n", e.what()); + } catch(const std::exception& e) { + printf("Exception: %s\n", e.what()); + } + return 0; +} diff --git a/test/link/macho/unwind_info/simple_string.cpp b/test/link/macho/unwind_info/simple_string.cpp new file mode 100644 index 0000000000..15699cd1e4 --- /dev/null +++ b/test/link/macho/unwind_info/simple_string.cpp @@ -0,0 +1,30 @@ +#include "all.h" +#include <cstdio> +#include <cstring> + +SimpleString::SimpleString(size_t max_size) +: max_size{ max_size }, length{} { + if (max_size == 0) { + throw Error{ "Max size must be at least 1." }; + } + buffer = new char[max_size]; + buffer[0] = 0; +} + +SimpleString::~SimpleString() { + delete[] buffer; +} + +void SimpleString::print(const char* tag) const { + printf("%s: %s", tag, buffer); +} + +bool SimpleString::append_line(const char* x) { + const auto x_len = strlen(x); + if (x_len + length + 2 > max_size) return false; + std::strncpy(buffer + length, x, max_size - length); + length += x_len; + buffer[length++] = '\n'; + buffer[length] = 0; + return true; +} diff --git a/test/link/macho/unwind_info/simple_string_owner.cpp b/test/link/macho/unwind_info/simple_string_owner.cpp new file mode 100644 index 0000000000..c242af6ecc --- /dev/null +++ b/test/link/macho/unwind_info/simple_string_owner.cpp @@ -0,0 +1,12 @@ +#include "all.h" + +SimpleStringOwner::SimpleStringOwner(const char* x) : string{ 10 } { + if (!string.append_line(x)) { + throw Error{ "Not enough memory!" }; + } + string.print("Constructed"); +} + +SimpleStringOwner::~SimpleStringOwner() { + string.print("About to destroy"); +} diff --git a/test/link/macho/uuid/build.zig b/test/link/macho/uuid/build.zig index fd7ad57e57..314febdb20 100644 --- a/test/link/macho/uuid/build.zig +++ b/test/link/macho/uuid/build.zig @@ -12,18 +12,18 @@ pub fn build(b: *Builder) void { .os_tag = .macos, }; - testUuid(b, test_step, .ReleaseSafe, aarch64_macos, "af0f4c21a07c30daba59213d80262e45"); - testUuid(b, test_step, .ReleaseFast, aarch64_macos, "af0f4c21a07c30daba59213d80262e45"); - testUuid(b, test_step, .ReleaseSmall, aarch64_macos, "af0f4c21a07c30daba59213d80262e45"); + testUuid(b, test_step, .ReleaseSafe, aarch64_macos, "675bb6ba8e5d3d3191f7936d7168f0e9"); + testUuid(b, test_step, .ReleaseFast, aarch64_macos, "675bb6ba8e5d3d3191f7936d7168f0e9"); + testUuid(b, test_step, .ReleaseSmall, aarch64_macos, "675bb6ba8e5d3d3191f7936d7168f0e9"); const x86_64_macos = std.zig.CrossTarget{ .cpu_arch = .x86_64, .os_tag = .macos, }; - testUuid(b, test_step, .ReleaseSafe, x86_64_macos, "63f47191c7153f5fba48bd63cb2f5f57"); - testUuid(b, test_step, .ReleaseFast, x86_64_macos, "63f47191c7153f5fba48bd63cb2f5f57"); - testUuid(b, test_step, .ReleaseSmall, x86_64_macos, "e7bba66220e33eda9e73ab293ccf93d2"); + testUuid(b, test_step, .ReleaseSafe, x86_64_macos, "5b7071b4587c3071b0d2352fadce0e48"); + testUuid(b, test_step, .ReleaseFast, x86_64_macos, "5b7071b4587c3071b0d2352fadce0e48"); + testUuid(b, test_step, .ReleaseSmall, x86_64_macos, "4b58f2583c383169bbe3a716bd240048"); } fn testUuid( diff --git a/test/link/macho/weak_library/build.zig b/test/link/macho/weak_library/build.zig index 8c41e0dfd1..79f67bd7df 100644 --- a/test/link/macho/weak_library/build.zig +++ b/test/link/macho/weak_library/build.zig @@ -31,6 +31,8 @@ pub fn build(b: *Builder) void { check.checkInSymtab(); check.checkNext("(undefined) weak external _a (from liba)"); + + check.checkInSymtab(); check.checkNext("(undefined) weak external _asStr (from liba)"); const run_cmd = check.runAndCompare(); |
