diff options
author | Marek Polacek <polacek@redhat.com> | 2014-05-08 18:19:09 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2014-05-08 18:19:09 +0000 |
commit | 2793eeab54e1969b2c5d5bebd89519048402e05b (patch) | |
tree | 91105210787a491bfe8736eb9fa6b7e58c1e68c4 /gcc/c-family | |
parent | f827930ae282f8ae4bedf0a38dbc2fa99d2b3d08 (diff) | |
download | gcc-2793eeab54e1969b2c5d5bebd89519048402e05b.zip gcc-2793eeab54e1969b2c5d5bebd89519048402e05b.tar.gz gcc-2793eeab54e1969b2c5d5bebd89519048402e05b.tar.bz2 |
re PR c/61053 (_Alignas(long long) reduces alignment of long long)
PR c/61053
c-family/
* c-common.c (min_align_of_type): New function factored out from...
(c_sizeof_or_alignof_type): ...here.
* c-common.h (min_align_of_type): Declare.
c/
* c-decl.c (grokdeclarator): Use min_align_of_type instead of
TYPE_ALIGN_UNIT.
testsuite/
* gcc.dg/pr61053.c: New test.
From-SVN: r210230
Diffstat (limited to 'gcc/c-family')
-rw-r--r-- | gcc/c-family/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 36 | ||||
-rw-r--r-- | gcc/c-family/c-common.h | 1 |
3 files changed, 29 insertions, 15 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 06a1b14..fc84f31 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,5 +1,12 @@ 2014-05-08 Marek Polacek <polacek@redhat.com> + PR c/61053 + * c-common.c (min_align_of_type): New function factored out from... + (c_sizeof_or_alignof_type): ...here. + * c-common.h (min_align_of_type): Declare. + +2014-05-08 Marek Polacek <polacek@redhat.com> + PR c/61077 * c-common.c (check_main_parameter_types): Warn for _Atomic-qualified parameter type of main. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 33ad250..d7c85fc 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -4938,6 +4938,26 @@ c_common_get_alias_set (tree t) return -1; } +/* Return the least alignment required for type TYPE. */ + +unsigned int +min_align_of_type (tree type) +{ + unsigned int align = TYPE_ALIGN (type); + align = MIN (align, BIGGEST_ALIGNMENT); +#ifdef BIGGEST_FIELD_ALIGNMENT + align = MIN (align, BIGGEST_FIELD_ALIGNMENT); +#endif + unsigned int field_align = align; +#ifdef ADJUST_FIELD_ALIGN + tree field = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, + type); + field_align = ADJUST_FIELD_ALIGN (field, field_align); +#endif + align = MIN (align, field_align); + return align / BITS_PER_UNIT; +} + /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where the IS_SIZEOF parameter indicates which operator is being applied. The COMPLAIN flag controls whether we should diagnose possibly @@ -5016,21 +5036,7 @@ c_sizeof_or_alignof_type (location_t loc, size_int (TYPE_PRECISION (char_type_node) / BITS_PER_UNIT)); else if (min_alignof) - { - unsigned int align = TYPE_ALIGN (type); - align = MIN (align, BIGGEST_ALIGNMENT); -#ifdef BIGGEST_FIELD_ALIGNMENT - align = MIN (align, BIGGEST_FIELD_ALIGNMENT); -#endif - unsigned int field_align = align; -#ifdef ADJUST_FIELD_ALIGN - tree field = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, - type); - field_align = ADJUST_FIELD_ALIGN (field, field_align); -#endif - align = MIN (align, field_align); - value = size_int (align / BITS_PER_UNIT); - } + value = size_int (min_align_of_type (type)); else value = size_int (TYPE_ALIGN_UNIT (type)); } diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 57b7dce..d34d2bb 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -758,6 +758,7 @@ extern tree c_wrap_maybe_const (tree, bool); extern tree c_save_expr (tree); extern tree c_common_truthvalue_conversion (location_t, tree); extern void c_apply_type_quals_to_decl (int, tree); +extern unsigned int min_align_of_type (tree); extern tree c_sizeof_or_alignof_type (location_t, tree, bool, bool, int); extern tree c_alignof_expr (location_t, tree); /* Print an error message for invalid operands to arith operation CODE. |