From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18188 invoked by alias); 28 Feb 2008 19:15:45 -0000 Received: (qmail 18175 invoked by uid 22791); 28 Feb 2008 19:15:43 -0000 X-Spam-Check-By: sourceware.org Received: from NaN.false.org (HELO nan.false.org) (208.75.86.248) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 28 Feb 2008 19:15:19 +0000 Received: from nan.false.org (localhost [127.0.0.1]) by nan.false.org (Postfix) with ESMTP id 72F2F983A1; Thu, 28 Feb 2008 19:15:17 +0000 (GMT) Received: from caradoc.them.org (22.svnf5.xdsl.nauticom.net [209.195.183.55]) by nan.false.org (Postfix) with ESMTP id 4B2C898140; Thu, 28 Feb 2008 19:15:17 +0000 (GMT) Received: from drow by caradoc.them.org with local (Exim 4.69) (envelope-from ) id 1JUoDs-0002UU-KG; Thu, 28 Feb 2008 14:15:16 -0500 Date: Thu, 28 Feb 2008 19:39:00 -0000 From: Daniel Jacobowitz To: Aleksandar Ristovski Cc: gdb-patches@sourceware.org Subject: Re: [patch] fix for c++/2416 Message-ID: <20080228191516.GA8975@caradoc.them.org> Mail-Followup-To: Aleksandar Ristovski , gdb-patches@sourceware.org References: <47C5A5EE.6070107@qnx.com> <20080227193546.GA11796@caradoc.them.org> <47C5BE84.7050803@qnx.com> <20080227200019.GB12434@caradoc.them.org> <47C5D138.6020909@qnx.com> <20080227220659.GE14556@caradoc.them.org> <47C70319.4050804@qnx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <47C70319.4050804@qnx.com> User-Agent: Mutt/1.5.17 (2007-12-11) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-02/txt/msg00487.txt.bz2 On Thu, Feb 28, 2008 at 01:53:13PM -0500, Aleksandar Ristovski wrote: > See revisited diff (attached). Also, please find attached the testcase > diff, I added check for reference casting. Do I need to provide change log > for tests too? The testsuite changes look fine but do need a changelog; that goes in testsuite/ChangeLog. > NOTE: value_as_address does *not* behave as you described, if passed in a > REF to STRUCT, it will coerce_ref, that is ok, but then it will pass > coerced value to unpack_long which doesn't know what to do with a STRUCT > (which is why I had that confusing code you and Michael complained about). That's what I was trying to describe, sorry if it was unclear. There's value_addr, which takes the address of its argument - give it a struct or a struct reference, get back a struct pointer. Then there's value_as_address, which tries to interpret its argument as an address. Give it a pointer, get back the pointer as a CORE_ADDR. Giving it a struct doesn't do anything useful. > @@ -1985,8 +1985,18 @@ evaluate_subexp_standard (struct type *e > arg1 = evaluate_subexp (type, exp, pos, noside); > if (noside == EVAL_SKIP) > goto nosideret; > - if (type != value_type (arg1)) > - arg1 = value_cast (type, arg1); > + if (type != value_type (arg1)) > + { > + if (TYPE_CODE (value_type (arg1)) == TYPE_CODE_REF > + && TYPE_CODE (type) == TYPE_CODE_REF) > + arg1 = value_cast_pointers (type, arg1); > + else if (TYPE_CODE (value_type (arg1)) != TYPE_CODE_REF > + && TYPE_CODE (type) != TYPE_CODE_REF) > + arg1 = value_cast (type, arg1); > + else /* We can not do much here. */ > + error (_("Attempt to cast to reference type from non-reference "\ > + "type or vice versa.")); > + } > return arg1; > > case UNOP_MEMVAL: There's nothing wrong with casting a reference to a non-reference; that coerces the reference. Also you have to beware typedefs. enum type_code code1, code2; code1 = TYPE_CODE (check_typedef (value_type (arg1))); code2 = TYPE_CODE (check_typedef (value_type (arg2))); if (code1 == TYPE_CODE_REF && code2 == TYPE_CODE_REF) arg1 = value_cast_pointers (type, arg1); else if (code1 == TYPE_CODE_REF) error (_("Attempt to cast to reference type from non-reference type.")); else arg1 = value_cast (type, arg1); > Index: gdb/valops.c > =================================================================== > RCS file: /cvs/src/src/gdb/valops.c,v > retrieving revision 1.183 > diff -u -p -r1.183 valops.c > --- gdb/valops.c 4 Feb 2008 00:23:04 -0000 1.183 > +++ gdb/valops.c 28 Feb 2008 18:47:50 -0000 > @@ -199,6 +199,7 @@ allocate_space_in_inferior (int len) > struct value * > value_cast_pointers (struct type *type, struct value *arg2) > { > + struct type *type1 = check_typedef (type); > struct type *type2 = check_typedef (value_type (arg2)); > struct type *t1 = check_typedef (TYPE_TARGET_TYPE (type)); > struct type *t2 = check_typedef (TYPE_TARGET_TYPE (type2)); Probably t1 should be set from type1. > value_zero (t1, not_lval), 0, t1, 1); > if (v) > { > - CORE_ADDR addr2 = value_as_address (arg2); > + /* Downcasting is possible (t1 is superclass of v2). */ > + CORE_ADDR addr2 = VALUE_ADDRESS (v2); Yep, that makes sense. This was the real bug. > addr2 -= (VALUE_ADDRESS (v) > + value_offset (v) > + value_embedded_offset (v)); > - return value_from_pointer (type, addr2); > + return value_from_pointer (type1, addr2); Why type1? It's nice to preserve the requested type on results, when we can. -- Daniel Jacobowitz CodeSourcery