From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29339 invoked by alias); 2 Sep 2008 12:38:21 -0000 Received: (qmail 29327 invoked by uid 22791); 2 Sep 2008 12:38:20 -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; Tue, 02 Sep 2008 12:37:41 +0000 Received: from nan.false.org (localhost [127.0.0.1]) by nan.false.org (Postfix) with ESMTP id 9B80298417 for ; Tue, 2 Sep 2008 12:37:39 +0000 (GMT) Received: from caradoc.them.org (22.svnf5.xdsl.nauticom.net [209.195.183.55]) by nan.false.org (Postfix) with ESMTP id 7D7B7981E8 for ; Tue, 2 Sep 2008 12:37:39 +0000 (GMT) Received: from drow by caradoc.them.org with local (Exim 4.69) (envelope-from ) id 1KaV8c-0005nU-TZ for gdb-patches@sourceware.org; Tue, 02 Sep 2008 08:37:38 -0400 Date: Tue, 02 Sep 2008 12:38:00 -0000 From: Daniel Jacobowitz To: gdb-patches@sourceware.org Subject: Re: [rfc][08/37] Eliminate builtin_type_ macros: Make pointer arithmetic explicit Message-ID: <20080902123738.GB21700@caradoc.them.org> Mail-Followup-To: gdb-patches@sourceware.org References: <20080831175045.128504000@de.ibm.com> <20080831175121.285976000@de.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20080831175121.285976000@de.ibm.com> User-Agent: Mutt/1.5.17 (2008-05-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-09/txt/msg00014.txt.bz2 On Sun, Aug 31, 2008 at 07:50:53PM +0200, Ulrich Weigand wrote: > Hello, > > this patch removes the functions value_add and value_sub which handle > both integer and pointer arithmetic, and replaces them by functions > value_ptradd, value_ptrsub, and value_ptrdiff that solely take care > of C-style pointer arithmetic. (For integer arithmetic, value_binop > can be used.) > > This moves the type to be used for pointer difference operations up > eval.c (this should at some point be replaces by a per-gdbarch > "ptrdiff_t" type). It also makes the subsequent patches to remove > current_gdbarch references from value_binop simpler. I've got to say I don't like the direction of this change :-( Smarts in the expression parser are not available to reuse by other code that constructs values - which is something I think we should be doing more often. Why should the caller have to know that the two values are pointers? > @@ -1531,8 +1556,19 @@ evaluate_subexp_standard (struct type *e > goto nosideret; > if (binop_user_defined_p (op, arg1, arg2)) > return value_x_binop (arg1, arg2, op, OP_NULL, noside); > + else if (ptrmath_type_p (value_type (arg1)) > + && ptrmath_type_p (value_type (arg2))) > + { > + /* FIXME -- should be ptrdiff_t */ > + type = builtin_type (exp->gdbarch)->builtin_long; > + return value_from_longest (type, value_ptrdiff (arg1, arg2)); > + } > + else if (ptrmath_type_p (value_type (arg1))) > + return value_ptrsub (arg1, arg2); > + else if (ptrmath_type_p (value_type (arg2))) > + return value_ptrsub (arg2, arg1); > else > - return value_sub (arg1, arg2); > + return value_binop (arg1, arg2, BINOP_SUB); > > case BINOP_EXP: > case BINOP_MUL: There's something wrong in the last else if; arg1 - arg2 != arg2 - arg1. -- Daniel Jacobowitz CodeSourcery