From 60a45536f1179f87632fb4f8c52ce0891f3a43a9 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Tue, 3 May 2011 08:48:00 +0000 Subject: [PATCH] c-decl.c (grokdeclarator): Instead of looking at TREE_OVERFLOW check if the constant fits in the index type. 2011-05-03 Richard Guenther * c-decl.c (grokdeclarator): Instead of looking at TREE_OVERFLOW check if the constant fits in the index type. * gcc.dg/large-size-array-5.c: New testcase. From-SVN: r173297 --- gcc/ChangeLog | 5 +++++ gcc/c-decl.c | 16 +++++++--------- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/large-size-array-5.c | 9 +++++++++ 4 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/large-size-array-5.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e4b35b7585f..aca7c221320 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2011-05-03 Richard Guenther + + * c-decl.c (grokdeclarator): Instead of looking at + TREE_OVERFLOW check if the constant fits in the index type. + 2011-05-03 Richard Sandiford * config/arm/neon.md (vec_load_lanes): New expanders, diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 9c6cc90d11a..008f4c65c76 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -5368,15 +5368,13 @@ grokdeclarator (const struct c_declarator *declarator, convert (index_type, size_one_node)); - /* If that overflowed, the array is too big. ??? - While a size of INT_MAX+1 technically shouldn't - cause an overflow (because we subtract 1), the - overflow is recorded during the conversion to - index_type, before the subtraction. Handling - this case seems like an unnecessary - complication. */ - if (TREE_CODE (itype) == INTEGER_CST - && TREE_OVERFLOW (itype)) + /* The above overflows when size does not fit + in index_type. + ??? While a size of INT_MAX+1 technically shouldn't + cause an overflow (because we subtract 1), handling + this case seems like an unnecessary complication. */ + if (TREE_CODE (size) == INTEGER_CST + && !int_fits_type_p (size, index_type)) { if (name) error_at (loc, "size of array %qE is too large", diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d9094f09c47..d15361c6b25 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-05-03 Richard Guenther + + * gcc.dg/large-size-array-5.c: New testcase. + 2011-05-03 Richard Sandiford * gcc.dg/vect/vect-strided-u16-i3.c: New test. diff --git a/gcc/testsuite/gcc.dg/large-size-array-5.c b/gcc/testsuite/gcc.dg/large-size-array-5.c new file mode 100644 index 00000000000..71ac47374f4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/large-size-array-5.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-Wno-overflow" } */ + +typedef __SIZE_TYPE__ size_t; + +extern char a[((size_t)-1 >> 1) + 1]; /* { dg-error "too large" } */ +extern char b[((size_t)-1 >> 1)]; +extern int c[(((size_t)-1 >> 1) + 1) / sizeof(int)]; /* { dg-error "too large" } */ +extern int d[((size_t)-1 >> 1) / sizeof(int)]; -- 2.30.2