summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.c-torture/execute/20020506-1.c
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gcc.c-torture/execute/20020506-1.c
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
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.
Diffstat (limited to 'gcc/testsuite/gcc.c-torture/execute/20020506-1.c')
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/20020506-1.c333
1 files changed, 333 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.c-torture/execute/20020506-1.c b/gcc/testsuite/gcc.c-torture/execute/20020506-1.c
new file mode 100644
index 000000000..bcbd45bf6
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/20020506-1.c
@@ -0,0 +1,333 @@
+/* Copyright (C) 2002 Free Software Foundation.
+
+ Test that (A & C1) op C2 optimizations behave correctly where C1 is
+ a constant power of 2, op is == or !=, and C2 is C1 or zero.
+
+ Written by Roger Sayle, 5th May 2002. */
+
+#include <limits.h>
+
+extern void abort (void);
+
+void test1 (signed char c, int set);
+void test2 (unsigned char c, int set);
+void test3 (short s, int set);
+void test4 (unsigned short s, int set);
+void test5 (int i, int set);
+void test6 (unsigned int i, int set);
+void test7 (long long l, int set);
+void test8 (unsigned long long l, int set);
+
+#ifndef LONG_LONG_MAX
+#define LONG_LONG_MAX __LONG_LONG_MAX__
+#endif
+#ifndef LONG_LONG_MIN
+#define LONG_LONG_MIN (-LONG_LONG_MAX-1)
+#endif
+#ifndef ULONG_LONG_MAX
+#define ULONG_LONG_MAX (LONG_LONG_MAX * 2ULL + 1)
+#endif
+
+
+void
+test1 (signed char c, int set)
+{
+ if ((c & (SCHAR_MAX+1)) == 0)
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+
+ if ((c & (SCHAR_MAX+1)) != 0)
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((c & (SCHAR_MAX+1)) == (SCHAR_MAX+1))
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((c & (SCHAR_MAX+1)) != (SCHAR_MAX+1))
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+}
+
+void
+test2 (unsigned char c, int set)
+{
+ if ((c & (SCHAR_MAX+1)) == 0)
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+
+ if ((c & (SCHAR_MAX+1)) != 0)
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((c & (SCHAR_MAX+1)) == (SCHAR_MAX+1))
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((c & (SCHAR_MAX+1)) != (SCHAR_MAX+1))
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+}
+
+void
+test3 (short s, int set)
+{
+ if ((s & (SHRT_MAX+1)) == 0)
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+
+ if ((s & (SHRT_MAX+1)) != 0)
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((s & (SHRT_MAX+1)) == (SHRT_MAX+1))
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((s & (SHRT_MAX+1)) != (SHRT_MAX+1))
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+}
+
+void
+test4 (unsigned short s, int set)
+{
+ if ((s & (SHRT_MAX+1)) == 0)
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+
+ if ((s & (SHRT_MAX+1)) != 0)
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((s & (SHRT_MAX+1)) == (SHRT_MAX+1))
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((s & (SHRT_MAX+1)) != (SHRT_MAX+1))
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+}
+
+void
+test5 (int i, int set)
+{
+ if ((i & (INT_MAX+1U)) == 0)
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+
+ if ((i & (INT_MAX+1U)) != 0)
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((i & (INT_MAX+1U)) == (INT_MAX+1U))
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((i & (INT_MAX+1U)) != (INT_MAX+1U))
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+}
+
+void
+test6 (unsigned int i, int set)
+{
+ if ((i & (INT_MAX+1U)) == 0)
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+
+ if ((i & (INT_MAX+1U)) != 0)
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((i & (INT_MAX+1U)) == (INT_MAX+1U))
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((i & (INT_MAX+1U)) != (INT_MAX+1U))
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+}
+
+void
+test7 (long long l, int set)
+{
+ if ((l & (LONG_LONG_MAX+1ULL)) == 0)
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+
+ if ((l & (LONG_LONG_MAX+1ULL)) != 0)
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((l & (LONG_LONG_MAX+1ULL)) == (LONG_LONG_MAX+1ULL))
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((l & (LONG_LONG_MAX+1ULL)) != (LONG_LONG_MAX+1ULL))
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+}
+
+void
+test8 (unsigned long long l, int set)
+{
+ if ((l & (LONG_LONG_MAX+1ULL)) == 0)
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+
+ if ((l & (LONG_LONG_MAX+1ULL)) != 0)
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((l & (LONG_LONG_MAX+1ULL)) == (LONG_LONG_MAX+1ULL))
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((l & (LONG_LONG_MAX+1ULL)) != (LONG_LONG_MAX+1ULL))
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+}
+
+int
+main ()
+{
+ test1 (0, 0);
+ test1 (SCHAR_MAX, 0);
+ test1 (SCHAR_MIN, 1);
+ test1 (UCHAR_MAX, 1);
+
+ test2 (0, 0);
+ test2 (SCHAR_MAX, 0);
+ test2 (SCHAR_MIN, 1);
+ test2 (UCHAR_MAX, 1);
+
+ test3 (0, 0);
+ test3 (SHRT_MAX, 0);
+ test3 (SHRT_MIN, 1);
+ test3 (USHRT_MAX, 1);
+
+ test4 (0, 0);
+ test4 (SHRT_MAX, 0);
+ test4 (SHRT_MIN, 1);
+ test4 (USHRT_MAX, 1);
+
+ test5 (0, 0);
+ test5 (INT_MAX, 0);
+ test5 (INT_MIN, 1);
+ test5 (UINT_MAX, 1);
+
+ test6 (0, 0);
+ test6 (INT_MAX, 0);
+ test6 (INT_MIN, 1);
+ test6 (UINT_MAX, 1);
+
+ test7 (0, 0);
+ test7 (LONG_LONG_MAX, 0);
+ test7 (LONG_LONG_MIN, 1);
+ test7 (ULONG_LONG_MAX, 1);
+
+ test8 (0, 0);
+ test8 (LONG_LONG_MAX, 0);
+ test8 (LONG_LONG_MIN, 1);
+ test8 (ULONG_LONG_MAX, 1);
+
+ return 0;
+}
+