diff mbox

[ubsan] Add more testing

Message ID 20130722114634.GH14359@redhat.com
State New
Headers show

Commit Message

Marek Polacek July 22, 2013, 11:46 a.m. UTC
This adds more testing to the ubsan testsuite.  It still doesn't
test everything, but it's better than nothing and I've already found
one bug (already fixed).

Tested with RUNTESTFLAGS='--target_board=unix\{-m32,-m64\}.
Commited to ubsan branch.

2013-07-22  Marek Polacek  <polacek@redhat.com>

	* c-c++-common/ubsan/div-by-zero-3.c: Add more testing.
	* c-c++-common/ubsan/div-by-zero-1.c: Likewise.
	* c-c++-common/ubsan/shift-1.c: Likewise.
	* c-c++-common/ubsan/shift-2.c: Likewise.
	* c-c++-common/ubsan/div-by-zero-2.c: Likewise.


	Marek
diff mbox

Patch

--- gcc/testsuite/c-c++-common/ubsan/div-by-zero-3.c.mp	2013-07-22 13:41:13.375402476 +0200
+++ gcc/testsuite/c-c++-common/ubsan/div-by-zero-3.c	2013-07-22 13:41:45.031527627 +0200
@@ -6,7 +6,16 @@ 
 int
 main (void)
 {
+  volatile int min = INT_MIN;
+  volatile int zero = 0;
+
   INT_MIN / -1;
+  min / -1;
+  min / (10 * zero - (2 - 1));
+
   return 0;
 }
- /* { dg-output "division of -2147483648 by -1 cannot be represented in type int" } */
+
+/* { dg-output "division of -2147483648 by -1 cannot be represented in type int(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*division of -2147483648 by -1 cannot be represented in type int(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*division of -2147483648 by -1 cannot be represented in type int(\n|\r\n|\r)" } */
--- gcc/testsuite/c-c++-common/ubsan/div-by-zero-1.c.mp	2013-07-22 13:41:13.370402454 +0200
+++ gcc/testsuite/c-c++-common/ubsan/div-by-zero-1.c	2013-07-22 13:41:45.030527622 +0200
@@ -4,7 +4,21 @@ 
 int
 main (void)
 {
+  volatile int a = 0;
+  volatile long long int b = 0;
+  volatile unsigned int c = 1;
+
+  a / b;
   0 / 0;
+  a / 0;
+  0 / b;
+  2 / --c;
+
   return 0;
 }
- /* { dg-output "division by zero" } */
+
+/* { dg-output "division by zero(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*division by zero(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*division by zero(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*division by zero(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*division by zero(\n|\r\n|\r)" } */
--- gcc/testsuite/c-c++-common/ubsan/shift-1.c.mp	2013-07-22 13:41:13.377402486 +0200
+++ gcc/testsuite/c-c++-common/ubsan/shift-1.c	2013-07-22 13:41:45.032527632 +0200
@@ -1,11 +1,31 @@ 
 /* { dg-do run } */
 /* { dg-options "-fsanitize=shift -w" } */
 
+typedef const unsigned long long int CULLI;
+typedef volatile int VI;
+struct s { signed long int a; };
+
 int
 main (void)
 {
   int a = 1;
+  struct s s = { .a = 400 };
+  CULLI culli = 42;
+  VI vi = 370;
+  volatile int shiftcount = 153;
+
   a <<= 152;
+  1 << shiftcount;
+  1 << 154;
+  culli << 524;
+  1 << vi++;
+  (long) 1 << (s.a + 2);
+
   return 0;
 }
-/* { dg-output "shift exponent 152 is too large for \[^\n\r]*-bit type int" } */
+/* { dg-output "shift exponent 152 is too large for \[^\n\r]*-bit type int(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*shift exponent 153 is too large for \[^\n\r]*-bit type int(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*shift exponent 154 is too large for \[^\n\r]*-bit type int(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*shift exponent 524 is too large for \[^\n\r]*-bit type long long unsigned int(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*shift exponent 370 is too large for \[^\n\r]*-bit type int(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*shift exponent 402 is too large for \[^\n\r]*-bit type long int(\n|\r\n|\r)" } */
--- gcc/testsuite/c-c++-common/ubsan/shift-2.c.mp	2013-07-22 13:41:13.378402491 +0200
+++ gcc/testsuite/c-c++-common/ubsan/shift-2.c	2013-07-22 13:41:45.033527637 +0200
@@ -5,7 +5,19 @@  int
 main (void)
 {
   int a = 1;
-  a <<= -3;
+  volatile int b = -5;
+  long long int c = -6;
+
+  a << -3;
+  1 << -4;
+  1 << b;
+  a << c;
+  a << (b + c);
+
   return 0;
 }
-/* { dg-output "shift exponent -3 is negative" } */
+/* { dg-output "shift exponent -3 is negative(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*shift exponent -4 is negative(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*shift exponent -5 is negative(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*shift exponent -6 is negative(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*shift exponent -11 is negative(\n|\r\n|\r)" } */
--- gcc/testsuite/c-c++-common/ubsan/div-by-zero-2.c.mp	2013-07-22 13:41:13.374402471 +0200
+++ gcc/testsuite/c-c++-common/ubsan/div-by-zero-2.c	2013-07-22 13:41:45.031527627 +0200
@@ -4,7 +4,20 @@ 
 int
 main (void)
 {
+  volatile const unsigned long int o = 1UL;
+  int zero = 0;
+
+  o / 0;
   1UL / 0;
+  1UL / zero;
+  o / zero;
+  o / (++zero - 1);
+
   return 0;
 }
- /* { dg-output "division by zero" } */
+
+/* { dg-output "division by zero(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*division by zero(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*division by zero(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*division by zero(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*division by zero(\n|\r\n|\r)" } */