summaryrefslogtreecommitdiff
path: root/gcc/stor-layout.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2018-01-16 16:08:32 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2018-01-16 16:08:32 +0100
commit38943500babbfda935c1108a16ecbb03cb1a33e8 (patch)
tree8c56b282c07c85b373c44f431ced983c5995758c /gcc/stor-layout.c
parent42b394ff00b100d2c968db6478c87a259333ccec (diff)
re PR c/83844 (ICE with warn_if_not_aligned attribute)
PR c/83844 * stor-layout.c (handle_warn_if_not_align): Use byte_position and multiple_of_p instead of unchecked tree_to_uhwi and UHWI check. If off is not INTEGER_CST, issue a may not be aligned warning rather than isn't aligned. Use isn%'t rather than isn't. * fold-const.c (multiple_of_p) <case BIT_AND_EXPR>: Don't fall through into MULT_EXPR. <case MULT_EXPR>: Improve the case when bottom and one of the MULT_EXPR operands are INTEGER_CSTs and bottom is multiple of that operand, in that case check if the other operand is multiple of bottom divided by the INTEGER_CST operand. * gcc.dg/pr83844.c: New test. From-SVN: r256745
Diffstat (limited to 'gcc/stor-layout.c')
-rw-r--r--gcc/stor-layout.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index 0f65e166411..8c415ebb6ac 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -1150,12 +1150,16 @@ handle_warn_if_not_align (tree field, unsigned int record_align)
warning (opt_w, "alignment %u of %qT is less than %u",
record_align, context, warn_if_not_align);
- unsigned HOST_WIDE_INT off
- = (tree_to_uhwi (DECL_FIELD_OFFSET (field))
- + tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field)) / BITS_PER_UNIT);
- if ((off % warn_if_not_align) != 0)
- warning (opt_w, "%q+D offset %wu in %qT isn't aligned to %u",
- field, off, context, warn_if_not_align);
+ tree off = byte_position (field);
+ if (!multiple_of_p (TREE_TYPE (off), off, size_int (warn_if_not_align)))
+ {
+ if (TREE_CODE (off) == INTEGER_CST)
+ warning (opt_w, "%q+D offset %E in %qT isn%'t aligned to %u",
+ field, off, context, warn_if_not_align);
+ else
+ warning (opt_w, "%q+D offset %E in %qT may not be aligned to %u",
+ field, off, context, warn_if_not_align);
+ }
}
/* Called from place_field to handle unions. */