aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/c-c++-common/ubsan/overflow-mul-3.c
diff options
context:
space:
mode:
authorBen Cheng <bccheng@google.com>2014-03-25 22:37:19 -0700
committerBen Cheng <bccheng@google.com>2014-03-25 22:37:19 -0700
commit1bc5aee63eb72b341f506ad058502cd0361f0d10 (patch)
treec607e8252f3405424ff15bc2d00aa38dadbb2518 /gcc-4.9/gcc/testsuite/c-c++-common/ubsan/overflow-mul-3.c
parent283a0bf58fcf333c58a2a92c3ebbc41fb9eb1fdb (diff)
downloadtoolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.gz
toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.bz2
toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.zip
Initial checkin of GCC 4.9.0 from trunk (r208799).
Change-Id: I48a3c08bb98542aa215912a75f03c0890e497dba
Diffstat (limited to 'gcc-4.9/gcc/testsuite/c-c++-common/ubsan/overflow-mul-3.c')
-rw-r--r--gcc-4.9/gcc/testsuite/c-c++-common/ubsan/overflow-mul-3.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/ubsan/overflow-mul-3.c b/gcc-4.9/gcc/testsuite/c-c++-common/ubsan/overflow-mul-3.c
new file mode 100644
index 000000000..037609be0
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/c-c++-common/ubsan/overflow-mul-3.c
@@ -0,0 +1,46 @@
+/* { dg-do run } */
+/* { dg-options "-fsanitize=signed-integer-overflow" } */
+
+#include <stdio.h>
+
+__attribute__((noinline, noclone)) long long
+mul (long long x, long long y)
+{
+ return x * y;
+}
+
+long long tab[] = {
+ 0x7fffffffLL, 0x7fffffffLL, 0x3fffffff00000001LL,
+ -0x80000000LL, -0x80000000LL, 0x4000000000000000LL,
+ 0x7fffffffLL, -0x80000000LL, -0x3fffffff80000000LL,
+ -0x80000000LL, 0x7fffffffLL, -0x3fffffff80000000LL,
+ 3LL, 5LL, 15LL,
+ -3LL, -9LL, 27LL,
+ 6LL, -7LL, -42LL,
+ -12LL, 13LL, -156LL,
+ 0x1555555555555555LL, 6LL, 0x7ffffffffffffffeLL,
+ -0x1555555555555555LL, -6LL, 0x7ffffffffffffffeLL,
+ 0x1555555555555555LL, -6LL, -0x7ffffffffffffffeLL,
+ -0x1555555555555555LL, 6LL, -0x7ffffffffffffffeLL,
+ 0x81234567LL, 0xfdbe971fLL, 0x7fffffffbea72879LL,
+ -0x81234567LL, -0xfdbe971fLL, 0x7fffffffbea72879LL,
+ 0x81234567LL, -0xfdbe971fLL, -0x7fffffffbea72879LL,
+ -0x81234567LL, 0xfdbe971fLL, -0x7fffffffbea72879LL
+};
+
+int
+main ()
+{
+ fputs ("UBSAN TEST START\n", stderr);
+
+ unsigned int i;
+ for (i = 0; i < sizeof (tab) / sizeof (long long); i += 3)
+ if (mul (tab[i], tab[i + 1]) != tab[i + 2]
+ || mul (tab[i + 1], tab[i]) != tab[i + 2])
+ __builtin_abort ();
+
+ fputs ("UBSAN TEST END\n", stderr);
+ return 0;
+}
+
+/* { dg-output "UBSAN TEST START(\n|\r\n|\r)UBSAN TEST END" } */