| ... | ... | @@ -891,39 +891,42 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void { |
| 891 | 891 | \\} |
| 892 | 892 | , ""); |
| 893 | 893 | |
| 894 | | cases.add("Obscure ways of calling functions; issue #4124", |
| 895 | | \\#include <stdlib.h> |
| 896 | | \\static int add(int a, int b) { |
| 897 | | \\ return a + b; |
| 898 | | \\} |
| 899 | | \\typedef int (*adder)(int, int); |
| 900 | | \\typedef void (*funcptr)(void); |
| 901 | | \\int main() { |
| 902 | | \\ if ((add)(1, 2) != 3) abort(); |
| 903 | | \\ if ((&add)(1, 2) != 3) abort(); |
| 904 | | \\ if (add(3, 1) != 4) abort(); |
| 905 | | \\ if ((*add)(2, 3) != 5) abort(); |
| 906 | | \\ if ((**add)(7, -1) != 6) abort(); |
| 907 | | \\ if ((***add)(-2, 9) != 7) abort(); |
| 908 | | \\ |
| 909 | | \\ int (*ptr)(int a, int b); |
| 910 | | \\ ptr = add; |
| 911 | | \\ |
| 912 | | \\ if (ptr(1, 2) != 3) abort(); |
| 913 | | \\ if ((*ptr)(3, 1) != 4) abort(); |
| 914 | | \\ if ((**ptr)(2, 3) != 5) abort(); |
| 915 | | \\ if ((***ptr)(7, -1) != 6) abort(); |
| 916 | | \\ if ((****ptr)(-2, 9) != 7) abort(); |
| 917 | | \\ |
| 918 | | \\ funcptr addr1 = (funcptr)(add); |
| 919 | | \\ funcptr addr2 = (funcptr)(&add); |
| 920 | | \\ |
| 921 | | \\ if (addr1 != addr2) abort(); |
| 922 | | \\ if (((int(*)(int, int))addr1)(1, 2) != 3) abort(); |
| 923 | | \\ if (((adder)addr2)(1, 2) != 3) abort(); |
| 924 | | \\ return 0; |
| 925 | | \\} |
| 926 | | , ""); |
| 894 | if (@import("builtin").zig_backend == .stage1) { |
| 895 | // https://github.com/ziglang/zig/issues/12263 |
| 896 | cases.add("Obscure ways of calling functions; issue #4124", |
| 897 | \\#include <stdlib.h> |
| 898 | \\static int add(int a, int b) { |
| 899 | \\ return a + b; |
| 900 | \\} |
| 901 | \\typedef int (*adder)(int, int); |
| 902 | \\typedef void (*funcptr)(void); |
| 903 | \\int main() { |
| 904 | \\ if ((add)(1, 2) != 3) abort(); |
| 905 | \\ if ((&add)(1, 2) != 3) abort(); |
| 906 | \\ if (add(3, 1) != 4) abort(); |
| 907 | \\ if ((*add)(2, 3) != 5) abort(); |
| 908 | \\ if ((**add)(7, -1) != 6) abort(); |
| 909 | \\ if ((***add)(-2, 9) != 7) abort(); |
| 910 | \\ |
| 911 | \\ int (*ptr)(int a, int b); |
| 912 | \\ ptr = add; |
| 913 | \\ |
| 914 | \\ if (ptr(1, 2) != 3) abort(); |
| 915 | \\ if ((*ptr)(3, 1) != 4) abort(); |
| 916 | \\ if ((**ptr)(2, 3) != 5) abort(); |
| 917 | \\ if ((***ptr)(7, -1) != 6) abort(); |
| 918 | \\ if ((****ptr)(-2, 9) != 7) abort(); |
| 919 | \\ |
| 920 | \\ funcptr addr1 = (funcptr)(add); |
| 921 | \\ funcptr addr2 = (funcptr)(&add); |
| 922 | \\ |
| 923 | \\ if (addr1 != addr2) abort(); |
| 924 | \\ if (((int(*)(int, int))addr1)(1, 2) != 3) abort(); |
| 925 | \\ if (((adder)addr2)(1, 2) != 3) abort(); |
| 926 | \\ return 0; |
| 927 | \\} |
| 928 | , ""); |
| 929 | } |
| 927 | 930 | |
| 928 | 931 | cases.add("Return boolean expression as int; issue #6215", |
| 929 | 932 | \\#include <stdlib.h> |
| ... | ... | @@ -1319,25 +1322,28 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void { |
| 1319 | 1322 | \\} |
| 1320 | 1323 | , ""); |
| 1321 | 1324 | |
| 1322 | | cases.add("basic vector expressions", |
| 1323 | | \\#include <stdlib.h> |
| 1324 | | \\#include <stdint.h> |
| 1325 | | \\typedef int16_t __v8hi __attribute__((__vector_size__(16))); |
| 1326 | | \\int main(int argc, char**argv) { |
| 1327 | | \\ __v8hi uninitialized; |
| 1328 | | \\ __v8hi empty_init = {}; |
| 1329 | | \\ __v8hi partial_init = {0, 1, 2, 3}; |
| 1330 | | \\ |
| 1331 | | \\ __v8hi a = {0, 1, 2, 3, 4, 5, 6, 7}; |
| 1332 | | \\ __v8hi b = (__v8hi) {100, 200, 300, 400, 500, 600, 700, 800}; |
| 1333 | | \\ |
| 1334 | | \\ __v8hi sum = a + b; |
| 1335 | | \\ for (int i = 0; i < 8; i++) { |
| 1336 | | \\ if (sum[i] != a[i] + b[i]) abort(); |
| 1337 | | \\ } |
| 1338 | | \\ return 0; |
| 1339 | | \\} |
| 1340 | | , ""); |
| 1325 | if (@import("builtin").zig_backend == .stage1) { |
| 1326 | // https://github.com/ziglang/zig/issues/12264 |
| 1327 | cases.add("basic vector expressions", |
| 1328 | \\#include <stdlib.h> |
| 1329 | \\#include <stdint.h> |
| 1330 | \\typedef int16_t __v8hi __attribute__((__vector_size__(16))); |
| 1331 | \\int main(int argc, char**argv) { |
| 1332 | \\ __v8hi uninitialized; |
| 1333 | \\ __v8hi empty_init = {}; |
| 1334 | \\ __v8hi partial_init = {0, 1, 2, 3}; |
| 1335 | \\ |
| 1336 | \\ __v8hi a = {0, 1, 2, 3, 4, 5, 6, 7}; |
| 1337 | \\ __v8hi b = (__v8hi) {100, 200, 300, 400, 500, 600, 700, 800}; |
| 1338 | \\ |
| 1339 | \\ __v8hi sum = a + b; |
| 1340 | \\ for (int i = 0; i < 8; i++) { |
| 1341 | \\ if (sum[i] != a[i] + b[i]) abort(); |
| 1342 | \\ } |
| 1343 | \\ return 0; |
| 1344 | \\} |
| 1345 | , ""); |
| 1346 | } |
| 1341 | 1347 | |
| 1342 | 1348 | cases.add("__builtin_shufflevector", |
| 1343 | 1349 | \\#include <stdlib.h> |