summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>2013-12-14 20:07:52 +0000
committermpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>2013-12-14 20:07:52 +0000
commit1e99ccfc56afe97e5bec8ca301b9b389657c9c7e (patch)
treed57e8392d1b7dfbfe7299758e9d8fac7435d9847
parent9ccaed8678c508558994428c28b433db1cc4343d (diff)
downloadgcc-1e99ccfc56afe97e5bec8ca301b9b389657c9c7e.tar.gz
More overflow-negate-* testing.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@205992 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/c-c++-common/ubsan/overflow-negate-1.c31
-rw-r--r--gcc/testsuite/c-c++-common/ubsan/overflow-negate-2.c39
3 files changed, 73 insertions, 3 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 6579c8bec96..d9106ea4212 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2013-12-14 Marek Polacek <polacek@redhat.com>
+
+ * c-c++-common/ubsan/overflow-negate-1.c: Add more testing. Don't
+ require int128 target.
+ * c-c++-common/ubsan/overflow-negate-2.c: New test.
+
2013-12-14 Janus Weil <janus@gcc.gnu.org>
PR fortran/59502
diff --git a/gcc/testsuite/c-c++-common/ubsan/overflow-negate-1.c b/gcc/testsuite/c-c++-common/ubsan/overflow-negate-1.c
index 9baada41007..2bdec61cba4 100644
--- a/gcc/testsuite/c-c++-common/ubsan/overflow-negate-1.c
+++ b/gcc/testsuite/c-c++-common/ubsan/overflow-negate-1.c
@@ -1,14 +1,39 @@
-/* { dg-do run { target int128 } } */
+/* { dg-do run } */
/* { dg-options "-fsanitize=signed-integer-overflow -Wno-unused-variable" } */
/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */
#define INT_MIN (-__INT_MAX__ - 1)
+#define LONG_MIN (-__LONG_MAX__ - 1L)
+#define LLONG_MIN (-__LONG_LONG_MAX__ - 1LL)
int
main (void)
{
- int j = INT_MIN;
- return -j;
+ int e = 1, f = -1;
+ volatile int i = INT_MIN;
+ volatile int i2 = i & (((((((-i) + 1) - 1) + 1) - 1) + 1) - 1);
+ i2 = -(i + e + f);
+ i = -i;
+
+ volatile long int li = LONG_MIN;
+ volatile long int li2 = li & (((((((-li) + 1) - 1) + 1) - 1) + 1) - 1);
+ li2 = -(li + e + f);
+ li = -li;
+
+ volatile long long int lli = LLONG_MIN;
+ volatile long long int lli2 = lli & (((((((-lli) + 1) - 1) + 1) - 1) + 1) - 1);
+ lli2 = -(lli + e + f);
+ lli = -lli;
+
+ return 0;
}
/* { dg-output "negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*negation of -\[^\n\r]* cannot be represented in type 'long int'; cast to an unsigned type to negate this value to itself(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*negation of -\[^\n\r]* cannot be represented in type 'long int'; cast to an unsigned type to negate this value to itself(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*negation of -\[^\n\r]* cannot be represented in type 'long int'; cast to an unsigned type to negate this value to itself(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*negation of -9223372036854775808 cannot be represented in type 'long long int'; cast to an unsigned type to negate this value to itself(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*negation of -9223372036854775808 cannot be represented in type 'long long int'; cast to an unsigned type to negate this value to itself(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*negation of -9223372036854775808 cannot be represented in type 'long long int'; cast to an unsigned type to negate this value to itself(\n|\r\n|\r)" } */
diff --git a/gcc/testsuite/c-c++-common/ubsan/overflow-negate-2.c b/gcc/testsuite/c-c++-common/ubsan/overflow-negate-2.c
new file mode 100644
index 00000000000..9ff35f86713
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/ubsan/overflow-negate-2.c
@@ -0,0 +1,39 @@
+/* { dg-do run } */
+/* { dg-options "-fsanitize=signed-integer-overflow -Wno-unused-variable" } */
+/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */
+
+#define SCHAR_MIN (-__SCHAR_MAX__ - 1)
+#define SHRT_MIN (-__SHRT_MAX__ - 1)
+#define INT_MIN (-__INT_MAX__ - 1)
+#define LONG_MIN (-__LONG_MAX__ - 1L)
+#define LLONG_MIN (-__LONG_LONG_MAX__ - 1LL)
+
+#define CHECK(A, B) ({ if ((A) != (B)) __builtin_abort (); })
+
+int
+main (void)
+{
+ volatile char c = -SCHAR_MIN;
+ CHECK (c, -128);
+
+ volatile short s = -SHRT_MIN;
+ CHECK (s, -32768);
+
+ volatile int i = INT_MIN;
+ i = -(unsigned) i;
+ CHECK (i, -0x80000000);
+
+ volatile long int li = LONG_MIN;
+ li = -(unsigned long) li;
+#if __LONG_MAX__ == 2147483647L
+ CHECK (li, -0x80000000L);
+#elif __LONG_MAX__ == 9223372036854775807L
+ CHECK (li, -0x8000000000000000L);
+#endif
+
+ volatile long long lli = LLONG_MIN;
+ lli = -(unsigned long long) lli;
+ CHECK (lli, -0x8000000000000000L);
+
+ return 0;
+}