From 9aa78eb08fb058149e7127b62e96b98420361d63 Mon Sep 17 00:00:00 2001 From: mpolacek Date: Tue, 8 Jul 2014 05:38:12 +0000 Subject: [PATCH] PR c/60226 * fold-const.c (round_up_loc): Change the parameter type. Remove assert. * fold-const.h (round_up_loc): Adjust declaration. * stor-layout.c (finalize_record_size): Check for too large types. * c-c++-common/pr60226.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@212346 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 8 ++++++++ gcc/fold-const.c | 3 +-- gcc/fold-const.h | 2 +- gcc/stor-layout.c | 5 +++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/c-c++-common/pr60226.c | 14 ++++++++++++++ 6 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/pr60226.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1e06ded53b3..edf3dc11d5e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2014-07-08 Marek Polacek + + PR c/60226 + * fold-const.c (round_up_loc): Change the parameter type. + Remove assert. + * fold-const.h (round_up_loc): Adjust declaration. + * stor-layout.c (finalize_record_size): Check for too large types. + 2014-07-07 Jan Hubicka * symtab.c: Include calls.h diff --git a/gcc/fold-const.c b/gcc/fold-const.c index d22eac15962..c57ac7bd1a9 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -16647,11 +16647,10 @@ fold_ignored_result (tree t) /* Return the value of VALUE, rounded up to a multiple of DIVISOR. */ tree -round_up_loc (location_t loc, tree value, int divisor) +round_up_loc (location_t loc, tree value, unsigned int divisor) { tree div = NULL_TREE; - gcc_assert (divisor > 0); if (divisor == 1) return value; diff --git a/gcc/fold-const.h b/gcc/fold-const.h index dcb97a17a31..3b5fd8476d6 100644 --- a/gcc/fold-const.h +++ b/gcc/fold-const.h @@ -144,7 +144,7 @@ extern tree combine_comparisons (location_t, enum tree_code, enum tree_code, extern void debug_fold_checksum (const_tree); extern bool may_negate_without_overflow_p (const_tree); #define round_up(T,N) round_up_loc (UNKNOWN_LOCATION, T, N) -extern tree round_up_loc (location_t, tree, int); +extern tree round_up_loc (location_t, tree, unsigned int); #define round_down(T,N) round_down_loc (UNKNOWN_LOCATION, T, N) extern tree round_down_loc (location_t, tree, int); extern tree size_int_kind (HOST_WIDE_INT, enum size_type_kind); diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index cfd436fe82b..19e7adbcbdd 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -1587,6 +1587,11 @@ finalize_record_size (record_layout_info rli) unpadded_size_unit = size_binop (PLUS_EXPR, unpadded_size_unit, size_one_node); + if (TREE_CODE (unpadded_size_unit) == INTEGER_CST + && !TREE_OVERFLOW (unpadded_size_unit) + && !valid_constant_size_p (unpadded_size_unit)) + error ("type %qT is too large", rli->t); + /* Round the size up to be a multiple of the required alignment. */ TYPE_SIZE (rli->t) = round_up (unpadded_size, TYPE_ALIGN (rli->t)); TYPE_SIZE_UNIT (rli->t) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2b5e354d79a..9940e724cb3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-07-08 Marek Polacek + + PR c/60226 + * c-c++-common/pr60226.c: New test. + 2014-07-07 Paul Thomas PR fortran/61459 diff --git a/gcc/testsuite/c-c++-common/pr60226.c b/gcc/testsuite/c-c++-common/pr60226.c new file mode 100644 index 00000000000..3a1c261fa93 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr60226.c @@ -0,0 +1,14 @@ +/* PR c/60226 */ +/* { dg-do compile } */ +/* { dg-options "-Wno-c++-compat" { target c } } */ + +typedef int __attribute__ ((aligned (1 << 28))) int28; +int28 foo[4] = {}; /* { dg-error "alignment of array elements is greater than element size" } */ +typedef int __attribute__ ((aligned (1 << 29))) int29; /* { dg-error "requested alignment is too large" } */ + +void +f (void) +{ + struct { __attribute__((aligned (1 << 28))) double a; } x1; + struct { __attribute__((aligned (1 << 29))) double a; } x2; /* { dg-error "requested alignment is too large" } */ +} -- 2.11.4.GIT