Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] sh-tdep.c (sh_use_struct_convention): Restructure and fix
@ 2003-10-04 11:39 Corinna Vinschen
  2003-10-04 15:54 ` Andrew Cagney
  2003-10-09 22:51 ` Elena Zannoni
  0 siblings, 2 replies; 20+ messages in thread
From: Corinna Vinschen @ 2003-10-04 11:39 UTC (permalink / raw)
  To: gdb-patches

Hi,

the below patch straightens out sh_use_struct_convention() so that it
allows a far better readability than before, especially by allowing
a bunch of comments spread out through the code.

Additionally it fixes one bug:  A struct of lenght 4 bytes, which
consists of only a bitfield, is returned in register r0, not on the
stack using the struct convention.  So far, GDB got that wrong.

Corinna

	* sh-tdep.c (sh_use_struct_convention): Clean up to have a
	more readable code.  Accomodate 4 byte structs with 4 byte sized
	first field (e.g. bitfields).

Index: sh-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/sh-tdep.c,v
retrieving revision 1.145
diff -u -p -r1.145 sh-tdep.c
--- sh-tdep.c	3 Oct 2003 08:13:37 -0000	1.145
+++ sh-tdep.c	4 Oct 2003 11:32:00 -0000
@@ -565,8 +565,25 @@ sh_use_struct_convention (int gcc_p, str
 {
   int len = TYPE_LENGTH (type);
   int nelem = TYPE_NFIELDS (type);
-  return ((len != 1 && len != 2 && len != 4 && len != 8) || nelem != 1) &&
-    (len != 8 || TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)) != 4);
+
+  /* Non-power of 2 length types and types bigger than 8 bytes (which don't
+     fit in two registers anyway) use struct convention.  */
+  if (len != 1 && len != 2 && len != 4 && len != 8)
+    return 1;
+  /* Structs with more than 1 fields use struct convention, if...  */
+  if (nelem != 1)
+    {
+      /* ... they are 1 or 2 bytes in size (e.g. struct of two chars)... */
+      if (len != 4 && len != 8)
+	return 1;
+      /* ... or, if the struct is 4 or 8 bytes and the first field is
+	 not of size 4 bytes.  Note that this also covers structs with
+	 bitfields. */
+      if (TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)) != 4)
+	return 1;
+    }
+  /* Otherwise return in registers.  */
+  return 0;
 }
 
 /* Extract from an array REGBUF containing the (raw) register state

-- 
Corinna Vinschen
Cygwin Developer
Red Hat, Inc.


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2003-10-11 20:05 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-04 11:39 [RFA] sh-tdep.c (sh_use_struct_convention): Restructure and fix Corinna Vinschen
2003-10-04 15:54 ` Andrew Cagney
2003-10-04 17:04   ` Kevin Buettner
2003-10-04 17:35     ` Andrew Cagney
2003-10-04 18:13       ` Kevin Buettner
2003-10-06 16:31         ` Andrew Cagney
2003-10-04 18:08   ` Corinna Vinschen
2003-10-06 15:52     ` Andrew Cagney
2003-10-07 14:52       ` Corinna Vinschen
2003-10-08 17:39         ` Andrew Cagney
2003-10-09 22:51     ` Elena Zannoni
2003-10-11 20:05       ` Andrew Cagney
2003-10-09 22:51 ` Elena Zannoni
2003-10-10  7:29   ` Corinna Vinschen
2003-10-10 15:01     ` Corinna Vinschen
2003-10-10 16:32       ` Elena Zannoni
2003-10-10 16:59         ` Corinna Vinschen
2003-10-10 17:56           ` Elena Zannoni
2003-10-10 19:14             ` Corinna Vinschen
2003-10-10 16:28     ` Elena Zannoni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox