aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2016-02-24 17:04:03 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2016-02-24 10:04:03 -0700
commit57c2c374df803636ce218618091114ac13647467 (patch)
tree20a1c935058eea046189d7f537732d0f329c0414
parent65433bb5b64b62dc66c850e312e3edd8236535d9 (diff)
downloadgcc-57c2c374df803636ce218618091114ac13647467.zip
gcc-57c2c374df803636ce218618091114ac13647467.tar.gz
gcc-57c2c374df803636ce218618091114ac13647467.tar.bz2
Avoid making unportable assumptions about the relationship between SIZE_MAX
and UINT_MAX. gcc/testsuite/ChangeLog: * gcc/testsuite/gcc.dg/builtins-68.c: Avoid making unportable assumptions about the relationship between SIZE_MAX and UINT_MAX. * gcc/testsuite/g++.dg/ext/builtin_alloca.C: Same. From-SVN: r233677
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/ext/builtin_alloca.C34
-rw-r--r--gcc/testsuite/gcc.dg/builtins-68.c34
3 files changed, 44 insertions, 30 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7db6b61..b215d09 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2016-02-24 Martin Sebor <msebor@redhat.com>
+
+ * gcc/testsuite/gcc.dg/builtins-68.c: Avoid making unportable
+ assumptions about the relationship between SIZE_MAX and UINT_MAX.
+ * gcc/testsuite/g++.dg/ext/builtin_alloca.C: Same.
+
2016-02-24 Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org>
Charles Baylis <charles.baylis@linaro.org>
diff --git a/gcc/testsuite/g++.dg/ext/builtin_alloca.C b/gcc/testsuite/g++.dg/ext/builtin_alloca.C
index 10a9bdc..7a0d331 100644
--- a/gcc/testsuite/g++.dg/ext/builtin_alloca.C
+++ b/gcc/testsuite/g++.dg/ext/builtin_alloca.C
@@ -4,10 +4,23 @@
// { dg-do compile }
#define CHAR_BIT __CHAR_BIT__
-#define INT_MAX __INT_MAX__
-#define INT_MIN (-INT_MAX - 1)
-#define LONG_MAX __LONG_MAX__
-#define LLONG_MAX __LONG_LONG_MAX__
+#define SIZE_MAX __SIZE_MAX__
+#define UINT_MAX (__INT_MAX__ + 1U)
+
+/* The largest valid alignment is undocumented and subject to change
+ but for the purposes of white box testing we rely on knowing that
+ it happens to be defined to (UINT_MAX >> 1) + 1. */
+#define ALIGN_MAX ((UINT_MAX >> 1) + 1)
+
+#if UINT_MAX < SIZE_MAX
+/* Define a constant to exercise an alignment that is valid a power
+ of 2 in excess of the maximum. */
+# define MAX_X_2 (ALIGN_MAX << 1)
+#else
+/* For targets where UINT_MAX is the same as SIZE_MAX, use an invalid
+ alignment that's less than the maximum to elicit the same errors. */
+# define MAX_X_2 (ALIGN_MAX + 1)
+#endif
static void* p;
@@ -122,10 +135,6 @@ void test_arg2_non_const (int n, int a1)
// of CHAR_BIT must be rejected.
void test_arg2_non_pow2 (int n)
{
- p = __builtin_alloca_with_align (n, INT_MIN); // { dg-error "must be a constant integer" }
- p = __builtin_alloca_with_align (n, -1); // { dg-error "must be a constant integer" }
- p = __builtin_alloca_with_align (n, !1); // { dg-error "must be a constant integer" }
- p = __builtin_alloca_with_align (n, !0); // { dg-error "must be a constant integer" }
p = __builtin_alloca_with_align (n, 0); // { dg-error "must be a constant integer" }
p = __builtin_alloca_with_align (n, 1); // { dg-error "must be a constant integer" }
p = __builtin_alloca_with_align (n, 2); // { dg-error "must be a constant integer" }
@@ -146,13 +155,8 @@ void test_arg2_non_pow2 (int n)
p = __builtin_alloca_with_align (n, 33); // { dg-error "must be a constant integer" }
p = __builtin_alloca_with_align (n, 63); // { dg-error "must be a constant integer" }
p = __builtin_alloca_with_align (n, 65); // { dg-error "must be a constant integer" }
- p = __builtin_alloca_with_align (n, INT_MAX); // { dg-error "must be a constant integer" }
- p = __builtin_alloca_with_align (n, ~0U); // { dg-error "must be a constant integer" }
- p = __builtin_alloca_with_align (n, LONG_MAX); // { dg-error "must be a constant integer" }
- p = __builtin_alloca_with_align (n, ~0LU); // { dg-error "must be a constant integer" }
- p = __builtin_alloca_with_align (n, 1LLU << 34); // { dg-error "must be a constant integer" }
- p = __builtin_alloca_with_align (n, LLONG_MAX); // { dg-error "must be a constant integer" }
- p = __builtin_alloca_with_align (n, ~0LLU); // { dg-error "must be a constant integer" }
+ p = __builtin_alloca_with_align (n, SIZE_MAX); /* { dg-error "must be a constant integer" } */
+ p = __builtin_alloca_with_align (n, MAX_X_2); /* { dg-error "must be a constant integer" } */
}
// Exercise invalid alignment specified by a template argument.
diff --git a/gcc/testsuite/gcc.dg/builtins-68.c b/gcc/testsuite/gcc.dg/builtins-68.c
index d2e65d0..c0cc1eb 100644
--- a/gcc/testsuite/gcc.dg/builtins-68.c
+++ b/gcc/testsuite/gcc.dg/builtins-68.c
@@ -5,10 +5,23 @@
/* { dg-options "-Wno-long-long" } */
#define CHAR_BIT __CHAR_BIT__
-#define INT_MAX __INT_MAX__
-#define INT_MIN (-INT_MAX - 1)
-#define LONG_MAX __LONG_MAX__
-#define LLONG_MAX __LONG_LONG_MAX__
+#define SIZE_MAX __SIZE_MAX__
+#define UINT_MAX (__INT_MAX__ + 1U)
+
+/* The largest valid alignment is undocumented and subject to change
+ but for the purposes of white box testing we rely on knowing that
+ it happens to be defined to (UINT_MAX >> 1) + 1. */
+#define ALIGN_MAX ((UINT_MAX >> 1) + 1)
+
+#if UINT_MAX < SIZE_MAX
+/* Define a constant to exercise an alignment that is valid a power
+ of 2 in excess of the maximum. */
+# define MAX_X_2 (ALIGN_MAX << 1)
+#else
+/* For targets where UINT_MAX is the same as SIZE_MAX, use an invalid
+ alignment that's less than the maximum to elicit the same errors. */
+# define MAX_X_2 (ALIGN_MAX + 1)
+#endif
static void* p;
@@ -76,10 +89,6 @@ void test_arg2_non_const (int n, int a1)
of CHAR_BIT less than (1LLU << 32) must be rejected. */
void test_arg2_non_pow2 (int n)
{
- p = __builtin_alloca_with_align (n, INT_MIN); /* { dg-error "must be a constant integer" } */
- p = __builtin_alloca_with_align (n, -1); /* { dg-error "must be a constant integer" } */
- p = __builtin_alloca_with_align (n, !1); /* { dg-error "must be a constant integer" } */
- p = __builtin_alloca_with_align (n, !0); /* { dg-error "must be a constant integer" } */
p = __builtin_alloca_with_align (n, 0); /* { dg-error "must be a constant integer" } */
p = __builtin_alloca_with_align (n, 1); /* { dg-error "must be a constant integer" } */
p = __builtin_alloca_with_align (n, 2); /* { dg-error "must be a constant integer" } */
@@ -100,11 +109,6 @@ void test_arg2_non_pow2 (int n)
p = __builtin_alloca_with_align (n, 33); /* { dg-error "must be a constant integer" } */
p = __builtin_alloca_with_align (n, 63); /* { dg-error "must be a constant integer" } */
p = __builtin_alloca_with_align (n, 65); /* { dg-error "must be a constant integer" } */
- p = __builtin_alloca_with_align (n, INT_MAX); /* { dg-error "must be a constant integer" } */
- p = __builtin_alloca_with_align (n, ~0U); /* { dg-error "must be a constant integer" } */
- p = __builtin_alloca_with_align (n, LONG_MAX); /* { dg-error "must be a constant integer" } */
- p = __builtin_alloca_with_align (n, ~0LU); /* { dg-error "must be a constant integer" } */
- p = __builtin_alloca_with_align (n, 1LLU << 34); /* { dg-error "must be a constant integer" } */
- p = __builtin_alloca_with_align (n, LLONG_MAX); /* { dg-error "must be a constant integer" } */
- p = __builtin_alloca_with_align (n, ~0LLU); /* { dg-error "must be a constant integer" } */
+ p = __builtin_alloca_with_align (n, SIZE_MAX); /* { dg-error "must be a constant integer" } */
+ p = __builtin_alloca_with_align (n, MAX_X_2); /* { dg-error "must be a constant integer" } */
}