https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79671

--- Comment #73 from rguenther at suse dot de <rguenther at suse dot de> ---
On Mon, 27 Mar 2017, jason at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79671
> 
> --- Comment #72 from Jason Merrill <jason at gcc dot gnu.org> ---
> (In reply to rguent...@suse.de from comment #69)
> > As I noted elsewhere union members in C++ seem to be pure convenience and a
> > union contains implicit members of all types (well, somehow factor in
> > alignment).  Of course Jason argues char[] is special and introduces this
> > but I can't find text anywhere to support that or require char[] and not,
> > say int[].
> 
> This is clarified somewhat in C++17, by
> 
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0137r1.html
> 
> Note that this wording makes only unsigned char[] special, not signed or plain
> char[].

Ah, I remember seeing this.  So this introduces object size as a way
to allow some TBAA to happen.  Specifically it forbids creating
a series of float sub-objects inside a char[sizeof(float)*4] sub-object
due to "there is no smaller array object that satisfies these 
constraints"(?).  One would need to use sth like

  struct { unsigned char storage[sizeof(float)]; } st[4];

to work around that "limitation".  Not if it's really possible to
take advantage of that size restriction in alias analysis though...

If we'd want to implement sth like this in the middle-end I'd suggest
to force frontends to mark these storage areas in some way.
In the C++ case all unsigned char arrays -- does the "array of N unsigned char"
wording allow for struct C {} to be created within a unsigned char
(no array!) member or has it to be unsigned char[1]?).

I suggest sth like

/* For an ARRAY_TYPE, indicates that when the dynamic type of the storage
   it provides differs from the declard type it is still valid to access
   it via the declared type or the type of a containing object.  */
#define ARRAY_TYPE_IS_STORAGE (NODE) \
  (ARRAY_TYPE_CHECK (NODE)->type_common.array_type_is_storage)

Reply via email to