https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43798
--- Comment #14 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Acjusted patch that uses build_aligned_type instead of doing it on its own. --- gcc/stor-layout.c.jj 2019-01-01 12:37:17.296972670 +0100 +++ gcc/stor-layout.c 2019-03-20 11:15:12.166935041 +0100 @@ -2547,13 +2547,32 @@ layout_type (tree type) large as the element alignment. */ if (TYPE_SIZE_UNIT (element) && TREE_CODE (TYPE_SIZE_UNIT (element)) == INTEGER_CST + && !integer_zerop (TYPE_SIZE_UNIT (element))) + { /* If TYPE_SIZE_UNIT overflowed, then it is certainly larger than TYPE_ALIGN_UNIT. */ - && !TREE_OVERFLOW (TYPE_SIZE_UNIT (element)) - && !integer_zerop (TYPE_SIZE_UNIT (element)) - && compare_tree_int (TYPE_SIZE_UNIT (element), - TYPE_ALIGN_UNIT (element)) < 0) - error ("alignment of array elements is greater than element size"); + if (!TREE_OVERFLOW (TYPE_SIZE_UNIT (element)) + && compare_tree_int (TYPE_SIZE_UNIT (element), + TYPE_ALIGN_UNIT (element)) < 0) + error ("alignment of array elements is greater than " + "element size"); + if (TYPE_ALIGN_UNIT (element)) + { + unsigned align = (TREE_INT_CST_LOW (TYPE_SIZE_UNIT (element)) + & (TYPE_ALIGN_UNIT (element) - 1)); + align = least_bit_hwi (align); + if (align && align != TYPE_ALIGN_UNIT (element)) + { + /* If the size of the element is not a multiple of + alignment, lower the alignment of the elements of the + array, but keep the whole array alignment. */ + element + = build_aligned_type (element, align * BITS_PER_UNIT); + TREE_TYPE (type) = element; + TYPE_USER_ALIGN (type) = 1; + } + } + } break; }