]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Avoid making unportable assumptions about the relationship between SIZE_MAX
authorMartin Sebor <msebor@redhat.com>
Wed, 24 Feb 2016 17:04:03 +0000 (17:04 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Wed, 24 Feb 2016 17:04:03 +0000 (10:04 -0700)
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

gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/builtin_alloca.C
gcc/testsuite/gcc.dg/builtins-68.c

index 7db6b61f86ae4c30b270c6a0eba822e25aab9dd1..b215d09080e4b05fc2d17108a1c583e3774c12d9 100644 (file)
@@ -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>
 
index 10a9bdce474b22d22fb6ec44b598a83e2657878c..7a0d331ced064ff6fcb93f49cc6b1a594e7f7250 100644 (file)
@@ -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.
index d2e65d08060191d096eeb54a5b05b1b784a827c7..c0cc1ebdcb9ab01a4771d5e5131ba0fdea91919c 100644 (file)
@@ -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" } */
 }