From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8479 invoked by alias); 9 Oct 2003 22:51:37 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 8334 invoked from network); 9 Oct 2003 22:51:35 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sources.redhat.com with SMTP; 9 Oct 2003 22:51:35 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.11.6/8.11.6) with ESMTP id h99MpZM18814 for ; Thu, 9 Oct 2003 18:51:35 -0400 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [172.16.52.156]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id h99MpYc10579 for ; Thu, 9 Oct 2003 18:51:34 -0400 Received: from localhost.redhat.com (devserv.devel.redhat.com [172.16.58.1]) by pobox.corp.redhat.com (8.12.8/8.12.8) with ESMTP id h99MpYdT012389; Thu, 9 Oct 2003 18:51:34 -0400 Received: by localhost.redhat.com (Postfix, from userid 469) id 4ED302CCB7; Thu, 9 Oct 2003 17:14:54 -0400 (EDT) From: Elena Zannoni MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16261.53197.951881.194874@localhost.redhat.com> Date: Thu, 09 Oct 2003 22:51:00 -0000 To: vinschen@redhat.com, gdb-patches@sources.redhat.com Subject: Re: [RFA] sh-tdep.c (sh_use_struct_convention): Restructure and fix In-Reply-To: <20031004113939.GK11435@cygbert.vinschen.de> References: <20031004113939.GK11435@cygbert.vinschen.de> X-SW-Source: 2003-10/txt/msg00331.txt.bz2 Corinna Vinschen writes: > 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. > I just added a detailed comment. Does that match what you implemented? I'd prefer the use of 'aggregate' instead of 'struct' in your comments. > 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. > Is there a test case that was failing? If not, it should be added. > 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) Can you just say len == 1 or len == 2 so that it matches your comment? Wait, this contradicts what the comments I just added say: For example, a 2-byte aligned structure with size 2 bytes has the same size and alignment as a short int, and will be returned in R0. Which is correct? > + 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) I am not sure I understand this one, that's why asked a pointer to a test case. It seems to contradict the following, i.e. it should still be in registers, or maybe I don't understand the language: When an aggregate type is returned in R0 and R1, R0 contains the first four bytes of the aggregate, and R1 contains the remainder. If the size of the aggregate type is not a multiple of 4 bytes, the aggregate is tail-padded up to a multiple of 4 bytes. The value of the padding is undefined. elena > + 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.