| ... | ... | @@ -819,6 +819,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 819 | 819 | \\} |
| 820 | 820 | }); |
| 821 | 821 | |
| 822 | cases.addC("__extension__ cast", |
| 823 | \\int foo(void) { |
| 824 | \\ return __extension__ 1; |
| 825 | \\} |
| 826 | , &[_][]const u8{ |
| 827 | \\pub export fn foo() c_int { |
| 828 | \\ return 1; |
| 829 | \\} |
| 830 | }); |
| 831 | |
| 822 | 832 | /////////////// Cases that pass for only stage2 //////////////// |
| 823 | 833 | |
| 824 | 834 | cases.add_2("Parameterless function prototypes", |
| ... | ... | @@ -2031,43 +2041,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2031 | 2041 | \\} |
| 2032 | 2042 | }); |
| 2033 | 2043 | |
| 2034 | | /////////////// Cases for only stage1 which are TODO items for stage2 //////////////// |
| 2035 | | |
| 2036 | | cases.add("macro defines string literal with hex", |
| 2037 | | \\#define FOO "aoeu\xab derp" |
| 2038 | | \\#define FOO2 "aoeu\x0007a derp" |
| 2039 | | \\#define FOO_CHAR '\xfF' |
| 2040 | | , &[_][]const u8{ |
| 2041 | | \\pub const FOO = "aoeu\xab derp"; |
| 2042 | | , |
| 2043 | | \\pub const FOO2 = "aoeuz derp"; |
| 2044 | | , |
| 2045 | | \\pub const FOO_CHAR = 255; |
| 2046 | | }); |
| 2047 | | |
| 2048 | | cases.add("macro defines string literal with octal", |
| 2049 | | \\#define FOO "aoeu\023 derp" |
| 2050 | | \\#define FOO2 "aoeu\0234 derp" |
| 2051 | | \\#define FOO_CHAR '\077' |
| 2052 | | , &[_][]const u8{ |
| 2053 | | \\pub const FOO = "aoeu\x13 derp"; |
| 2054 | | , |
| 2055 | | \\pub const FOO2 = "aoeu\x134 derp"; |
| 2056 | | , |
| 2057 | | \\pub const FOO_CHAR = 63; |
| 2058 | | }); |
| 2059 | | |
| 2060 | | cases.addC("__extension__ cast", |
| 2061 | | \\int foo(void) { |
| 2062 | | \\ return __extension__ 1; |
| 2063 | | \\} |
| 2064 | | , &[_][]const u8{ |
| 2065 | | \\pub export fn foo() c_int { |
| 2066 | | \\ return 1; |
| 2067 | | \\} |
| 2068 | | }); |
| 2069 | | |
| 2070 | | cases.addC("implicit casts", |
| 2044 | cases.add_2("implicit casts", |
| 2071 | 2045 | \\#include <stdbool.h> |
| 2072 | 2046 | \\ |
| 2073 | 2047 | \\void fn_int(int x); |
| ... | ... | @@ -2103,25 +2077,51 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2103 | 2077 | \\pub extern fn fn_bool(x: bool) void; |
| 2104 | 2078 | \\pub extern fn fn_ptr(x: ?*c_void) void; |
| 2105 | 2079 | \\pub export fn call(q: c_int) void { |
| 2106 | | \\ fn_int(@floatToInt(c_int, 3.000000)); |
| 2107 | | \\ fn_int(@floatToInt(c_int, 3.000000)); |
| 2108 | | \\ fn_int(@floatToInt(c_int, 3.000000)); |
| 2080 | \\ fn_int(@floatToInt(c_int, 3)); |
| 2081 | \\ fn_int(@floatToInt(c_int, 3)); |
| 2082 | \\ fn_int(@floatToInt(c_int, 3)); |
| 2109 | 2083 | \\ fn_int(1094861636); |
| 2110 | 2084 | \\ fn_f32(@intToFloat(f32, 3)); |
| 2111 | 2085 | \\ fn_f64(@intToFloat(f64, 3)); |
| 2112 | 2086 | \\ fn_char(@as(u8, '3')); |
| 2113 | 2087 | \\ fn_char(@as(u8, '\x01')); |
| 2114 | 2088 | \\ fn_char(@as(u8, 0)); |
| 2115 | | \\ fn_f32(3.000000); |
| 2116 | | \\ fn_f64(3.000000); |
| 2117 | | \\ fn_bool(true); |
| 2118 | | \\ fn_bool(false); |
| 2089 | \\ fn_f32(3); |
| 2090 | \\ fn_f64(3); |
| 2091 | \\ fn_bool(123 != 0); |
| 2092 | \\ fn_bool(0 != 0); |
| 2119 | 2093 | \\ fn_bool(@ptrToInt(&fn_int) != 0); |
| 2120 | 2094 | \\ fn_int(@intCast(c_int, @ptrToInt(&fn_int))); |
| 2121 | 2095 | \\ fn_ptr(@intToPtr(?*c_void, 42)); |
| 2122 | 2096 | \\} |
| 2123 | 2097 | }); |
| 2124 | 2098 | |
| 2099 | /////////////// Cases for only stage1 which are TODO items for stage2 //////////////// |
| 2100 | |
| 2101 | cases.add("macro defines string literal with hex", |
| 2102 | \\#define FOO "aoeu\xab derp" |
| 2103 | \\#define FOO2 "aoeu\x0007a derp" |
| 2104 | \\#define FOO_CHAR '\xfF' |
| 2105 | , &[_][]const u8{ |
| 2106 | \\pub const FOO = "aoeu\xab derp"; |
| 2107 | , |
| 2108 | \\pub const FOO2 = "aoeuz derp"; |
| 2109 | , |
| 2110 | \\pub const FOO_CHAR = 255; |
| 2111 | }); |
| 2112 | |
| 2113 | cases.add("macro defines string literal with octal", |
| 2114 | \\#define FOO "aoeu\023 derp" |
| 2115 | \\#define FOO2 "aoeu\0234 derp" |
| 2116 | \\#define FOO_CHAR '\077' |
| 2117 | , &[_][]const u8{ |
| 2118 | \\pub const FOO = "aoeu\x13 derp"; |
| 2119 | , |
| 2120 | \\pub const FOO2 = "aoeu\x134 derp"; |
| 2121 | , |
| 2122 | \\pub const FOO_CHAR = 63; |
| 2123 | }); |
| 2124 | |
| 2125 | 2125 | if (builtin.os != builtin.Os.windows) { |
| 2126 | 2126 | // sysv_abi not currently supported on windows |
| 2127 | 2127 | cases.add("Macro qualified functions", |
| ... | ... | @@ -2990,4 +2990,59 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2990 | 2990 | \\ }); |
| 2991 | 2991 | \\} |
| 2992 | 2992 | }); |
| 2993 | |
| 2994 | cases.addC("implicit casts", |
| 2995 | \\#include <stdbool.h> |
| 2996 | \\ |
| 2997 | \\void fn_int(int x); |
| 2998 | \\void fn_f32(float x); |
| 2999 | \\void fn_f64(double x); |
| 3000 | \\void fn_char(char x); |
| 3001 | \\void fn_bool(bool x); |
| 3002 | \\void fn_ptr(void *x); |
| 3003 | \\ |
| 3004 | \\void call(int q) { |
| 3005 | \\ fn_int(3.0f); |
| 3006 | \\ fn_int(3.0); |
| 3007 | \\ fn_int(3.0L); |
| 3008 | \\ fn_int('ABCD'); |
| 3009 | \\ fn_f32(3); |
| 3010 | \\ fn_f64(3); |
| 3011 | \\ fn_char('3'); |
| 3012 | \\ fn_char('\x1'); |
| 3013 | \\ fn_char(0); |
| 3014 | \\ fn_f32(3.0f); |
| 3015 | \\ fn_f64(3.0); |
| 3016 | \\ fn_bool(123); |
| 3017 | \\ fn_bool(0); |
| 3018 | \\ fn_bool(&fn_int); |
| 3019 | \\ fn_int(&fn_int); |
| 3020 | \\ fn_ptr(42); |
| 3021 | \\} |
| 3022 | , &[_][]const u8{ |
| 3023 | \\pub extern fn fn_int(x: c_int) void; |
| 3024 | \\pub extern fn fn_f32(x: f32) void; |
| 3025 | \\pub extern fn fn_f64(x: f64) void; |
| 3026 | \\pub extern fn fn_char(x: u8) void; |
| 3027 | \\pub extern fn fn_bool(x: bool) void; |
| 3028 | \\pub extern fn fn_ptr(x: ?*c_void) void; |
| 3029 | \\pub export fn call(q: c_int) void { |
| 3030 | \\ fn_int(@floatToInt(c_int, 3.000000)); |
| 3031 | \\ fn_int(@floatToInt(c_int, 3.000000)); |
| 3032 | \\ fn_int(@floatToInt(c_int, 3.000000)); |
| 3033 | \\ fn_int(1094861636); |
| 3034 | \\ fn_f32(@intToFloat(f32, 3)); |
| 3035 | \\ fn_f64(@intToFloat(f64, 3)); |
| 3036 | \\ fn_char(@as(u8, '3')); |
| 3037 | \\ fn_char(@as(u8, '\x01')); |
| 3038 | \\ fn_char(@as(u8, 0)); |
| 3039 | \\ fn_f32(3.000000); |
| 3040 | \\ fn_f64(3.000000); |
| 3041 | \\ fn_bool(true); |
| 3042 | \\ fn_bool(false); |
| 3043 | \\ fn_bool(@ptrToInt(&fn_int) != 0); |
| 3044 | \\ fn_int(@intCast(c_int, @ptrToInt(&fn_int))); |
| 3045 | \\ fn_ptr(@intToPtr(?*c_void, 42)); |
| 3046 | \\} |
| 3047 | }); |
| 2993 | 3048 | } |