| author | |
| committer | |
| log | 40a50f5e2cd4900d2b3d13b353b18a8b6ae052af |
| tree | 3eb5861ab1b461c6ea52a764f39a1c545a3b3dd1 |
| parent | 47a2437afb3c392771eed8a26aac1bb3c84963af |
| signature | Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM |
6 files changed, 22 insertions(+), 56 deletions(-)
test/c_abi/cfuncs.c+11| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | #include <complex.h> | 1 | #include <complex.h> |
| 2 | #include <inttypes.h> | 2 | #include <inttypes.h> |
| 3 | #include <stdalign.h> | 3 | #include <stdalign.h> |
| 4 | #include <stdarg.h> | ||
| 4 | #include <stdbool.h> | 5 | #include <stdbool.h> |
| 5 | #include <stdlib.h> | 6 | #include <stdlib.h> |
| 6 | #include <string.h> | 7 | #include <string.h> |
| ... | @@ -16775,6 +16776,16 @@ void c_x86_64_sysv_uint_int_uint_int(unsigned a, int b, unsigned c, int d) { | ... | @@ -16775,6 +16776,16 @@ void c_x86_64_sysv_uint_int_uint_int(unsigned a, int b, unsigned c, int d) { |
| 16775 | assert_or_panic(d == -4); | 16776 | assert_or_panic(d == -4); |
| 16776 | } | 16777 | } |
| 16777 | 16778 | ||
| 16779 | void c_varargs_fn_ptr(int n, ...) { | ||
| 16780 | assert_or_panic(n == 2); | ||
| 16781 | va_list ap; | ||
| 16782 | va_start(ap, n); | ||
| 16783 | void (*fn_ptr)(int) = va_arg(ap, void (*)(int)); | ||
| 16784 | int arg = va_arg(ap, int); | ||
| 16785 | va_end(ap); | ||
| 16786 | fn_ptr(arg); | ||
| 16787 | } | ||
| 16788 | |||
| 16778 | void c_win64_varargs_u64_f64_u64_f64(uint64_t a, double b, uint64_t c, double d) { | 16789 | void c_win64_varargs_u64_f64_u64_f64(uint64_t a, double b, uint64_t c, double d) { |
| 16779 | assert_or_panic(a == UINT64_C(0x3ff0000000000000)); | 16790 | assert_or_panic(a == UINT64_C(0x3ff0000000000000)); |
| 16780 | assert_or_panic(b == 2.0); | 16791 | assert_or_panic(b == 2.0); |
test/c_abi/main.zig+11| ... | @@ -18009,6 +18009,17 @@ test "x86_64 sysv args" { | ... | @@ -18009,6 +18009,17 @@ test "x86_64 sysv args" { |
| 18009 | c_x86_64_sysv_uint_int_uint_int(1, -2, 3, -4); | 18009 | c_x86_64_sysv_uint_int_uint_int(1, -2, 3, -4); |
| 18010 | } | 18010 | } |
| 18011 | 18011 | ||
| 18012 | extern fn c_varargs_fn_ptr(n: c_int, ...) void; | ||
| 18013 | |||
| 18014 | fn zigVaCb(x: c_int) callconv(.c) void { | ||
| 18015 | expect(x == 123) catch @panic("test failure: zigVaCb"); | ||
| 18016 | } | ||
| 18017 | |||
| 18018 | test "function pointer through varargs" { | ||
| 18019 | // Bare function (not `&`), as in the original #12706 repro. | ||
| 18020 | c_varargs_fn_ptr(2, zigVaCb, @as(c_int, 123)); | ||
| 18021 | } | ||
| 18022 | |||
| 18012 | extern fn c_win64_varargs_u64_f64_u64_f64(...) void; | 18023 | extern fn c_win64_varargs_u64_f64_u64_f64(...) void; |
| 18013 | extern fn c_win64_varargs_f64_u64_f64_u64(...) void; | 18024 | extern fn c_win64_varargs_f64_u64_f64_u64(...) void; |
| 18014 | 18025 |
test/standalone/build.zig.zon-3| ... | @@ -126,9 +126,6 @@ | ... | @@ -126,9 +126,6 @@ |
| 126 | .c_embed_path = .{ | 126 | .c_embed_path = .{ |
| 127 | .path = "c_embed_path", | 127 | .path = "c_embed_path", |
| 128 | }, | 128 | }, |
| 129 | .issue_12706 = .{ | ||
| 130 | .path = "issue_12706", | ||
| 131 | }, | ||
| 132 | .coff_dwarf = .{ | 129 | .coff_dwarf = .{ |
| 133 | .path = "coff_dwarf", | 130 | .path = "coff_dwarf", |
| 134 | }, | 131 | }, |
test/standalone/issue_12706/build.zig deleted-30| ... | @@ -1,30 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | pub fn build(b: *std.Build) void { | ||
| 5 | const test_step = b.step("test", "Test it"); | ||
| 6 | b.default_step = test_step; | ||
| 7 | |||
| 8 | const optimize: std.builtin.Optimize = .debug; | ||
| 9 | const target = b.graph.host; | ||
| 10 | |||
| 11 | const exe = b.addExecutable(.{ | ||
| 12 | .name = "main", | ||
| 13 | .root_module = b.createModule(.{ | ||
| 14 | .root_source_file = b.path("main.zig"), | ||
| 15 | .optimize = optimize, | ||
| 16 | .target = target, | ||
| 17 | }), | ||
| 18 | }); | ||
| 19 | |||
| 20 | const c_sources = [_][]const u8{ | ||
| 21 | "test.c", | ||
| 22 | }; | ||
| 23 | exe.root_module.addCSourceFiles(.{ .files = &c_sources }); | ||
| 24 | exe.root_module.link_libc = true; | ||
| 25 | |||
| 26 | const run_cmd = b.addRunArtifact(exe); | ||
| 27 | run_cmd.expectExitCode(0); | ||
| 28 | run_cmd.skip_foreign_checks = true; | ||
| 29 | test_step.dependOn(&run_cmd.step); | ||
| 30 | } | ||
test/standalone/issue_12706/main.zig deleted-12| ... | @@ -1,12 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | extern fn testFnPtr(n: c_int, ...) void; | ||
| 3 | |||
| 4 | const val: c_int = 123; | ||
| 5 | |||
| 6 | fn func(a: c_int) callconv(.c) void { | ||
| 7 | std.debug.assert(a == val); | ||
| 8 | } | ||
| 9 | |||
| 10 | pub fn main() void { | ||
| 11 | testFnPtr(2, func, val); | ||
| 12 | } | ||
test/standalone/issue_12706/test.c deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | #include <stdarg.h> | ||
| 2 | |||
| 3 | void testFnPtr(int n, ...) { | ||
| 4 | va_list ap; | ||
| 5 | va_start(ap, n); | ||
| 6 | |||
| 7 | void (*fnPtr)(int) = va_arg(ap, void (*)(int)); | ||
| 8 | int arg = va_arg(ap, int); | ||
| 9 | fnPtr(arg); | ||
| 10 | va_end(ap); | ||
| 11 | } | ||
| \ No newline at end of file | |||