aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-12-06 18:52:39 -0500
committerGitHub <noreply@github.com>2022-12-06 18:52:39 -0500
commite7d28344fa3ee81d6ad7ca5ce1f83d50d8502118 (patch)
tree012b2556f2bda10ae663fab8efb235efe30e02f4 /test
parent817cf6a82efa7ed274371a28621bbf88a723d9b7 (diff)
parent20d86d9c63476b6312b87dc5b0e4aa4822eb7717 (diff)
downloadzig-e7d28344fa3ee81d6ad7ca5ce1f83d50d8502118.tar.gz
zig-e7d28344fa3ee81d6ad7ca5ce1f83d50d8502118.zip
Merge pull request #13560 from ziglang/wasi-bootstrap
Nuke the C++ implementation of Zig from orbit using WASI
Diffstat (limited to 'test')
-rw-r--r--test/link/wasm/archive/build.zig1
-rw-r--r--test/link/wasm/bss/build.zig1
-rw-r--r--test/link/wasm/producers/build.zig1
-rw-r--r--test/link/wasm/segments/build.zig1
-rw-r--r--test/link/wasm/stack_pointer/build.zig1
-rw-r--r--test/link/wasm/type/build.zig1
-rw-r--r--test/tests.zig10
-rw-r--r--test/translate_c.zig458
8 files changed, 221 insertions, 253 deletions
diff --git a/test/link/wasm/archive/build.zig b/test/link/wasm/archive/build.zig
index 5ac97c9cef..7efa88999a 100644
--- a/test/link/wasm/archive/build.zig
+++ b/test/link/wasm/archive/build.zig
@@ -13,7 +13,6 @@ pub fn build(b: *Builder) void {
lib.setBuildMode(mode);
lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
lib.use_llvm = false;
- lib.use_stage1 = false;
lib.use_lld = false;
lib.strip = false;
diff --git a/test/link/wasm/bss/build.zig b/test/link/wasm/bss/build.zig
index 0a8d652338..c9bc1aa106 100644
--- a/test/link/wasm/bss/build.zig
+++ b/test/link/wasm/bss/build.zig
@@ -11,7 +11,6 @@ pub fn build(b: *Builder) void {
lib.setBuildMode(mode);
lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
lib.use_llvm = false;
- lib.use_stage1 = false;
lib.use_lld = false;
lib.strip = false;
// to make sure the bss segment is emitted, we must import memory
diff --git a/test/link/wasm/producers/build.zig b/test/link/wasm/producers/build.zig
index 0f29c68968..7557b4fa41 100644
--- a/test/link/wasm/producers/build.zig
+++ b/test/link/wasm/producers/build.zig
@@ -12,7 +12,6 @@ pub fn build(b: *Builder) void {
lib.setBuildMode(mode);
lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
lib.use_llvm = false;
- lib.use_stage1 = false;
lib.use_lld = false;
lib.strip = false;
lib.install();
diff --git a/test/link/wasm/segments/build.zig b/test/link/wasm/segments/build.zig
index 06ca55300f..1b2cdf87ab 100644
--- a/test/link/wasm/segments/build.zig
+++ b/test/link/wasm/segments/build.zig
@@ -11,7 +11,6 @@ pub fn build(b: *Builder) void {
lib.setBuildMode(mode);
lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
lib.use_llvm = false;
- lib.use_stage1 = false;
lib.use_lld = false;
lib.strip = false;
lib.install();
diff --git a/test/link/wasm/stack_pointer/build.zig b/test/link/wasm/stack_pointer/build.zig
index 1f50a60d19..5b67c3caa3 100644
--- a/test/link/wasm/stack_pointer/build.zig
+++ b/test/link/wasm/stack_pointer/build.zig
@@ -11,7 +11,6 @@ pub fn build(b: *Builder) void {
lib.setBuildMode(mode);
lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
lib.use_llvm = false;
- lib.use_stage1 = false;
lib.use_lld = false;
lib.strip = false;
lib.stack_size = std.wasm.page_size * 2; // set an explicit stack size
diff --git a/test/link/wasm/type/build.zig b/test/link/wasm/type/build.zig
index 2c926eced3..fbae6dc741 100644
--- a/test/link/wasm/type/build.zig
+++ b/test/link/wasm/type/build.zig
@@ -11,7 +11,6 @@ pub fn build(b: *Builder) void {
lib.setBuildMode(mode);
lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
lib.use_llvm = false;
- lib.use_stage1 = false;
lib.use_lld = false;
lib.strip = false;
lib.install();
diff --git a/test/tests.zig b/test/tests.zig
index b738de86b0..0817a541d9 100644
--- a/test/tests.zig
+++ b/test/tests.zig
@@ -720,20 +720,18 @@ pub fn addPkgTests(
these_tests.addIncludePath("test");
if (test_target.backend) |backend| switch (backend) {
.stage1 => {
- these_tests.use_stage1 = true;
+ @panic("stage1 testing requested");
},
.stage2_llvm => {
- these_tests.use_stage1 = false;
these_tests.use_llvm = true;
},
.stage2_c => {
- these_tests.use_stage1 = false;
these_tests.use_llvm = false;
},
else => {
- these_tests.use_stage1 = false;
these_tests.use_llvm = false;
- // TODO: force self-hosted linkers to avoid LLD creeping in until the auto-select mechanism deems them worthy
+ // TODO: force self-hosted linkers to avoid LLD creeping in
+ // until the auto-select mechanism deems them worthy
these_tests.use_lld = false;
},
};
@@ -1355,8 +1353,6 @@ pub fn addCAbiTests(b: *build.Builder, skip_non_native: bool) *build.Step {
triple_prefix,
}));
- test_step.use_stage1 = false;
-
step.dependOn(&test_step.step);
}
return step;
diff --git a/test/translate_c.zig b/test/translate_c.zig
index 690b584d92..4ecb6835f5 100644
--- a/test/translate_c.zig
+++ b/test/translate_c.zig
@@ -549,27 +549,25 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\};
});
- if (builtin.zig_backend != .stage1) {
- cases.add("function prototype translated as optional",
- \\typedef void (*fnptr_ty)(void);
- \\typedef __attribute__((cdecl)) void (*fnptr_attr_ty)(void);
- \\struct foo {
- \\ __attribute__((cdecl)) void (*foo)(void);
- \\ void (*bar)(void);
- \\ fnptr_ty baz;
- \\ fnptr_attr_ty qux;
- \\};
- , &[_][]const u8{
- \\pub const fnptr_ty = ?*const fn () callconv(.C) void;
- \\pub const fnptr_attr_ty = ?*const fn () callconv(.C) void;
- \\pub const struct_foo = extern struct {
- \\ foo: ?*const fn () callconv(.C) void,
- \\ bar: ?*const fn () callconv(.C) void,
- \\ baz: fnptr_ty,
- \\ qux: fnptr_attr_ty,
- \\};
- });
- }
+ cases.add("function prototype translated as optional",
+ \\typedef void (*fnptr_ty)(void);
+ \\typedef __attribute__((cdecl)) void (*fnptr_attr_ty)(void);
+ \\struct foo {
+ \\ __attribute__((cdecl)) void (*foo)(void);
+ \\ void (*bar)(void);
+ \\ fnptr_ty baz;
+ \\ fnptr_attr_ty qux;
+ \\};
+ , &[_][]const u8{
+ \\pub const fnptr_ty = ?*const fn () callconv(.C) void;
+ \\pub const fnptr_attr_ty = ?*const fn () callconv(.C) void;
+ \\pub const struct_foo = extern struct {
+ \\ foo: ?*const fn () callconv(.C) void,
+ \\ bar: ?*const fn () callconv(.C) void,
+ \\ baz: fnptr_ty,
+ \\ qux: fnptr_attr_ty,
+ \\};
+ });
cases.add("function prototype with parenthesis",
\\void (f0) (void *L);
@@ -897,22 +895,20 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub const baz = c_int;
});
- if (builtin.zig_backend != .stage1) {
- cases.add("casting pointers to ints and ints to pointers",
- \\void foo(void);
- \\void bar(void) {
- \\ void *func_ptr = foo;
- \\ void (*typed_func_ptr)(void) = (void (*)(void)) (unsigned long) func_ptr;
- \\}
- , &[_][]const u8{
- \\pub extern fn foo() void;
- \\pub export fn bar() void {
- \\ var func_ptr: ?*anyopaque = @ptrCast(?*anyopaque, &foo);
- \\ var typed_func_ptr: ?*const fn () callconv(.C) void = @intToPtr(?*const fn () callconv(.C) void, @intCast(c_ulong, @ptrToInt(func_ptr)));
- \\ _ = @TypeOf(typed_func_ptr);
- \\}
- });
- }
+ cases.add("casting pointers to ints and ints to pointers",
+ \\void foo(void);
+ \\void bar(void) {
+ \\ void *func_ptr = foo;
+ \\ void (*typed_func_ptr)(void) = (void (*)(void)) (unsigned long) func_ptr;
+ \\}
+ , &[_][]const u8{
+ \\pub extern fn foo() void;
+ \\pub export fn bar() void {
+ \\ var func_ptr: ?*anyopaque = @ptrCast(?*anyopaque, &foo);
+ \\ var typed_func_ptr: ?*const fn () callconv(.C) void = @intToPtr(?*const fn () callconv(.C) void, @intCast(c_ulong, @ptrToInt(func_ptr)));
+ \\ _ = @TypeOf(typed_func_ptr);
+ \\}
+ });
cases.add("noreturn attribute",
\\void foo(void) __attribute__((noreturn));
@@ -972,21 +968,19 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\}
});
- if (builtin.zig_backend != .stage1) {
- cases.add("typedef of function in struct field",
- \\typedef void lws_callback_function(void);
- \\struct Foo {
- \\ void (*func)(void);
- \\ lws_callback_function *callback_http;
- \\};
- , &[_][]const u8{
- \\pub const lws_callback_function = fn () callconv(.C) void;
- \\pub const struct_Foo = extern struct {
- \\ func: ?*const fn () callconv(.C) void,
- \\ callback_http: ?*const lws_callback_function,
- \\};
- });
- }
+ cases.add("typedef of function in struct field",
+ \\typedef void lws_callback_function(void);
+ \\struct Foo {
+ \\ void (*func)(void);
+ \\ lws_callback_function *callback_http;
+ \\};
+ , &[_][]const u8{
+ \\pub const lws_callback_function = fn () callconv(.C) void;
+ \\pub const struct_Foo = extern struct {
+ \\ func: ?*const fn () callconv(.C) void,
+ \\ callback_http: ?*const lws_callback_function,
+ \\};
+ });
cases.add("pointer to struct demoted to opaque due to bit fields",
\\struct Foo {
@@ -1057,19 +1051,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub const Foo = struct_Foo;
});
- if (builtin.zig_backend != .stage1) {
- cases.add("self referential struct with function pointer",
- \\struct Foo {
- \\ void (*derp)(struct Foo *foo);
- \\};
- , &[_][]const u8{
- \\pub const struct_Foo = extern struct {
- \\ derp: ?*const fn ([*c]struct_Foo) callconv(.C) void,
- \\};
- ,
- \\pub const Foo = struct_Foo;
- });
- }
+ cases.add("self referential struct with function pointer",
+ \\struct Foo {
+ \\ void (*derp)(struct Foo *foo);
+ \\};
+ , &[_][]const u8{
+ \\pub const struct_Foo = extern struct {
+ \\ derp: ?*const fn ([*c]struct_Foo) callconv(.C) void,
+ \\};
+ ,
+ \\pub const Foo = struct_Foo;
+ });
cases.add("struct prototype used in func",
\\struct Foo;
@@ -1335,13 +1327,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub extern fn func(array: [*c]c_int) void;
});
- if (builtin.zig_backend != .stage1) {
- cases.add("__cdecl doesn't mess up function pointers",
- \\void foo(void (__cdecl *fn_ptr)(void));
- , &[_][]const u8{
- \\pub extern fn foo(fn_ptr: ?*const fn () callconv(.C) void) void;
- });
- }
+ cases.add("__cdecl doesn't mess up function pointers",
+ \\void foo(void (__cdecl *fn_ptr)(void));
+ , &[_][]const u8{
+ \\pub extern fn foo(fn_ptr: ?*const fn () callconv(.C) void) void;
+ });
cases.add("void cast",
\\void foo() {
@@ -1764,15 +1754,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub extern var my_enum: enum_enum_ty;
});
- if (builtin.zig_backend != .stage1) {
- cases.add("Parameterless function pointers",
- \\typedef void (*fn0)();
- \\typedef void (*fn1)(char);
- , &[_][]const u8{
- \\pub const fn0 = ?*const fn (...) callconv(.C) void;
- \\pub const fn1 = ?*const fn (u8) callconv(.C) void;
- });
- }
+ cases.add("Parameterless function pointers",
+ \\typedef void (*fn0)();
+ \\typedef void (*fn1)(char);
+ , &[_][]const u8{
+ \\pub const fn0 = ?*const fn (...) callconv(.C) void;
+ \\pub const fn1 = ?*const fn (u8) callconv(.C) void;
+ });
cases.addWithTarget("Calling convention", .{
.cpu_arch = .x86,
@@ -1972,64 +1960,60 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub const SDL_INIT_VIDEO = @as(c_ulonglong, 0x00000020);
});
- if (builtin.zig_backend != .stage1) {
- cases.add("generate inline func for #define global extern fn",
- \\extern void (*fn_ptr)(void);
- \\#define foo fn_ptr
- \\
- \\extern char (*fn_ptr2)(int, float);
- \\#define bar fn_ptr2
- , &[_][]const u8{
- \\pub extern var fn_ptr: ?*const fn () callconv(.C) void;
- ,
- \\pub inline fn foo() void {
- \\ return fn_ptr.?();
- \\}
- ,
- \\pub extern var fn_ptr2: ?*const fn (c_int, f32) callconv(.C) u8;
- ,
- \\pub inline fn bar(arg_1: c_int, arg_2: f32) u8 {
- \\ return fn_ptr2.?(arg_1, arg_2);
- \\}
- });
- }
+ cases.add("generate inline func for #define global extern fn",
+ \\extern void (*fn_ptr)(void);
+ \\#define foo fn_ptr
+ \\
+ \\extern char (*fn_ptr2)(int, float);
+ \\#define bar fn_ptr2
+ , &[_][]const u8{
+ \\pub extern var fn_ptr: ?*const fn () callconv(.C) void;
+ ,
+ \\pub inline fn foo() void {
+ \\ return fn_ptr.?();
+ \\}
+ ,
+ \\pub extern var fn_ptr2: ?*const fn (c_int, f32) callconv(.C) u8;
+ ,
+ \\pub inline fn bar(arg_1: c_int, arg_2: f32) u8 {
+ \\ return fn_ptr2.?(arg_1, arg_2);
+ \\}
+ });
- if (builtin.zig_backend != .stage1) {
- cases.add("macros with field targets",
- \\typedef unsigned int GLbitfield;
- \\typedef void (*PFNGLCLEARPROC) (GLbitfield mask);
- \\typedef void(*OpenGLProc)(void);
- \\union OpenGLProcs {
- \\ OpenGLProc ptr[1];
- \\ struct {
- \\ PFNGLCLEARPROC Clear;
- \\ } gl;
- \\};
- \\extern union OpenGLProcs glProcs;
- \\#define glClearUnion glProcs.gl.Clear
- \\#define glClearPFN PFNGLCLEARPROC
- , &[_][]const u8{
- \\pub const GLbitfield = c_uint;
- \\pub const PFNGLCLEARPROC = ?*const fn (GLbitfield) callconv(.C) void;
- \\pub const OpenGLProc = ?*const fn () callconv(.C) void;
- \\const struct_unnamed_1 = extern struct {
- \\ Clear: PFNGLCLEARPROC,
- \\};
- \\pub const union_OpenGLProcs = extern union {
- \\ ptr: [1]OpenGLProc,
- \\ gl: struct_unnamed_1,
- \\};
- \\pub extern var glProcs: union_OpenGLProcs;
- ,
- \\pub const glClearPFN = PFNGLCLEARPROC;
- ,
- \\pub inline fn glClearUnion(arg_2: GLbitfield) void {
- \\ return glProcs.gl.Clear.?(arg_2);
- \\}
- ,
- \\pub const OpenGLProcs = union_OpenGLProcs;
- });
- }
+ cases.add("macros with field targets",
+ \\typedef unsigned int GLbitfield;
+ \\typedef void (*PFNGLCLEARPROC) (GLbitfield mask);
+ \\typedef void(*OpenGLProc)(void);
+ \\union OpenGLProcs {
+ \\ OpenGLProc ptr[1];
+ \\ struct {
+ \\ PFNGLCLEARPROC Clear;
+ \\ } gl;
+ \\};
+ \\extern union OpenGLProcs glProcs;
+ \\#define glClearUnion glProcs.gl.Clear
+ \\#define glClearPFN PFNGLCLEARPROC
+ , &[_][]const u8{
+ \\pub const GLbitfield = c_uint;
+ \\pub const PFNGLCLEARPROC = ?*const fn (GLbitfield) callconv(.C) void;
+ \\pub const OpenGLProc = ?*const fn () callconv(.C) void;
+ \\const struct_unnamed_1 = extern struct {
+ \\ Clear: PFNGLCLEARPROC,
+ \\};
+ \\pub const union_OpenGLProcs = extern union {
+ \\ ptr: [1]OpenGLProc,
+ \\ gl: struct_unnamed_1,
+ \\};
+ \\pub extern var glProcs: union_OpenGLProcs;
+ ,
+ \\pub const glClearPFN = PFNGLCLEARPROC;
+ ,
+ \\pub inline fn glClearUnion(arg_2: GLbitfield) void {
+ \\ return glProcs.gl.Clear.?(arg_2);
+ \\}
+ ,
+ \\pub const OpenGLProcs = union_OpenGLProcs;
+ });
cases.add("macro pointer cast",
\\#define NRF_GPIO_BASE 0
@@ -2936,37 +2920,35 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\}
});
- if (builtin.zig_backend != .stage1) {
- cases.add("deref function pointer",
- \\void foo(void) {}
- \\int baz(void) { return 0; }
- \\void bar(void) {
- \\ void(*f)(void) = foo;
- \\ int(*b)(void) = baz;
- \\ f();
- \\ (*(f))();
- \\ foo();
- \\ b();
- \\ (*(b))();
- \\ baz();
- \\}
- , &[_][]const u8{
- \\pub export fn foo() void {}
- \\pub export fn baz() c_int {
- \\ return 0;
- \\}
- \\pub export fn bar() void {
- \\ var f: ?*const fn () callconv(.C) void = &foo;
- \\ var b: ?*const fn () callconv(.C) c_int = &baz;
- \\ f.?();
- \\ f.?();
- \\ foo();
- \\ _ = b.?();
- \\ _ = b.?();
- \\ _ = baz();
- \\}
- });
- }
+ cases.add("deref function pointer",
+ \\void foo(void) {}
+ \\int baz(void) { return 0; }
+ \\void bar(void) {
+ \\ void(*f)(void) = foo;
+ \\ int(*b)(void) = baz;
+ \\ f();
+ \\ (*(f))();
+ \\ foo();
+ \\ b();
+ \\ (*(b))();
+ \\ baz();
+ \\}
+ , &[_][]const u8{
+ \\pub export fn foo() void {}
+ \\pub export fn baz() c_int {
+ \\ return 0;
+ \\}
+ \\pub export fn bar() void {
+ \\ var f: ?*const fn () callconv(.C) void = &foo;
+ \\ var b: ?*const fn () callconv(.C) c_int = &baz;
+ \\ f.?();
+ \\ f.?();
+ \\ foo();
+ \\ _ = b.?();
+ \\ _ = b.?();
+ \\ _ = baz();
+ \\}
+ });
cases.add("pre increment/decrement",
\\void foo(void) {
@@ -3241,77 +3223,73 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\}
});
- if (builtin.zig_backend != .stage1) {
- cases.add("implicit casts",
- \\#include <stdbool.h>
- \\
- \\void fn_int(int x);
- \\void fn_f32(float x);
- \\void fn_f64(double x);
- \\void fn_char(char x);
- \\void fn_bool(bool x);
- \\void fn_ptr(void *x);
- \\
- \\void call() {
- \\ fn_int(3.0f);
- \\ fn_int(3.0);
- \\ fn_int('ABCD');
- \\ fn_f32(3);
- \\ fn_f64(3);
- \\ fn_char('3');
- \\ fn_char('\x1');
- \\ fn_char(0);
- \\ fn_f32(3.0f);
- \\ fn_f64(3.0);
- \\ fn_bool(123);
- \\ fn_bool(0);
- \\ fn_bool(&fn_int);
- \\ fn_int((int)&fn_int);
- \\ fn_ptr((void *)42);
- \\}
- , &[_][]const u8{
- \\pub extern fn fn_int(x: c_int) void;
- \\pub extern fn fn_f32(x: f32) void;
- \\pub extern fn fn_f64(x: f64) void;
- \\pub extern fn fn_char(x: u8) void;
- \\pub extern fn fn_bool(x: bool) void;
- \\pub extern fn fn_ptr(x: ?*anyopaque) void;
- \\pub export fn call() void {
- \\ fn_int(@floatToInt(c_int, 3.0));
- \\ fn_int(@floatToInt(c_int, 3.0));
- \\ fn_int(@as(c_int, 1094861636));
- \\ fn_f32(@intToFloat(f32, @as(c_int, 3)));
- \\ fn_f64(@intToFloat(f64, @as(c_int, 3)));
- \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '3'))));
- \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '\x01'))));
- \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, 0))));
- \\ fn_f32(3.0);
- \\ fn_f64(3.0);
- \\ fn_bool(@as(c_int, 123) != 0);
- \\ fn_bool(@as(c_int, 0) != 0);
- \\ fn_bool(@ptrToInt(&fn_int) != 0);
- \\ fn_int(@intCast(c_int, @ptrToInt(&fn_int)));
- \\ fn_ptr(@intToPtr(?*anyopaque, @as(c_int, 42)));
- \\}
- });
- }
-
- if (builtin.zig_backend != .stage1) {
- cases.add("function call",
- \\static void bar(void) { }
- \\void foo(int *(baz)(void)) {
- \\ bar();
- \\ baz();
- \\}
- , &[_][]const u8{
- \\pub fn bar() callconv(.C) void {}
- \\pub export fn foo(arg_baz: ?*const fn () callconv(.C) [*c]c_int) void {
- \\ var baz = arg_baz;
- \\ bar();
- \\ _ = baz.?();
- \\}
- });
- }
+ cases.add("implicit casts",
+ \\#include <stdbool.h>
+ \\
+ \\void fn_int(int x);
+ \\void fn_f32(float x);
+ \\void fn_f64(double x);
+ \\void fn_char(char x);
+ \\void fn_bool(bool x);
+ \\void fn_ptr(void *x);
+ \\
+ \\void call() {
+ \\ fn_int(3.0f);
+ \\ fn_int(3.0);
+ \\ fn_int('ABCD');
+ \\ fn_f32(3);
+ \\ fn_f64(3);
+ \\ fn_char('3');
+ \\ fn_char('\x1');
+ \\ fn_char(0);
+ \\ fn_f32(3.0f);
+ \\ fn_f64(3.0);
+ \\ fn_bool(123);
+ \\ fn_bool(0);
+ \\ fn_bool(&fn_int);
+ \\ fn_int((int)&fn_int);
+ \\ fn_ptr((void *)42);
+ \\}
+ , &[_][]const u8{
+ \\pub extern fn fn_int(x: c_int) void;
+ \\pub extern fn fn_f32(x: f32) void;
+ \\pub extern fn fn_f64(x: f64) void;
+ \\pub extern fn fn_char(x: u8) void;
+ \\pub extern fn fn_bool(x: bool) void;
+ \\pub extern fn fn_ptr(x: ?*anyopaque) void;
+ \\pub export fn call() void {
+ \\ fn_int(@floatToInt(c_int, 3.0));
+ \\ fn_int(@floatToInt(c_int, 3.0));
+ \\ fn_int(@as(c_int, 1094861636));
+ \\ fn_f32(@intToFloat(f32, @as(c_int, 3)));
+ \\ fn_f64(@intToFloat(f64, @as(c_int, 3)));
+ \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '3'))));
+ \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '\x01'))));
+ \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, 0))));
+ \\ fn_f32(3.0);
+ \\ fn_f64(3.0);
+ \\ fn_bool(@as(c_int, 123) != 0);
+ \\ fn_bool(@as(c_int, 0) != 0);
+ \\ fn_bool(@ptrToInt(&fn_int) != 0);
+ \\ fn_int(@intCast(c_int, @ptrToInt(&fn_int)));
+ \\ fn_ptr(@intToPtr(?*anyopaque, @as(c_int, 42)));
+ \\}
+ });
+
+ cases.add("function call",
+ \\static void bar(void) { }
+ \\void foo(int *(baz)(void)) {
+ \\ bar();
+ \\ baz();
+ \\}
+ , &[_][]const u8{
+ \\pub fn bar() callconv(.C) void {}
+ \\pub export fn foo(arg_baz: ?*const fn () callconv(.C) [*c]c_int) void {
+ \\ var baz = arg_baz;
+ \\ bar();
+ \\ _ = baz.?();
+ \\}
+ });
cases.add("macro defines string literal with octal",
\\#define FOO "aoeu\023 derp"