From 050273662d97139eefd4ead154b7a3ee78af0b54 Mon Sep 17 00:00:00 2001 From: msebor Date: Wed, 24 Feb 2016 17:04:03 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@233677 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/ext/builtin_alloca.C | 34 +++++++++++++++++-------------- gcc/testsuite/gcc.dg/builtins-68.c | 34 +++++++++++++++++-------------- 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 + + * 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 Charles Baylis 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" } */ } -- 2.7.4