Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / tests / tcg / multiarch / overflow.c
blob1c59c2cb7079378c33157a92e35260d0270caf07
1 #include <stdio.h>
3 int overflow_add_32(int x, int y)
5 int res;
6 return __builtin_add_overflow(x, y, &res);
9 int overflow_add_64(long long x, long long y)
11 long long res;
12 return __builtin_add_overflow(x, y, &res);
15 int overflow_sub_32(int x, int y)
17 int res;
18 return __builtin_sub_overflow(x, y, &res);
21 int overflow_sub_64(long long x, long long y)
23 long long res;
24 return __builtin_sub_overflow(x, y, &res);
27 int a1_add = -2147483648;
28 int b1_add = -2147483648;
29 long long a2_add = -9223372036854775808ULL;
30 long long b2_add = -9223372036854775808ULL;
32 int a1_sub;
33 int b1_sub = -2147483648;
34 long long a2_sub = 0L;
35 long long b2_sub = -9223372036854775808ULL;
37 int main()
39 int ret = 0;
41 if (!overflow_add_32(a1_add, b1_add)) {
42 fprintf(stderr, "data overflow while adding 32 bits\n");
43 ret = 1;
45 if (!overflow_add_64(a2_add, b2_add)) {
46 fprintf(stderr, "data overflow while adding 64 bits\n");
47 ret = 1;
49 if (!overflow_sub_32(a1_sub, b1_sub)) {
50 fprintf(stderr, "data overflow while subtracting 32 bits\n");
51 ret = 1;
53 if (!overflow_sub_64(a2_sub, b2_sub)) {
54 fprintf(stderr, "data overflow while subtracting 64 bits\n");
55 ret = 1;
57 return ret;