> 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.
--
Eric Botcazou