From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16221 invoked by alias); 4 Oct 2010 13:01:38 -0000 Received: (qmail 16205 invoked by uid 22791); 4 Oct 2010 13:01:37 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00,MSGID_FROM_MTA_HEADER,SPF_SOFTFAIL,TW_CP,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mtagate7.de.ibm.com (HELO mtagate7.de.ibm.com) (195.212.17.167) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 04 Oct 2010 13:01:31 +0000 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate7.de.ibm.com (8.13.1/8.13.1) with ESMTP id o94D1SxB029418 for ; Mon, 4 Oct 2010 13:01:28 GMT Received: from d12av02.megacenter.de.ibm.com (d12av02.megacenter.de.ibm.com [9.149.165.228]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o94D1RaZ3498100 for ; Mon, 4 Oct 2010 15:01:28 +0200 Received: from d12av02.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o94D1RCW000399 for ; Mon, 4 Oct 2010 15:01:27 +0200 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with SMTP id o94D1QHV032611; Mon, 4 Oct 2010 15:01:26 +0200 Message-Id: <201010041301.o94D1QHV032611@d12av02.megacenter.de.ibm.com> Received: by tuxmaker.boeblingen.de.ibm.com (sSMTP sendmail emulation); Mon, 04 Oct 2010 15:01:22 +0200 Subject: Re: [patch] fix pre-/post- in-/decrement To: ken@linux.vnet.ibm.com (Ken Werner) Date: Mon, 04 Oct 2010 13:01:00 -0000 From: "Ulrich Weigand" Cc: gdb-patches@sourceware.org, brobecker@adacore.com (Joel Brobecker) In-Reply-To: <201010011945.27883.ken@linux.vnet.ibm.com> from "Ken Werner" at Oct 01, 2010 07:45:27 PM MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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: 2010-10/txt/msg00028.txt.bz2 Ken Werner wrote: > - return value_assign (arg1, arg2); > + /* Prevent to return a lvalue. */ > + arg3 = value_assign (arg1, arg2); > + VALUE_LVAL (arg3) = not_lval; > + return arg3; We want to get away from changing core properties like lval in values after the fact ... In any case, hard-coding the lval to non_lval without any further change can cause problems, e.g. if the value is lazy. I think there is a more general issue underlying this particular change. You're right that the result of a preincrement should not be an lvalue. But the same is true for results of assignment operators in general. Note that value_assign is used only to implement such operators (simple assignment, compound assignment, pre/postfix operators). Since *all* of them return non-lvalues, it might make sense to simply change value_assign to return a non-lvalue in the first place ... > + type = value_type (arg1); > + arg3 = allocate_value (type); > + > + /* Copy the value to prevent to return a lvalue. */ > + memcpy (value_contents_raw (arg3), value_contents (arg1), > + TYPE_LENGTH (type)); I'd prefer to encapsulate this in a function, e.g. value_non_lval (...) or a similar name, which returns a version of the value that is non_lval. This could then address a couple of additional issues: - if the value is already non_lval, no need to create an extra copy - it might be better to copy the full contents / enclosing type for C++ objects Bye, Ulrich -- Dr. Ulrich Weigand GNU Toolchain for Linux on System z and Cell BE Ulrich.Weigand@de.ibm.com