Am Samstag, dem 18.07.2026 um 10:25 +0200 schrieb Eric Botcazou:
> > I think there's no ABI difference between QUAL_UNION_TYPE and UNION_TYPE.
> > There is just the opportunity to perform runtime checking when you
> > access <union>.x (assert 'x' is active) and you can access <union>,
> > magically getting the active member, but that would require some
> > polymorphism I guess.  I'm not actually sure how Ada uses it.
> 
> The run-time check is implemented in the front-end.  QUAL_UNION_TYPE is used 
> to drive layout (stor-layout.cc) and debug info generation (dwarf2out.cc).
> 
> > Basically each union member has a "is-this-active" predicate which can
> > refer to for example fields in an outer object via PLACEHODER_EXPRs.
> 
> Right, the predicate is DECL_QUALIFIER and it references the tag 
> (discriminant 
> in Ada parlance) via PLACEHODER_EXPRs.
> 
> > So sth like
> > 
> >  struct X {
> >    int tag;
> >    union {
> >       int a __attribute__((qual(tag == 1)));
> >       double b __attribute__((qual(tag == 2)));
> >    };
> >    int k;
> >  };
> > 
> > note I think the twist with the above example is that if the union is
> > a QUAL_UNION_TYPE then the actual size of a struct X object
> > depends on which union element is active, so an access to 'k'
> > would be of variable-offset.
> 
> Yes, QUAL_UNION_TYPE has dynamic size, unlike UNION_TYPE.

I guess you can't use them in arrays?

Martin


Reply via email to