This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Must TYPE_MODE of a UNION_TYPE be of MODE_INT class?
- From: Eric Botcazou <ebotcazou at adacore dot com>
- To: Jozef Lawrynowicz <jozef dot l at mittosystems dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 24 May 2018 21:13:58 +0200
- Subject: Re: Must TYPE_MODE of a UNION_TYPE be of MODE_INT class?
- References: <3115e5bc-cd54-24e8-727d-6e88b79f3f46@mittosystems.com>
> See stor-layout.c (compute_record_mode), particularly this section:
>
> /* If we only have one real field; use its mode if that mode's size
> matches the type's size. This only applies to RECORD_TYPE. This
> does not apply to unions. */
> if (TREE_CODE (type) == RECORD_TYPE && mode != VOIDmode
> && tree_fits_uhwi_p (TYPE_SIZE (type))
> && known_eq (GET_MODE_BITSIZE (mode), tree_to_uhwi (TYPE_SIZE
> (type))))
> ;
> else
> mode = mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1).else_blk ();
>
> Is there a reason the type of the union must be of MODE_INT class but a
> RECORD_TYPE with one field can have the class of it's single field?
Yes, ABIs that pass structures or unions in registers traditionally pass the
unions always in integer registers, whereas for structures it's dependent on
the types of the fields.
> Could anyone provide some insight on whether the TYPE_MODE of a union should
> stay as a MODE_INT class or if it would be acceptable for the TYPE_MODE to
> be other classes e.g. MODE_FLOAT?
No, I don't think we want to change that.
--
Eric Botcazou