diff options
author | Martin Sebor <msebor@redhat.com> | 2016-04-14 17:35:23 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2016-04-14 11:35:23 -0600 |
commit | d8747845fded660e09bab98470f77753a4216b6e (patch) | |
tree | 83cb3798bea28b1aa1cc72277814a9f1a15bffd0 /gcc/testsuite | |
parent | 851285595028bdbb0eed29766e6eece1a884138e (diff) | |
download | gcc-d8747845fded660e09bab98470f77753a4216b6e.zip gcc-d8747845fded660e09bab98470f77753a4216b6e.tar.gz gcc-d8747845fded660e09bab98470f77753a4216b6e.tar.bz2 |
PR c++/70652 - [6 Regression] r234966 causes bootstrap to fail
PR c++/70652 - [6 Regression] r234966 causes bootstrap to fail
Revert patch for c++/69517, c++/70019, and c++/70588.
From-SVN: r234981
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/ChangeLog | 14 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/ubsan/vla-1.c | 30 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1y/vla12.C | 99 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1y/vla13.C | 260 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1y/vla14.C | 48 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1y/vla3.C | 43 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/init/array24.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ubsan/vla-1.C | 5 |
8 files changed, 28 insertions, 473 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9cd0c6c..44f71b5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,17 @@ +2016-04-14 Martin Sebor <msebor@redhat.com> + + PR c++/69517 + PR c++/70019 + PR c++/70588 + * c-c++-common/ubsan/vla-1.c: Revert. + * g++.dg/cpp1y/vla11.C: Same. + * g++.dg/cpp1y/vla12.C: Same. + * g++.dg/cpp1y/vla13.C: Same. + * g++.dg/cpp1y/vla14.C: Same. + * g++.dg/cpp1y/vla3.C: Same. + * gcc/testsuite/g++.dg/init/array24.C: Same. + * g++.dg/ubsan/vla-1.C: Same. + 2016-04-14 Marek Polacek <polacek@redhat.com> Jan Hubicka <hubicka@ucw.cz> diff --git a/gcc/testsuite/c-c++-common/ubsan/vla-1.c b/gcc/testsuite/c-c++-common/ubsan/vla-1.c index 27ef110..52ade3a 100644 --- a/gcc/testsuite/c-c++-common/ubsan/vla-1.c +++ b/gcc/testsuite/c-c++-common/ubsan/vla-1.c @@ -87,24 +87,18 @@ fn12 (void) int main (void) { -#if __cplusplus -# define TRY(stmt) do { try { stmt; } catch (...) { } } while (0) -#else -# define TRY(stmt) stmt -#endif - - TRY (fn1 ()); - TRY (fn2 ()); - TRY (fn3 ()); - TRY (fn4 ()); - TRY (fn5 ()); - TRY (fn6 ()); - TRY (fn7 ()); - TRY (fn8 ()); - TRY (fn9 ()); - TRY (fn10 ()); - TRY (fn11 ()); - TRY (fn12 ()); + fn1 (); + fn2 (); + fn3 (); + fn4 (); + fn5 (); + fn6 (); + fn7 (); + fn8 (); + fn9 (); + fn10 (); + fn11 (); + fn12 (); return 0; } diff --git a/gcc/testsuite/g++.dg/cpp1y/vla12.C b/gcc/testsuite/g++.dg/cpp1y/vla12.C deleted file mode 100644 index f938f3b..0000000 --- a/gcc/testsuite/g++.dg/cpp1y/vla12.C +++ /dev/null @@ -1,99 +0,0 @@ -// Test to verify that variable length arrays the product of whose constant -// bounds overflows or exceeds the implementation-defined limit are diagnosed. -// { dg-do compile { target c++11 } } -// { dg-additional-options "-Wno-error=vla" } - -#define INT_MAX __INT_MAX__ -#define LONG_MAX __LONG_MAX__ -#define SIZE_MAX __SIZE_MAX__ - -typedef __SIZE_TYPE__ size_t; - -#define MAX (SIZE_MAX / 2) - -void test (int x) -{ - const size_t amax = MAX; - - // The following are valid and shouldn't elicit a bounds overflow warning. - { - char a [x][amax]; // { dg-warning "forbids" } - (void)a; - } - - { - char a [amax][x]; // { dg-warning "forbids" } - (void)a; - } - - // The following is invalid and should be diagnosed. Unfortunately, - // when the VLA maximum size is (SIZE_MAX / 2), G++ also issues - // a (bogus) -Woverflow because it computes the array bound in - // a signed type (ssize_t) instead of size_t, in addition to - // rejecting the declaration with error: size of array ‘a’ is too - // large, before the VLA constant bound check has had a chance to - // see it. So the test is disabled. - // { - // char a [x][amax + 1]; - // (void)a; - // } - - { - char a [x][x][amax]; // { dg-warning "forbids" } - (void)a; - } - - { - char a [x][amax][x]; // { dg-warning "forbids" } - (void)a; - } - - { - char a [amax][x][x]; // { dg-warning "forbids" } - (void)a; - } - - { - char a [2][x][amax]; // { dg-warning "forbids|exceeds maximum" } - (void)a; - } - - { - // Unfortunately, the following is rejected with a different error - // earlier during parsing and before the VLA checking gets to see - // it: error: size of array ‘a’ is too large - // Ditto for other multidimensional VLAs where the overflow occurs - // in the computation of the product of adjacent constant bounds. - // char a [x][amax][amax]; - // char b [x][2][amax]; - // That error above also leads to the following error when using - // the variable below. - // error:’ was not declared in this scope - // (void)a; - } - - { - char a [amax][x][amax]; // { dg-warning "forbids|exceeds maximum" } - (void)a; - } - - { - char a [amax][amax][x]; // { dg-warning "forbids|exceeds maximum" } - (void)a; - } - - { - struct A256 { __attribute__ ((aligned (256))) char a; }; - - enum { - M = 1024, - N = MAX / (sizeof (A256) * M) - }; - - A256 a [x][M][x][N]; // { dg-warning "forbids" } - (void)a; - - A256 b [2][x][M][x][N]; // { dg-warning "forbids|exceeds maximum" } - (void)b; - } -} diff --git a/gcc/testsuite/g++.dg/cpp1y/vla13.C b/gcc/testsuite/g++.dg/cpp1y/vla13.C deleted file mode 100644 index d473a63..0000000 --- a/gcc/testsuite/g++.dg/cpp1y/vla13.C +++ /dev/null @@ -1,260 +0,0 @@ -// PR c++/70019 - VLA size overflow not detected -// Runtime test to verify that attempting to initialize a VLA with a string -// or character array that's longer than the non-constant (runtime) bound -// of the VLA causes an exception to be thrown. For a compile-time version -// of the test see vla14.C. - -// { dg-do run { target c++11 } } -// { dg-additional-options "-Wno-vla" } - -#pragma GCC diagnostic ignored "-Wvla" - -#define SIZE_MAX __SIZE_MAX__ - -// The size of the largest allowed VLA in bytes. Bigger objects -// cause an exception to be thrown. Unless the maximum size is -// obscenely large, smaller objects should be successfully created -// provided there's enough stack space. See TEST_NEAR_VLA_MAX_SIZE -// below. -#define MAX (__SIZE_MAX__ / 2) - -// Define to non-zero to exercise very large VLAs with size just -// below the implementation-defined maximum. -#define TEST_NEAR_VLA_MAX_SIZE 0 - -// Define to zero to enable tests that cause an ICE due to c++/58646. -#define BUG_58646 1 - -// Define to zero to enable tests that cause an ICE due to c++/69487. -#define BUG_69487 1 - -// Helper macro to make it possible to pass as one multpile arguments -// to another macro. -#define Init(...) __VA_ARGS__ - -typedef __SIZE_TYPE__ size_t; - -// Incremented for each test failure. -int fail; - -// Used to convert a constant array dimension to a non-constant one. -template <class T> -T d (T n) -{ - return n; -} - -// Verify either that an expected exception has been thrown or that -// one hasn't been thrown if one isn't expected. -int __attribute__ ((noclone, noinline)) -sink (void *p, int line, bool expect, const char *expr) -{ - if (!p != expect) - { - __builtin_printf ("line %i: Assertion failed: '%s': " - "exception unexpectedly %sthrown\n", - line, expr, !p ? "" : "not "); - ++fail; - } - else - { -#if defined DEBUG && DEBUG - __builtin_printf ("line %i: Assertion passed: '%s': " - "exception %sthrown as expected\n", - line, expr, !p ? "" : "not "); -#endif - } - return 0; -} - -template <class T, int> -int test (); - -#define _CAT(name, line) name ## line -#define CAT(name, line) _CAT (name, line) - -#define STR(...) #__VA_ARGS__ - -// Macro to define a unique specialization of a function template to -// exercise a VLA of type T, rank N, with dimensions given by Dims -// and initializer Init. Expect is true when the VLA initialization -// is expected to trigger an exception. -// The macro creates a unique global dummy int object and initializes -// it with the result of the function. The dummy object servers no -// other purpose but to call the function. The function verifies -// the expected postconditions. -#define TEST(T, Dims, Init, Expect) \ - template <> \ - int test<T, __LINE__>() \ - { \ - const char str[] = "char a" #Dims " = { " STR (Init) " }"; \ - try { \ - T a Dims = { Init }; \ - return sink (a, __LINE__, Expect, str); \ - } \ - catch (...) { \ - return sink (0, __LINE__, Expect, str); \ - } \ - } \ - const int CAT (dummy, __LINE__) = test<T, __LINE__>() - - -// Create and run a test function exercising a VLA definition -// +-- Element Type -// | +-- VLA Dimensions -// | | +-- VLA Initializer -// | | | -// | | | +-- Expect Exception -// | | | | -// V V V V -TEST (char, [d(-1)], "", true); - -TEST (char, [d(0)], "", true); -TEST (char, [d(0)], (""), true); - -TEST (char, [d(1)], "", false); -TEST (char, [d(1)], (""), false); - -TEST (char, [d(1)], "1", true); -TEST (char, [d(1)], ("1"), true); - -TEST (char, [d(1)], "12", true); -TEST (char, [d(1)], "1234567890", true); - -TEST (char, [d(2)], "", false); -TEST (char, [d(2)], (""), false); - -TEST (char, [d(2)], "1", false); -TEST (char, [d(2)], "12", true); -TEST (char, [d(2)], "123", true); -TEST (char, [d(2)], "1234567890", true); - -TEST (char, [d(3)], "", false); -TEST (char, [d(3)], "1", false); -TEST (char, [d(3)], "12", false); -TEST (char, [d(3)], "123", true); -TEST (char, [d(3)], "1234", true); -TEST (char, [d(3)], "1234567890", true); - -#if TEST_NEAR_VLA_MAX_SIZE - -# if !BUG_69487 -// The following crash due to c++/69487. -TEST (char, [d(MAX)], "", false); -TEST (char, [d(MAX)], "1", false); -TEST (char, [d(MAX)], "12", false); -TEST (char, [d(MAX)], "1234567890", false); -# endif - -TEST (char, [d(MAX)], Init (), false); -TEST (char, [d(MAX)], Init (1), false); -TEST (char, [d(MAX)], Init (1, 2), false); -TEST (char, [d(MAX)], Init (1, 2, 3, 4, 5, 6, 7, 8, 9, 0), false); -#endif - -TEST (char, [d(SIZE_MAX / 2 + 1)], "", true); -TEST (char, [d(SIZE_MAX - 2)], "", true); -TEST (char, [d(SIZE_MAX - 1)], "", true); - -TEST (wchar_t, [d(1)], L"", false); -TEST (wchar_t, [d(1)], (L""), false); -TEST (wchar_t, [d(1)], L"1", true); -TEST (wchar_t, [d(1)], L"12", true); -TEST (wchar_t, [d(1)], L"1234567890", true); - -TEST (wchar_t, [d(2)], L"", false); -TEST (wchar_t, [d(2)], L"1", false); -TEST (wchar_t, [d(2)], L"12", true); -TEST (wchar_t, [d(2)], L"123", true); -TEST (wchar_t, [d(2)], L"1234567890", true); - -TEST (char, [d(1)][d(1)], Init (""), false); -TEST (char, [1] [d(1)], Init (""), false); -TEST (char, [d(1)][1], Init (""), false); - -TEST (char, [d(1)][d(1)], Init ("1"), true); - -// The following is accepted at compile time but throws an exception -// at runtime since in C++ a one-element array cannot be initialized -// with a string literal of length one because there isn't room for -// the terminating NUL -TEST (char, [1][d(1)], Init ("1"), true); - -// The following is rejected at compile-time since a one-element array -// cannot be initialized with a string literal of length one because -// there isn't room for the terminating NUL (see vla14.C). -// TEST (char, [d(1)][1], Init ("1"), false); - -TEST (char, [d(1)][d(1)], Init ("12"), true); -TEST (char, [d(1)][d(1)], Init ("1", "2"), true); -TEST (char, [d(1)][d(1)], Init ("1", "23"), true); - -TEST (char, [d(2)][d(2)], Init ("", ""), false); -TEST (char, [d(2)][d(2)], Init ("", "1"), false); -TEST (char, [d(2)][d(2)], Init ("1", ""), false); -TEST (char, [d(2)][d(2)], Init ("1", "1"), false); -TEST (char, [2][d(2)], Init ("", "1"), false); -TEST (char, [2][d(2)], Init ("1", ""), false); -TEST (char, [2][d(2)], Init ("1", "1"), false); -TEST (char, [d(2)][2], Init ("", "1"), false); -TEST (char, [d(2)][2], Init ("1", ""), false); -TEST (char, [d(2)][2], Init ("1", "1"), false); - -TEST (char, [2][d(2)], Init ("1", "23"), true); -TEST (char, [d(2)][d(2)], Init ("1", "23"), true); -TEST (char, [d(2)][d(2)], Init ("1", "23"), true); -TEST (char, [d(2)][d(2)], Init ("12","3"), true); - -#if TEST_NEAR_VLA_MAX_SIZE -# if !BUG_69487 - // The following crash due to c++/69487. -TEST (char, [1][d(MAX)], Init (""), false); -TEST (char, [1][d(MAX)], Init ("1"), false); -TEST (char, [1][d(MAX)], Init ("12"), false); -TEST (char, [1][d(MAX)], Init ("1234567890"), false); -# endif - -# if !BUG_58646 -// The following causes an ICE due to c++/58646. -TEST (char, [1][d(MAX)], Init (), false); -# endif - -TEST (char, [1][d(MAX)], Init ({1}), false); -TEST (char, [1][d(MAX)], Init ({1, 2}), false); -TEST (char, [1][d(MAX)], Init ({1, 2, 3}), false); -TEST (char, [1][d(MAX)], Init ({1, 2, 3, 4, 5, 6, 7, 8, 9, 0}), false); - -TEST (char, [d(MAX)][1], Init ({1}), false); -TEST (char, [d(MAX)][1], Init ({1}, {2}), false); -TEST (char, [d(MAX)][1], Init ({1}, {2}, {3}), false); -TEST (char, [d(MAX)][1], Init ({1}, {2}, {3}, {4}, {5}, - {6}, {7}, {8}, {9}, {0}), false); -#endif // TEST_NEAR_VLA_MAX_SIZE - -// The following are expected to throw due to excessive size. -TEST (char, [2][d(MAX)], Init ({1}), true); -TEST (char, [2][d(MAX)], Init ({1, 2}), true); -TEST (char, [2][d(MAX)], Init ({1}, {2}), true); -TEST (char, [2][d(MAX)], Init ({1, 2}, {3, 4}), true); -TEST (char, [2][d(MAX)], Init ({1, 2, 3}, {4, 5, 6}), true); -TEST (char, [2][d(MAX)], Init ({1, 2, 3, 4}, {5, 6, 7, 8}), true); - -TEST (char, [d(MAX)][2], Init ({1}), true); -TEST (char, [d(MAX)][2], Init ({1, 2}), true); -TEST (char, [d(MAX)][2], Init ({1}, {2}), true); -TEST (char, [d(MAX)][2], Init ({1, 2}, {3, 4}), true); -TEST (char, [d(MAX)][2], Init ({1, 2}, {3, 4}, {5, 6}), true); -TEST (char, [d(MAX)][2], Init ({1, 2}, {3, 4}, {5, 6}, {7, 8}), true); - -TEST (char, [d(MAX)][d(MAX)], Init ({1}), true); -TEST (char, [d(MAX)][d(MAX)], Init ({1, 2}), true); -TEST (char, [d(MAX)][d(MAX)], Init ({1}, {2}), true); -TEST (char, [d(MAX)][d(MAX)], Init ({1, 2}, {3, 4}), true); -TEST (char, [d(MAX)][d(MAX)], Init ({1, 2}, {3, 4}, {5, 6}), true); -TEST (char, [d(MAX)][d(MAX)], Init ({1, 2}, {3, 4}, {5, 6}, {7, 8}), true); - -int main () -{ - if (fail) - __builtin_abort (); -} diff --git a/gcc/testsuite/g++.dg/cpp1y/vla14.C b/gcc/testsuite/g++.dg/cpp1y/vla14.C deleted file mode 100644 index 4a0e827..0000000 --- a/gcc/testsuite/g++.dg/cpp1y/vla14.C +++ /dev/null @@ -1,48 +0,0 @@ -// PR c++/70019 - VLA size overflow not detected -// Compile-time test to verify that attempting to initialize a VLA with -// a string that's longer than the VLA's constant bound is diagnosed at -// compile time. For a runtime version of the test see vla13.C. - -// { dg-do run } -// { dg-additional-options "-Wno-vla" } - - -void test (int n) -{ - char a1[n][1] = { { "a" } }; // { dg-error "initializer-string for array of chars is too long" } - (void)a1; - - char a2[1][n] = { { "a" } }; - (void)a2; - - char a3[n][1][1] = { { { "a" } } }; // { dg-error "initializer-string for array of chars is too long" } - (void)a3; - - char a4[1][1][n] = { { { "a" } } }; - (void)a4; - - char a5[1][n][1] = { { { "a" } } }; // { dg-error "initializer-string for array of chars is too long" } - (void)a5; - - char a6[n][1][n] = { { { "a" } } }; - (void)a6; - - - wchar_t a7[n][1] = { { L"a" } }; // { dg-error "initializer-string for array of chars is too long" } - (void)a7; - - wchar_t a8[1][n] = { { L"a" } }; - (void)a8; - - wchar_t a9[n][1][1] = { { { L"a" } } }; // { dg-error "initializer-string for array of chars is too long" } - (void)a9; - - wchar_t a10[1][1][n] = { { { L"a" } } }; - (void)a10; - - wchar_t a11[][n][1] = { { { L"a" } } }; // { dg-error "initializer-string for array of chars is too long" } - (void)a11; - - wchar_t a12[n][1][n] = { { { L"a" } } }; - (void)a12; -} diff --git a/gcc/testsuite/g++.dg/cpp1y/vla3.C b/gcc/testsuite/g++.dg/cpp1y/vla3.C deleted file mode 100644 index 9b2d6b307..0000000 --- a/gcc/testsuite/g++.dg/cpp1y/vla3.C +++ /dev/null @@ -1,43 +0,0 @@ -// Test for throwing bad_array_length on invalid array length. -// { dg-do run { target c++14 } } -// { dg-additional-options "-Wno-vla" } - -namespace std -{ -struct exception -{ - virtual ~exception (); - virtual const char* what () const throw (); -}; -} - -int f(int i) -{ - int ar[i]{1,2,3,4}; - return ar[i-1]; -} - -void g(int i) -{ - int ar[i]; - ar[0] = 42; -} - -int main() -{ - int ok = 0; - f(4); // OK - try { - f(3); // too small - } - catch (std::exception &e) { - ++ok; - } - try { g(-24); } // negative - catch (std::exception &e) { - ++ok; - } - - if (ok != 2) - __builtin_abort (); -} diff --git a/gcc/testsuite/g++.dg/init/array24.C b/gcc/testsuite/g++.dg/init/array24.C index fc10c0a..2d72df4 100644 --- a/gcc/testsuite/g++.dg/init/array24.C +++ b/gcc/testsuite/g++.dg/init/array24.C @@ -3,5 +3,5 @@ void foo(int i) { - int x[][i] = { { 0 } }; + int x[][i] = { 0 }; } diff --git a/gcc/testsuite/g++.dg/ubsan/vla-1.C b/gcc/testsuite/g++.dg/ubsan/vla-1.C index 374c80a..311cdb1 100644 --- a/gcc/testsuite/g++.dg/ubsan/vla-1.C +++ b/gcc/testsuite/g++.dg/ubsan/vla-1.C @@ -1,8 +1,5 @@ // { dg-do run } -// Disable exceptions to prevent the erroneous initializer from -// throwing before the sanitizer instrumentation has detected -// the problem. -// { dg-options "-Wno-vla -fno-exceptions -fsanitize=undefined" } +// { dg-options "-Wno-vla -fsanitize=undefined" } // { dg-output "index 1 out of bounds" } void f(int i) { |