This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] pass C++ decimal classes same as scalars
- From: Jason Merrill <jason at redhat dot com>
- To: janis187 at us dot ibm dot com
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 13 Jan 2010 20:51:02 -0500
- Subject: Re: [PATCH] pass C++ decimal classes same as scalars
- References: <1259019284.13735.17.camel@janis-laptop>
On 11/23/2009 06:34 PM, Janis Johnson wrote:
* tree.h (TYPE_TRANSPARENT_UNION): Replace with ...
(TYPE_PASS_AS_TRANSPARENT): this, for union and record.
Maybe "TYPE_TRANSPARENT_AGGR"? And change the field name as well.
+ /* If a record should be passed the same as its first (and only) member
+ don't pass it as an aggregate. */
+ if (TREE_CODE (type) == RECORD_TYPE&& TYPE_PASS_AS_TRANSPARENT (type))
+ return 0;
What if its field is itself an aggregate? Unlikely, but we might as
well recurse.
+ /* According to the C++ ABI, some library classes are passed the
+ same as the scalar type of their single member and use the same
+ mangling. */
+ if (TREE_CODE (type) == RECORD_TYPE&& TYPE_PASS_AS_TRANSPARENT (type))
+ type = TREE_TYPE (TYPE_FIELDS (type));
I'm nervous about assuming that the first element of TYPE_FIELDS is a
FIELD_DECL (rather than TYPE_DECL or VAR_DECL), though I know calls.c
does the same thing. Maybe add a function get_first_field?
+ /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
+ are passed the same as decimal scalar types. */
+ if (TREE_CODE (t) == RECORD_TYPE)
+ {
+ const char *n = type_as_string (t, TFF_CLASS_KEY_OR_ENUM);
+ if ((strcmp (n, "class std::decimal::decimal32") == 0)
+ || (strcmp (n, "class std::decimal::decimal64") == 0)
+ || (strcmp (n, "class std::decimal::decimal128") == 0))
+ TYPE_PASS_AS_TRANSPARENT (t) = 1;
+ }
Relying on the formatting from type_as_string seems a bit fragile,
though I suppose in this case it's unlikely to change.
Jason