| ... | @@ -549,27 +549,25 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -549,27 +549,25 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 549 | \\}; | 549 | \\}; |
| 550 | }); | 550 | }); |
| 551 | | 551 | |
| 552 | if (builtin.zig_backend != .stage1) { | 552 | cases.add("function prototype translated as optional", |
| 553 | cases.add("function prototype translated as optional", | 553 | \\typedef void (*fnptr_ty)(void); |
| 554 | \\typedef void (*fnptr_ty)(void); | 554 | \\typedef __attribute__((cdecl)) void (*fnptr_attr_ty)(void); |
| 555 | \\typedef __attribute__((cdecl)) void (*fnptr_attr_ty)(void); | 555 | \\struct foo { |
| 556 | \\struct foo { | 556 | \\ __attribute__((cdecl)) void (*foo)(void); |
| 557 | \\ __attribute__((cdecl)) void (*foo)(void); | 557 | \\ void (*bar)(void); |
| 558 | \\ void (*bar)(void); | 558 | \\ fnptr_ty baz; |
| 559 | \\ fnptr_ty baz; | 559 | \\ fnptr_attr_ty qux; |
| 560 | \\ fnptr_attr_ty qux; | 560 | \\}; |
| 561 | \\}; | 561 | , &[_][]const u8{ |
| 562 | , &[_][]const u8{ | 562 | \\pub const fnptr_ty = ?*const fn () callconv(.C) void; |
| 563 | \\pub const fnptr_ty = ?*const fn () callconv(.C) void; | 563 | \\pub const fnptr_attr_ty = ?*const fn () callconv(.C) void; |
| 564 | \\pub const fnptr_attr_ty = ?*const fn () callconv(.C) void; | 564 | \\pub const struct_foo = extern struct { |
| 565 | \\pub const struct_foo = extern struct { | 565 | \\ foo: ?*const fn () callconv(.C) void, |
| 566 | \\ foo: ?*const fn () callconv(.C) void, | 566 | \\ bar: ?*const fn () callconv(.C) void, |
| 567 | \\ bar: ?*const fn () callconv(.C) void, | 567 | \\ baz: fnptr_ty, |
| 568 | \\ baz: fnptr_ty, | 568 | \\ qux: fnptr_attr_ty, |
| 569 | \\ qux: fnptr_attr_ty, | 569 | \\}; |
| 570 | \\}; | 570 | }); |
| 571 | }); | | |
| 572 | } | | |
| 573 | | 571 | |
| 574 | cases.add("function prototype with parenthesis", | 572 | cases.add("function prototype with parenthesis", |
| 575 | \\void (f0) (void *L); | 573 | \\void (f0) (void *L); |
| ... | @@ -897,22 +895,20 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -897,22 +895,20 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 897 | \\pub const baz = c_int; | 895 | \\pub const baz = c_int; |
| 898 | }); | 896 | }); |
| 899 | | 897 | |
| 900 | if (builtin.zig_backend != .stage1) { | 898 | cases.add("casting pointers to ints and ints to pointers", |
| 901 | cases.add("casting pointers to ints and ints to pointers", | 899 | \\void foo(void); |
| 902 | \\void foo(void); | 900 | \\void bar(void) { |
| 903 | \\void bar(void) { | 901 | \\ void *func_ptr = foo; |
| 904 | \\ void *func_ptr = foo; | 902 | \\ void (*typed_func_ptr)(void) = (void (*)(void)) (unsigned long) func_ptr; |
| 905 | \\ void (*typed_func_ptr)(void) = (void (*)(void)) (unsigned long) func_ptr; | 903 | \\} |
| 906 | \\} | 904 | , &[_][]const u8{ |
| 907 | , &[_][]const u8{ | 905 | \\pub extern fn foo() void; |
| 908 | \\pub extern fn foo() void; | 906 | \\pub export fn bar() void { |
| 909 | \\pub export fn bar() void { | 907 | \\ var func_ptr: ?*anyopaque = @ptrCast(?*anyopaque, &foo); |
| 910 | \\ var func_ptr: ?*anyopaque = @ptrCast(?*anyopaque, &foo); | 908 | \\ var typed_func_ptr: ?*const fn () callconv(.C) void = @intToPtr(?*const fn () callconv(.C) void, @intCast(c_ulong, @ptrToInt(func_ptr))); |
| 911 | \\ var typed_func_ptr: ?*const fn () callconv(.C) void = @intToPtr(?*const fn () callconv(.C) void, @intCast(c_ulong, @ptrToInt(func_ptr))); | 909 | \\ _ = @TypeOf(typed_func_ptr); |
| 912 | \\ _ = @TypeOf(typed_func_ptr); | 910 | \\} |
| 913 | \\} | 911 | }); |
| 914 | }); | | |
| 915 | } | | |
| 916 | | 912 | |
| 917 | cases.add("noreturn attribute", | 913 | cases.add("noreturn attribute", |
| 918 | \\void foo(void) __attribute__((noreturn)); | 914 | \\void foo(void) __attribute__((noreturn)); |
| ... | @@ -972,21 +968,19 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -972,21 +968,19 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 972 | \\} | 968 | \\} |
| 973 | }); | 969 | }); |
| 974 | | 970 | |
| 975 | if (builtin.zig_backend != .stage1) { | 971 | cases.add("typedef of function in struct field", |
| 976 | cases.add("typedef of function in struct field", | 972 | \\typedef void lws_callback_function(void); |
| 977 | \\typedef void lws_callback_function(void); | 973 | \\struct Foo { |
| 978 | \\struct Foo { | 974 | \\ void (*func)(void); |
| 979 | \\ void (*func)(void); | 975 | \\ lws_callback_function *callback_http; |
| 980 | \\ lws_callback_function *callback_http; | 976 | \\}; |
| 981 | \\}; | 977 | , &[_][]const u8{ |
| 982 | , &[_][]const u8{ | 978 | \\pub const lws_callback_function = fn () callconv(.C) void; |
| 983 | \\pub const lws_callback_function = fn () callconv(.C) void; | 979 | \\pub const struct_Foo = extern struct { |
| 984 | \\pub const struct_Foo = extern struct { | 980 | \\ func: ?*const fn () callconv(.C) void, |
| 985 | \\ func: ?*const fn () callconv(.C) void, | 981 | \\ callback_http: ?*const lws_callback_function, |
| 986 | \\ callback_http: ?*const lws_callback_function, | 982 | \\}; |
| 987 | \\}; | 983 | }); |
| 988 | }); | | |
| 989 | } | | |
| 990 | | 984 | |
| 991 | cases.add("pointer to struct demoted to opaque due to bit fields", | 985 | cases.add("pointer to struct demoted to opaque due to bit fields", |
| 992 | \\struct Foo { | 986 | \\struct Foo { |
| ... | @@ -1057,19 +1051,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1057,19 +1051,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1057 | \\pub const Foo = struct_Foo; | 1051 | \\pub const Foo = struct_Foo; |
| 1058 | }); | 1052 | }); |
| 1059 | | 1053 | |
| 1060 | if (builtin.zig_backend != .stage1) { | 1054 | cases.add("self referential struct with function pointer", |
| 1061 | cases.add("self referential struct with function pointer", | 1055 | \\struct Foo { |
| 1062 | \\struct Foo { | 1056 | \\ void (*derp)(struct Foo *foo); |
| 1063 | \\ void (*derp)(struct Foo *foo); | 1057 | \\}; |
| 1064 | \\}; | 1058 | , &[_][]const u8{ |
| 1065 | , &[_][]const u8{ | 1059 | \\pub const struct_Foo = extern struct { |
| 1066 | \\pub const struct_Foo = extern struct { | 1060 | \\ derp: ?*const fn ([*c]struct_Foo) callconv(.C) void, |
| 1067 | \\ derp: ?*const fn ([*c]struct_Foo) callconv(.C) void, | 1061 | \\}; |
| 1068 | \\}; | 1062 | , |
| 1069 | , | 1063 | \\pub const Foo = struct_Foo; |
| 1070 | \\pub const Foo = struct_Foo; | 1064 | }); |
| 1071 | }); | | |
| 1072 | } | | |
| 1073 | | 1065 | |
| 1074 | cases.add("struct prototype used in func", | 1066 | cases.add("struct prototype used in func", |
| 1075 | \\struct Foo; | 1067 | \\struct Foo; |
| ... | @@ -1335,13 +1327,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1335,13 +1327,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1335 | \\pub extern fn func(array: [*c]c_int) void; | 1327 | \\pub extern fn func(array: [*c]c_int) void; |
| 1336 | }); | 1328 | }); |
| 1337 | | 1329 | |
| 1338 | if (builtin.zig_backend != .stage1) { | 1330 | cases.add("__cdecl doesn't mess up function pointers", |
| 1339 | cases.add("__cdecl doesn't mess up function pointers", | 1331 | \\void foo(void (__cdecl *fn_ptr)(void)); |
| 1340 | \\void foo(void (__cdecl *fn_ptr)(void)); | 1332 | , &[_][]const u8{ |
| 1341 | , &[_][]const u8{ | 1333 | \\pub extern fn foo(fn_ptr: ?*const fn () callconv(.C) void) void; |
| 1342 | \\pub extern fn foo(fn_ptr: ?*const fn () callconv(.C) void) void; | 1334 | }); |
| 1343 | }); | | |
| 1344 | } | | |
| 1345 | | 1335 | |
| 1346 | cases.add("void cast", | 1336 | cases.add("void cast", |
| 1347 | \\void foo() { | 1337 | \\void foo() { |
| ... | @@ -1764,15 +1754,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1764,15 +1754,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1764 | \\pub extern var my_enum: enum_enum_ty; | 1754 | \\pub extern var my_enum: enum_enum_ty; |
| 1765 | }); | 1755 | }); |
| 1766 | | 1756 | |
| 1767 | if (builtin.zig_backend != .stage1) { | 1757 | cases.add("Parameterless function pointers", |
| 1768 | cases.add("Parameterless function pointers", | 1758 | \\typedef void (*fn0)(); |
| 1769 | \\typedef void (*fn0)(); | 1759 | \\typedef void (*fn1)(char); |
| 1770 | \\typedef void (*fn1)(char); | 1760 | , &[_][]const u8{ |
| 1771 | , &[_][]const u8{ | 1761 | \\pub const fn0 = ?*const fn (...) callconv(.C) void; |
| 1772 | \\pub const fn0 = ?*const fn (...) callconv(.C) void; | 1762 | \\pub const fn1 = ?*const fn (u8) callconv(.C) void; |
| 1773 | \\pub const fn1 = ?*const fn (u8) callconv(.C) void; | 1763 | }); |
| 1774 | }); | | |
| 1775 | } | | |
| 1776 | | 1764 | |
| 1777 | cases.addWithTarget("Calling convention", .{ | 1765 | cases.addWithTarget("Calling convention", .{ |
| 1778 | .cpu_arch = .x86, | 1766 | .cpu_arch = .x86, |
| ... | @@ -1972,64 +1960,60 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1972,64 +1960,60 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1972 | \\pub const SDL_INIT_VIDEO = @as(c_ulonglong, 0x00000020); | 1960 | \\pub const SDL_INIT_VIDEO = @as(c_ulonglong, 0x00000020); |
| 1973 | }); | 1961 | }); |
| 1974 | | 1962 | |
| 1975 | if (builtin.zig_backend != .stage1) { | 1963 | cases.add("generate inline func for #define global extern fn", |
| 1976 | cases.add("generate inline func for #define global extern fn", | 1964 | \\extern void (*fn_ptr)(void); |
| 1977 | \\extern void (*fn_ptr)(void); | 1965 | \\#define foo fn_ptr |
| 1978 | \\#define foo fn_ptr | 1966 | \\ |
| 1979 | \\ | 1967 | \\extern char (*fn_ptr2)(int, float); |
| 1980 | \\extern char (*fn_ptr2)(int, float); | 1968 | \\#define bar fn_ptr2 |
| 1981 | \\#define bar fn_ptr2 | 1969 | , &[_][]const u8{ |
| 1982 | , &[_][]const u8{ | 1970 | \\pub extern var fn_ptr: ?*const fn () callconv(.C) void; |
| 1983 | \\pub extern var fn_ptr: ?*const fn () callconv(.C) void; | 1971 | , |
| 1984 | , | 1972 | \\pub inline fn foo() void { |
| 1985 | \\pub inline fn foo() void { | 1973 | \\ return fn_ptr.?(); |
| 1986 | \\ return fn_ptr.?(); | 1974 | \\} |
| 1987 | \\} | 1975 | , |
| 1988 | , | 1976 | \\pub extern var fn_ptr2: ?*const fn (c_int, f32) callconv(.C) u8; |
| 1989 | \\pub extern var fn_ptr2: ?*const fn (c_int, f32) callconv(.C) u8; | 1977 | , |
| 1990 | , | 1978 | \\pub inline fn bar(arg_1: c_int, arg_2: f32) u8 { |
| 1991 | \\pub inline fn bar(arg_1: c_int, arg_2: f32) u8 { | 1979 | \\ return fn_ptr2.?(arg_1, arg_2); |
| 1992 | \\ return fn_ptr2.?(arg_1, arg_2); | 1980 | \\} |
| 1993 | \\} | 1981 | }); |
| 1994 | }); | | |
| 1995 | } | | |
| 1996 | | 1982 | |
| 1997 | if (builtin.zig_backend != .stage1) { | 1983 | cases.add("macros with field targets", |
| 1998 | cases.add("macros with field targets", | 1984 | \\typedef unsigned int GLbitfield; |
| 1999 | \\typedef unsigned int GLbitfield; | 1985 | \\typedef void (*PFNGLCLEARPROC) (GLbitfield mask); |
| 2000 | \\typedef void (*PFNGLCLEARPROC) (GLbitfield mask); | 1986 | \\typedef void(*OpenGLProc)(void); |
| 2001 | \\typedef void(*OpenGLProc)(void); | 1987 | \\union OpenGLProcs { |
| 2002 | \\union OpenGLProcs { | 1988 | \\ OpenGLProc ptr[1]; |
| 2003 | \\ OpenGLProc ptr[1]; | 1989 | \\ struct { |
| 2004 | \\ struct { | 1990 | \\ PFNGLCLEARPROC Clear; |
| 2005 | \\ PFNGLCLEARPROC Clear; | 1991 | \\ } gl; |
| 2006 | \\ } gl; | 1992 | \\}; |
| 2007 | \\}; | 1993 | \\extern union OpenGLProcs glProcs; |
| 2008 | \\extern union OpenGLProcs glProcs; | 1994 | \\#define glClearUnion glProcs.gl.Clear |
| 2009 | \\#define glClearUnion glProcs.gl.Clear | 1995 | \\#define glClearPFN PFNGLCLEARPROC |
| 2010 | \\#define glClearPFN PFNGLCLEARPROC | 1996 | , &[_][]const u8{ |
| 2011 | , &[_][]const u8{ | 1997 | \\pub const GLbitfield = c_uint; |
| 2012 | \\pub const GLbitfield = c_uint; | 1998 | \\pub const PFNGLCLEARPROC = ?*const fn (GLbitfield) callconv(.C) void; |
| 2013 | \\pub const PFNGLCLEARPROC = ?*const fn (GLbitfield) callconv(.C) void; | 1999 | \\pub const OpenGLProc = ?*const fn () callconv(.C) void; |
| 2014 | \\pub const OpenGLProc = ?*const fn () callconv(.C) void; | 2000 | \\const struct_unnamed_1 = extern struct { |
| 2015 | \\const struct_unnamed_1 = extern struct { | 2001 | \\ Clear: PFNGLCLEARPROC, |
| 2016 | \\ Clear: PFNGLCLEARPROC, | 2002 | \\}; |
| 2017 | \\}; | 2003 | \\pub const union_OpenGLProcs = extern union { |
| 2018 | \\pub const union_OpenGLProcs = extern union { | 2004 | \\ ptr: [1]OpenGLProc, |
| 2019 | \\ ptr: [1]OpenGLProc, | 2005 | \\ gl: struct_unnamed_1, |
| 2020 | \\ gl: struct_unnamed_1, | 2006 | \\}; |
| 2021 | \\}; | 2007 | \\pub extern var glProcs: union_OpenGLProcs; |
| 2022 | \\pub extern var glProcs: union_OpenGLProcs; | 2008 | , |
| 2023 | , | 2009 | \\pub const glClearPFN = PFNGLCLEARPROC; |
| 2024 | \\pub const glClearPFN = PFNGLCLEARPROC; | 2010 | , |
| 2025 | , | 2011 | \\pub inline fn glClearUnion(arg_2: GLbitfield) void { |
| 2026 | \\pub inline fn glClearUnion(arg_2: GLbitfield) void { | 2012 | \\ return glProcs.gl.Clear.?(arg_2); |
| 2027 | \\ return glProcs.gl.Clear.?(arg_2); | 2013 | \\} |
| 2028 | \\} | 2014 | , |
| 2029 | , | 2015 | \\pub const OpenGLProcs = union_OpenGLProcs; |
| 2030 | \\pub const OpenGLProcs = union_OpenGLProcs; | 2016 | }); |
| 2031 | }); | | |
| 2032 | } | | |
| 2033 | | 2017 | |
| 2034 | cases.add("macro pointer cast", | 2018 | cases.add("macro pointer cast", |
| 2035 | \\#define NRF_GPIO_BASE 0 | 2019 | \\#define NRF_GPIO_BASE 0 |
| ... | @@ -2936,37 +2920,35 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2936,37 +2920,35 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2936 | \\} | 2920 | \\} |
| 2937 | }); | 2921 | }); |
| 2938 | | 2922 | |
| 2939 | if (builtin.zig_backend != .stage1) { | 2923 | cases.add("deref function pointer", |
| 2940 | cases.add("deref function pointer", | 2924 | \\void foo(void) {} |
| 2941 | \\void foo(void) {} | 2925 | \\int baz(void) { return 0; } |
| 2942 | \\int baz(void) { return 0; } | 2926 | \\void bar(void) { |
| 2943 | \\void bar(void) { | 2927 | \\ void(*f)(void) = foo; |
| 2944 | \\ void(*f)(void) = foo; | 2928 | \\ int(*b)(void) = baz; |
| 2945 | \\ int(*b)(void) = baz; | 2929 | \\ f(); |
| 2946 | \\ f(); | 2930 | \\ (*(f))(); |
| 2947 | \\ (*(f))(); | 2931 | \\ foo(); |
| 2948 | \\ foo(); | 2932 | \\ b(); |
| 2949 | \\ b(); | 2933 | \\ (*(b))(); |
| 2950 | \\ (*(b))(); | 2934 | \\ baz(); |
| 2951 | \\ baz(); | 2935 | \\} |
| 2952 | \\} | 2936 | , &[_][]const u8{ |
| 2953 | , &[_][]const u8{ | 2937 | \\pub export fn foo() void {} |
| 2954 | \\pub export fn foo() void {} | 2938 | \\pub export fn baz() c_int { |
| 2955 | \\pub export fn baz() c_int { | 2939 | \\ return 0; |
| 2956 | \\ return 0; | 2940 | \\} |
| 2957 | \\} | 2941 | \\pub export fn bar() void { |
| 2958 | \\pub export fn bar() void { | 2942 | \\ var f: ?*const fn () callconv(.C) void = &foo; |
| 2959 | \\ var f: ?*const fn () callconv(.C) void = &foo; | 2943 | \\ var b: ?*const fn () callconv(.C) c_int = &baz; |
| 2960 | \\ var b: ?*const fn () callconv(.C) c_int = &baz; | 2944 | \\ f.?(); |
| 2961 | \\ f.?(); | 2945 | \\ f.?(); |
| 2962 | \\ f.?(); | 2946 | \\ foo(); |
| 2963 | \\ foo(); | 2947 | \\ _ = b.?(); |
| 2964 | \\ _ = b.?(); | 2948 | \\ _ = b.?(); |
| 2965 | \\ _ = b.?(); | 2949 | \\ _ = baz(); |
| 2966 | \\ _ = baz(); | 2950 | \\} |
| 2967 | \\} | 2951 | }); |
| 2968 | }); | | |
| 2969 | } | | |
| 2970 | | 2952 | |
| 2971 | cases.add("pre increment/decrement", | 2953 | cases.add("pre increment/decrement", |
| 2972 | \\void foo(void) { | 2954 | \\void foo(void) { |
| ... | @@ -3241,77 +3223,73 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3241,77 +3223,73 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3241 | \\} | 3223 | \\} |
| 3242 | }); | 3224 | }); |
| 3243 | | 3225 | |
| 3244 | if (builtin.zig_backend != .stage1) { | 3226 | cases.add("implicit casts", |
| 3245 | cases.add("implicit casts", | 3227 | \\#include <stdbool.h> |
| 3246 | \\#include <stdbool.h> | 3228 | \\ |
| 3247 | \\ | 3229 | \\void fn_int(int x); |
| 3248 | \\void fn_int(int x); | 3230 | \\void fn_f32(float x); |
| 3249 | \\void fn_f32(float x); | 3231 | \\void fn_f64(double x); |
| 3250 | \\void fn_f64(double x); | 3232 | \\void fn_char(char x); |
| 3251 | \\void fn_char(char x); | 3233 | \\void fn_bool(bool x); |
| 3252 | \\void fn_bool(bool x); | 3234 | \\void fn_ptr(void *x); |
| 3253 | \\void fn_ptr(void *x); | 3235 | \\ |
| 3254 | \\ | 3236 | \\void call() { |
| 3255 | \\void call() { | 3237 | \\ fn_int(3.0f); |
| 3256 | \\ fn_int(3.0f); | 3238 | \\ fn_int(3.0); |
| 3257 | \\ fn_int(3.0); | 3239 | \\ fn_int('ABCD'); |
| 3258 | \\ fn_int('ABCD'); | 3240 | \\ fn_f32(3); |
| 3259 | \\ fn_f32(3); | 3241 | \\ fn_f64(3); |
| 3260 | \\ fn_f64(3); | 3242 | \\ fn_char('3'); |
| 3261 | \\ fn_char('3'); | 3243 | \\ fn_char('\x1'); |
| 3262 | \\ fn_char('\x1'); | 3244 | \\ fn_char(0); |
| 3263 | \\ fn_char(0); | 3245 | \\ fn_f32(3.0f); |
| 3264 | \\ fn_f32(3.0f); | 3246 | \\ fn_f64(3.0); |
| 3265 | \\ fn_f64(3.0); | 3247 | \\ fn_bool(123); |
| 3266 | \\ fn_bool(123); | 3248 | \\ fn_bool(0); |
| 3267 | \\ fn_bool(0); | 3249 | \\ fn_bool(&fn_int); |
| 3268 | \\ fn_bool(&fn_int); | 3250 | \\ fn_int((int)&fn_int); |
| 3269 | \\ fn_int((int)&fn_int); | 3251 | \\ fn_ptr((void *)42); |
| 3270 | \\ fn_ptr((void *)42); | 3252 | \\} |
| 3271 | \\} | 3253 | , &[_][]const u8{ |
| 3272 | , &[_][]const u8{ | 3254 | \\pub extern fn fn_int(x: c_int) void; |
| 3273 | \\pub extern fn fn_int(x: c_int) void; | 3255 | \\pub extern fn fn_f32(x: f32) void; |
| 3274 | \\pub extern fn fn_f32(x: f32) void; | 3256 | \\pub extern fn fn_f64(x: f64) void; |
| 3275 | \\pub extern fn fn_f64(x: f64) void; | 3257 | \\pub extern fn fn_char(x: u8) void; |
| 3276 | \\pub extern fn fn_char(x: u8) void; | 3258 | \\pub extern fn fn_bool(x: bool) void; |
| 3277 | \\pub extern fn fn_bool(x: bool) void; | 3259 | \\pub extern fn fn_ptr(x: ?*anyopaque) void; |
| 3278 | \\pub extern fn fn_ptr(x: ?*anyopaque) void; | 3260 | \\pub export fn call() void { |
| 3279 | \\pub export fn call() void { | 3261 | \\ fn_int(@floatToInt(c_int, 3.0)); |
| 3280 | \\ fn_int(@floatToInt(c_int, 3.0)); | 3262 | \\ fn_int(@floatToInt(c_int, 3.0)); |
| 3281 | \\ fn_int(@floatToInt(c_int, 3.0)); | 3263 | \\ fn_int(@as(c_int, 1094861636)); |
| 3282 | \\ fn_int(@as(c_int, 1094861636)); | 3264 | \\ fn_f32(@intToFloat(f32, @as(c_int, 3))); |
| 3283 | \\ fn_f32(@intToFloat(f32, @as(c_int, 3))); | 3265 | \\ fn_f64(@intToFloat(f64, @as(c_int, 3))); |
| 3284 | \\ fn_f64(@intToFloat(f64, @as(c_int, 3))); | 3266 | \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '3')))); |
| 3285 | \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '3')))); | 3267 | \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '\x01')))); |
| 3286 | \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '\x01')))); | 3268 | \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, 0)))); |
| 3287 | \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, 0)))); | 3269 | \\ fn_f32(3.0); |
| 3288 | \\ fn_f32(3.0); | 3270 | \\ fn_f64(3.0); |
| 3289 | \\ fn_f64(3.0); | 3271 | \\ fn_bool(@as(c_int, 123) != 0); |
| 3290 | \\ fn_bool(@as(c_int, 123) != 0); | 3272 | \\ fn_bool(@as(c_int, 0) != 0); |
| 3291 | \\ fn_bool(@as(c_int, 0) != 0); | 3273 | \\ fn_bool(@ptrToInt(&fn_int) != 0); |
| 3292 | \\ fn_bool(@ptrToInt(&fn_int) != 0); | 3274 | \\ fn_int(@intCast(c_int, @ptrToInt(&fn_int))); |
| 3293 | \\ fn_int(@intCast(c_int, @ptrToInt(&fn_int))); | 3275 | \\ fn_ptr(@intToPtr(?*anyopaque, @as(c_int, 42))); |
| 3294 | \\ fn_ptr(@intToPtr(?*anyopaque, @as(c_int, 42))); | 3276 | \\} |
| 3295 | \\} | 3277 | }); |
| 3296 | }); | 3278 | |
| 3297 | } | 3279 | cases.add("function call", |
| 3298 | | 3280 | \\static void bar(void) { } |
| 3299 | if (builtin.zig_backend != .stage1) { | 3281 | \\void foo(int *(baz)(void)) { |
| 3300 | cases.add("function call", | 3282 | \\ bar(); |
| 3301 | \\static void bar(void) { } | 3283 | \\ baz(); |
| 3302 | \\void foo(int *(baz)(void)) { | 3284 | \\} |
| 3303 | \\ bar(); | 3285 | , &[_][]const u8{ |
| 3304 | \\ baz(); | 3286 | \\pub fn bar() callconv(.C) void {} |
| 3305 | \\} | 3287 | \\pub export fn foo(arg_baz: ?*const fn () callconv(.C) [*c]c_int) void { |
| 3306 | , &[_][]const u8{ | 3288 | \\ var baz = arg_baz; |
| 3307 | \\pub fn bar() callconv(.C) void {} | 3289 | \\ bar(); |
| 3308 | \\pub export fn foo(arg_baz: ?*const fn () callconv(.C) [*c]c_int) void { | 3290 | \\ _ = baz.?(); |
| 3309 | \\ var baz = arg_baz; | 3291 | \\} |
| 3310 | \\ bar(); | 3292 | }); |
| 3311 | \\ _ = baz.?(); | | |
| 3312 | \\} | | |
| 3313 | }); | | |
| 3314 | } | | |
| 3315 | | 3293 | |
| 3316 | cases.add("macro defines string literal with octal", | 3294 | cases.add("macro defines string literal with octal", |
| 3317 | \\#define FOO "aoeu\023 derp" | 3295 | \\#define FOO "aoeu\023 derp" |