From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4812 invoked by alias); 25 Oct 2013 08:13:51 -0000 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 Received: (qmail 4799 invoked by uid 89); 25 Oct 2013 08:13:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mga01.intel.com Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 25 Oct 2013 08:13:49 +0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 25 Oct 2013 01:13:46 -0700 X-ExtLoop1: 1 Received: from irsmsx103.ger.corp.intel.com ([163.33.3.157]) by fmsmga002.fm.intel.com with ESMTP; 25 Oct 2013 01:13:45 -0700 Received: from irsmsx151.ger.corp.intel.com (163.33.192.59) by IRSMSX103.ger.corp.intel.com (163.33.3.157) with Microsoft SMTP Server (TLS) id 14.3.123.3; Fri, 25 Oct 2013 09:13:43 +0100 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.75]) by IRSMSX151.ger.corp.intel.com ([169.254.4.252]) with mapi id 14.03.0123.003; Fri, 25 Oct 2013 09:13:43 +0100 From: "Agovic, Sanimir" To: 'Tom Tromey' CC: "gdb-patches@sourceware.org" Subject: RE: [PATCH 05/10] vla: allow side effects for sizeof argument Date: Fri, 25 Oct 2013 08:13:00 -0000 Message-ID: <0377C58828D86C4588AEEC42FC3B85A71769F292@IRSMSX105.ger.corp.intel.com> References: <1382366424-21010-1-git-send-email-sanimir.agovic@intel.com> <1382366424-21010-6-git-send-email-sanimir.agovic@intel.com> <87d2mua1gi.fsf@fleche.redhat.com> In-Reply-To: <87d2mua1gi.fsf@fleche.redhat.com> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2013-10/txt/msg00787.txt.bz2 Thanks for your review. I avoid to re-send the complete patch series, thus see my=20 alternative proposal below. Once I receive more feedback I will re-publish my patch series including this fix if=20 applicable. Meanwhile you can track our latest development efforts on http://intel-gdb.github.io/ branch vla-c99. -Sanimir vla: allow side effects for subscripts in the sizeof operator C99 requires the sizeof operator to be evaluated at runtime to retrieve the size of the vla, reflect this behavior in gdb. 1| void foo (size_t n, int vla[n][n]) { 2| } (gdb) p sizeof(vla[0]) yields N. 2013-10-18 Sanimir Agovic Keven Boell * eval.c (evaluate_subexp_for_sizeof): Allow side effects for subscripts in the sizeof operator. Change-Id: I945e8a259e850cc0470faa742a0d2191122ef37b diff --git a/gdb/eval.c b/gdb/eval.c index ab3cb95..255ea09 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -3054,6 +3054,13 @@ evaluate_subexp_for_sizeof (struct expression *exp, = int *pos) return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type)); + case BINOP_SUBSCRIPT: + /* In case of a variable length array we need to evaluate the subscr= ipt + with side effects to correcly infere the size. */ + val =3D evaluate_subexp (NULL_TYPE, exp, pos, EVAL_NORMAL); + return value_from_longest (size_type, + (LONGEST) TYPE_LENGTH (value_type (val))); + default: val =3D evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECT= S); return value_from_longest (size_type, > -----Original Message----- > From: Tom Tromey [mailto:tromey@redhat.com] > Sent: Thursday, October 24, 2013 09:55 PM > To: Agovic, Sanimir > Cc: gdb-patches@sourceware.org > Subject: Re: [PATCH 05/10] vla: allow side effects for sizeof argument >=20 > >>>>> "Sanimir" =3D=3D Sanimir Agovic writes: >=20 > Sanimir> C99 requires the sizeof operator to be evaluated at runtime to c= ompute > Sanimir> the size of the vla, reflect this behavior in gdb. >=20 > Sanimir> - val =3D evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_= SIDE_EFFECTS); > Sanimir> + val =3D evaluate_subexp (NULL_TYPE, exp, pos, EVAL_NORMAL= ); >=20 > I think this will do the wrong thing for cases like (assuming "int x"): >=20 > (gdb) print sizeof (x++) >=20 > I think some other approach will be needed for this patch. >=20 > Tom Intel GmbH Dornacher Strasse 1 85622 Feldkirchen/Muenchen, Deutschland Sitz der Gesellschaft: Feldkirchen bei Muenchen Geschaeftsfuehrer: Christian Lamprechter, Hannes Schwaderer, Douglas Lusk Registergericht: Muenchen HRB 47456 Ust.-IdNr./VAT Registration No.: DE129385895 Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052