aboutsummaryrefslogtreecommitdiff
path: root/tests/tcg
diff options
context:
space:
mode:
authorGautam Agrawal <gautamnagrawal@gmail.com>2022-06-01 00:05:24 +0530
committerThomas Huth <thuth@redhat.com>2022-06-03 08:03:28 +0200
commit69d0535db941d1095d6ee2dba019c4c8cf8e2fa1 (patch)
treeeb380820c71c598256d26af2a921de8f1ceafb52 /tests/tcg
parent117d794396cea7d9c661c95e716eb618406d31aa (diff)
tests/tcg: Test overflow conditions
Add a test to check for overflow conditions in s390x. This patch is based on the following patches : * https://git.qemu.org/?p=qemu.git;a=commitdiff;h=5a2e67a691501 * https://git.qemu.org/?p=qemu.git;a=commitdiff;h=fc6e0d0f2db51 Signed-off-by: Gautam Agrawal <gautamnagrawal@gmail.com> Message-Id: <20220531183524.40948-1-gautamnagrawal@gmail.com> [thuth: Move overflow.c to tests/tcg/multiarch/ to make it generic] Signed-off-by: Thomas Huth <thuth@redhat.com>
Diffstat (limited to 'tests/tcg')
-rw-r--r--tests/tcg/multiarch/overflow.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/tcg/multiarch/overflow.c b/tests/tcg/multiarch/overflow.c
new file mode 100644
index 0000000000..1c59c2cb70
--- /dev/null
+++ b/tests/tcg/multiarch/overflow.c
@@ -0,0 +1,58 @@
+#include <stdio.h>
+
+int overflow_add_32(int x, int y)
+{
+ int res;
+ return __builtin_add_overflow(x, y, &res);
+}
+
+int overflow_add_64(long long x, long long y)
+{
+ long long res;
+ return __builtin_add_overflow(x, y, &res);
+}
+
+int overflow_sub_32(int x, int y)
+{
+ int res;
+ return __builtin_sub_overflow(x, y, &res);
+}
+
+int overflow_sub_64(long long x, long long y)
+{
+ long long res;
+ return __builtin_sub_overflow(x, y, &res);
+}
+
+int a1_add = -2147483648;
+int b1_add = -2147483648;
+long long a2_add = -9223372036854775808ULL;
+long long b2_add = -9223372036854775808ULL;
+
+int a1_sub;
+int b1_sub = -2147483648;
+long long a2_sub = 0L;
+long long b2_sub = -9223372036854775808ULL;
+
+int main()
+{
+ int ret = 0;
+
+ if (!overflow_add_32(a1_add, b1_add)) {
+ fprintf(stderr, "data overflow while adding 32 bits\n");
+ ret = 1;
+ }
+ if (!overflow_add_64(a2_add, b2_add)) {
+ fprintf(stderr, "data overflow while adding 64 bits\n");
+ ret = 1;
+ }
+ if (!overflow_sub_32(a1_sub, b1_sub)) {
+ fprintf(stderr, "data overflow while subtracting 32 bits\n");
+ ret = 1;
+ }
+ if (!overflow_sub_64(a2_sub, b2_sub)) {
+ fprintf(stderr, "data overflow while subtracting 64 bits\n");
+ ret = 1;
+ }
+ return ret;
+}