From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- gcc/testsuite/gcc.c-torture/execute/arith-rand.c | 114 +++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 gcc/testsuite/gcc.c-torture/execute/arith-rand.c (limited to 'gcc/testsuite/gcc.c-torture/execute/arith-rand.c') diff --git a/gcc/testsuite/gcc.c-torture/execute/arith-rand.c b/gcc/testsuite/gcc.c-torture/execute/arith-rand.c new file mode 100644 index 000000000..4af146a1a --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/arith-rand.c @@ -0,0 +1,114 @@ +long +simple_rand () +{ + static unsigned long seed = 47114711; + unsigned long this = seed * 1103515245 + 12345; + seed = this; + return this >> 8; +} + +unsigned long int +random_bitstring () +{ + unsigned long int x; + int n_bits; + long ran; + int tot_bits = 0; + + x = 0; + for (;;) + { + ran = simple_rand (); + n_bits = (ran >> 1) % 16; + tot_bits += n_bits; + + if (n_bits == 0) + return x; + else + { + x <<= n_bits; + if (ran & 1) + x |= (1 << n_bits) - 1; + + if (tot_bits > 8 * sizeof (long) + 6) + return x; + } + } +} + +#define ABS(x) ((x) >= 0 ? (x) : -(x)) + +main () +{ + long int i; + + for (i = 0; i < 1000; i++) + { + unsigned long x, y; + x = random_bitstring (); + y = random_bitstring (); + + if (sizeof (int) == sizeof (long)) + goto save_time; + + { unsigned long xx = x, yy = y, r1, r2; + if (yy == 0) continue; + r1 = xx / yy; + r2 = xx % yy; + if (r2 >= yy || r1 * yy + r2 != xx) + abort (); + } + { signed long xx = x, yy = y, r1, r2; + if ((unsigned long) xx << 1 == 0 && yy == -1) + continue; + r1 = xx / yy; + r2 = xx % yy; + if (ABS (r2) >= (unsigned long) ABS (yy) || (signed long) (r1 * yy + r2) != xx) + abort (); + } + save_time: + { unsigned int xx = x, yy = y, r1, r2; + if (yy == 0) continue; + r1 = xx / yy; + r2 = xx % yy; + if (r2 >= yy || r1 * yy + r2 != xx) + abort (); + } + { signed int xx = x, yy = y, r1, r2; + if ((unsigned int) xx << 1 == 0 && yy == -1) + continue; + r1 = xx / yy; + r2 = xx % yy; + if (ABS (r2) >= (unsigned int) ABS (yy) || (signed int) (r1 * yy + r2) != xx) + abort (); + } + { unsigned short xx = x, yy = y, r1, r2; + if (yy == 0) continue; + r1 = xx / yy; + r2 = xx % yy; + if (r2 >= yy || r1 * yy + r2 != xx) + abort (); + } + { signed short xx = x, yy = y, r1, r2; + r1 = xx / yy; + r2 = xx % yy; + if (ABS (r2) >= (unsigned short) ABS (yy) || (signed short) (r1 * yy + r2) != xx) + abort (); + } + { unsigned char xx = x, yy = y, r1, r2; + if (yy == 0) continue; + r1 = xx / yy; + r2 = xx % yy; + if (r2 >= yy || r1 * yy + r2 != xx) + abort (); + } + { signed char xx = x, yy = y, r1, r2; + r1 = xx / yy; + r2 = xx % yy; + if (ABS (r2) >= (unsigned char) ABS (yy) || (signed char) (r1 * yy + r2) != xx) + abort (); + } + } + + exit (0); +} -- cgit v1.2.3