From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8394 invoked by alias); 23 Nov 2015 16:53:46 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 8311 invoked by uid 89); 23 Nov 2015 16:53:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 23 Nov 2015 16:53:43 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 483E28E241; Mon, 23 Nov 2015 16:53:42 +0000 (UTC) Received: from [10.3.233.130] (vpn-233-130.phx2.redhat.com [10.3.233.130]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tANGrfEm003575; Mon, 23 Nov 2015 11:53:41 -0500 Message-ID: <1448297620.19594.168.camel@surprise> Subject: Re: [PATCH/RFC] C++ FE: expression ranges (v2) From: David Malcolm To: Richard Biener Cc: Jakub Jelinek , Jason Merrill , GCC Patches Date: Mon, 23 Nov 2015 16:58:00 -0000 In-Reply-To: References: <1446868737-3306-1-git-send-email-dmalcolm@redhat.com> <1447563717-24429-1-git-send-email-dmalcolm@redhat.com> <564E3512.9080701@redhat.com> <56501A61.6010806@redhat.com> <20151121082151.GQ5675@tucnak.redhat.com> Content-Type: multipart/mixed; boundary="=-ceHaKdaLVv8HRKaKSlOc" Mime-Version: 1.0 X-IsSubscribed: yes X-SW-Source: 2015-11/txt/msg02763.txt.bz2 --=-ceHaKdaLVv8HRKaKSlOc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Content-length: 2210 On Mon, 2015-11-23 at 10:59 +0100, Richard Biener wrote: > On Sat, Nov 21, 2015 at 9:21 AM, Jakub Jelinek wrote: > > On Sat, Nov 21, 2015 at 02:16:49AM -0500, Jason Merrill wrote: > >> On 11/19/2015 03:46 PM, Jason Merrill wrote: > >> >On 11/15/2015 12:01 AM, David Malcolm wrote: > >> >>As with the C frontend, there's an issue with tree nodes that > >> >>don't have locations: VAR_DECL, INTEGER_CST, etc: > >> >> > >> >> int test (int foo) > >> >> { > >> >> return foo * 100; > >> >> ^^^ ^^^ > >> >> } > >> >> > >> >>where we'd like to access the source spelling ranges of the expressions > >> >>during parsing, so that we can use them when reporting parser errors. > >> > > >> >Hmm, I had been thinking to address this in the C++ front end by > >> >wrapping uses in another tree: NOP_EXPR for rvalues, VIEW_CONVERT_EXPR > >> >for lvalues. > >> > >> On the other hand, my direction seems likely to cause more issues, > >> especially with code that doesn't yet know how to handle VIEW_CONVERT_EXPR, > >> and could create ambiguity with explicit conversions. So I guess your > >> approach seems reasonable. > > > > But your approach would allow better diagnostics even in places where you > > don't have the structures with tree, location_t pairs around. With that > > it will be limited solely to the parser and nothing else, so even template > > instantiation if it is something that can be only detected when > > instantiating would be too late. > > > > I think using a new tree (rather than using NOP_EXPR/VIEW_CONVERT_EXPR) > > that would be just some expression with location and teaching the FE and > > folder about it might be even better. > > Agreed. Note that we already have NON_LVALUE_EXPR and fold-const.c uses > that to stick locations on things that cannot have them. > > OTOH I would like to get rid of NON_LVALUE_EXPR in the middle-end (and thus > fold-const.c). Thanks. Does the following look like the kind of thing you had in mind? (just the tree.def part for now). Presumably usable for both lvalues and rvalues, where the thing it wraps is what's important. It merely exists to add an EXPR_LOCATION, for a usage of the wrapped thing. --=-ceHaKdaLVv8HRKaKSlOc Content-Disposition: attachment; filename="tree.def.patch" Content-Type: text/x-patch; name="tree.def.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit Content-length: 726 diff --git a/gcc/tree.def b/gcc/tree.def index 44e5a5e..30fd766 100644 --- a/gcc/tree.def +++ b/gcc/tree.def @@ -1407,6 +1407,13 @@ DEFTREECODE (CILK_SPAWN_STMT, "cilk_spawn_stmt", tcc_statement, 1) /* Cilk Sync statement: Does not have any operands. */ DEFTREECODE (CILK_SYNC_STMT, "cilk_sync_stmt", tcc_statement, 0) +/* Wrapper to add a source code location to an expression, either one + that doesn't have one (such as an INTEGER_CST), or to a usage of a + variable (e.g. PARAM_DECL or VAR_DECL), where we want to record + the site in the source where the variable was *used* rather than + where it was declared. */ +DEFTREECODE (LOCATION_EXPR, "location_expr", tcc_unary, 1) + /* Local variables: mode:c --=-ceHaKdaLVv8HRKaKSlOc--