Re: [PATCH] Classify non-POD struct types more or less correctly on AMD64

Daniel Jacobowitz
2004-03-09T15:39:45Z

On Sun, Jan 11, 2004 at 01:37:31PM +0100, Mark Kettenis wrote:
> That function just implements the rules for normal C structures. Th
> rules are a bit more complex than you say above, but that bit is
> implemented correctly in GDB. At least that's the intention. The
> decision to not pass certain C++ classes in registers is made
> somewhere else, most notably in cp/class.c:finish_struct_bits(), where
> TYPE_MODE is set to BLKmode, and TREE_ADDRESSABLE is set. Both
> conditions are enough to get the type returned in memory instead of
> registers. However, there are more places where TREE_ADDRESSABLE is
> tweaked.

Hi Mark,

As it happens I just ran into the same problem on ARM and on MIPS n32.
I don't have a patch yet, but I can excerpt code I'm using at the
moment:

+ /* This is... rough. If we have a non-trivial copy constructor or
+ destructor, use reference. This should be in common code. */
+ int i, j;
+ for (i = 0; i < TYPE_NFN_FIELDS (type); i++)
+ for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (type, i); j++)
+ {
+ struct fn_field *fn = TYPE_FN_FIELDLIST1 (type, i);
+ if (TYPE_FN_FIELD_ARTIFICIAL (fn, j))
+ continue;
+ if (TYPE_FN_FIELDLIST_NAME (type, i)[0] == '~')
+ return RETURN_VALUE_STRUCT_CONVENTION;
+ if (strncmp (TYPE_NAME (type),
+ TYPE_FN_FIELDLIST_NAME (type, i),
+ strlen (TYPE_NAME (type))) == 0
+ && (TYPE_FN_FIELDLIST_NAME (type, i)[strlen (TYPE_NAME (type))] == '\0'
+ || TYPE_FN_FIELDLIST_NAME (type, i)[strlen (TYPE_NAME (type))] == '<')
+ && TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (fn, j)) == 2
+ && TYPE_CODE (TYPE_FIELD_TYPE (TYPE_FN_FIELD_TYPE (fn, j), 1)) == TYPE_CODE_REF
+ && TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (TYPE_FN_FIELD_TYPE (fn, j), 1)) == type)
+ return RETURN_VALUE_STRUCT_CONVENTION;
+ }

This doesn't address everything that GCC does to change the
pass-by-invisible-reference/return-by-invisible-reference behavior, but
it's a pretty good start and fixes one test in the GDB testsuite. Note
that we can't implement the TYPE_FN_FIELD_ARTIFICIAL test with stabs.
This also doesn't handle anything about calling constructors or
destructors, which GDB just isn't set up for yet...

I don't know if this sort of information should be in the dwarf2
information somehow. It definitely is in the C++ GNU v3 ABI:
http://www.codesourcery.com/cxx-abi/abi.html#calls

I'm guessing that this is what the x86-64 ABI was referring to, rather
than the actual term POD.

--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer