On 2/17/21 1:56 PM, Jakub Jelinek wrote:
On Wed, Feb 17, 2021 at 01:38:56PM -0700, Martin Sebor wrote:
-       reftype = build_array_type_nelts (reftype, 1);
+       {
+         if (overaligned_type_p (reftype))
+           reftype = TYPE_MAIN_VARIANT (reftype);
+         reftype = build_array_type_nelts (reftype, 1);
+       }

Rather than complicating the logic in the caller (which is already
long and hard to follow) I'd suggest to consider changing
the build_zero_elt_array_type() helper to handle both kinds of arrays
(i.e., zero-length and otherwise), and strip the excess alignment
from reftype in it.  That will simplify the function.

That will mean the overaligned type checking will need to be done
even for the case where reftype was originally an ARRAY_TYPE and the code
just picks up an element type out of it (in that case it is known that it
will succeed).
And there is a question how to name it, build_array_type_nelts is already
taken and it might be confusing what this almost like build_array_type_nelts
but with extras differs from the tree.c function.

Anyway, can change it if you can suggest a good name...

How does build_printable_array_type sound?

Also, would using TYPE_MAIN_VARIANT whenever TYPE_USER_ALIGN is set
be a simpler solution?  (It might not be as refined as the test in
your patch but I don't think we'd be giving up too much by
the simplification.)

Martin

Reply via email to