> Here's the Correct Fix(tm). We may or may not decide to go for it because
> of concerns about ABI changes; in the latter case, any kludge that we'll
> put in place instead must be restricted to the cases caught by this patch.
>
>
> * stor-layout.c (compute_record_mode): Return BLKmode for a trailing
> array with size 0 or 1.
Revised version without the one-by-one error...
--
Eric Botcazou
Index: stor-layout.c
===================================================================
--- stor-layout.c (revision 205727)
+++ stor-layout.c (working copy)
@@ -1605,6 +1605,17 @@ compute_record_mode (tree type)
|| ! tree_fits_uhwi_p (DECL_SIZE (field)))
return;
+ /* As a GNU extension, we support out-of-bounds accesses for a trailing
+ array with size 0 or 1. In this case, the record type effectively
+ has variable size so it needs to have BLKmode. */
+ if (!DECL_CHAIN (field) && TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE)
+ {
+ tree domain_type = TYPE_DOMAIN (TREE_TYPE (field));
+ if (!TYPE_MAX_VALUE (domain_type)
+ || integer_zerop (TYPE_MAX_VALUE (domain_type)))
+ return;
+ }
+
/* If this field is the whole struct, remember its mode so
that, say, we can put a double in a class into a DF
register instead of forcing it to live in the stack. */