From: Jason Merrill <jason@redhat.com>
To: David Malcolm <dmalcolm@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH/RFC] C++ FE: expression ranges (v2)
Date: Sat, 21 Nov 2015 08:22:00 -0000 [thread overview]
Message-ID: <56501A61.6010806@redhat.com> (raw)
In-Reply-To: <564E3512.9080701@redhat.com>
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.
What is the memory consumption impact of this change?
> Also, in cp_parser_new_expression I attempted to generate meaningful
> ranges e.g.:
>
> int *foo = new int[100];
> ^~~~~~~~~~~~
>
> but it seems to be hard to do this, due to the trailing optional
> components; I found myself wanting to ask the lexer for the last
> token it consumed (in particular, I'm interested in the
> location_t of that token). Is this a reasonable thing to add to the
> lexer?
cp_lexer_previous_token seems like what you want.
> - return cp_build_unary_op (code, arg1, candidates != 0, complain);
> + {
> + tree result = cp_build_unary_op (code, arg1, candidates != 0, complain);
> + protected_set_expr_location (result, loc);
I'd much rather pass loc into cp_build_unary_op. At least add a FIXME
to that effect. Likewise in the other places you call *build* and then
set the loc.
> +#if 0
> + /* FIXME: various assertions can be put in here when debugging,
> + for tracking down where location information gets thrown
> + away (during a trip through a purely "tree" value). */
> + if (m_value && m_value != error_mark_node)
> + {
> + if (TREE_CODE (m_value) == FUNCTION_DECL)
> + return; // for now
> + gcc_assert (CAN_HAVE_LOCATION_P (m_value));
> + //gcc_assert (m_loc != UNKNOWN_LOCATION);
Yeah, I don't think you want to assert on UNKNOWN_LOCATION; some code
does not and should not have an associated location. In particular,
cleanups.
> Build the assignment expression. Its default
> - location is the location of the '=' token. */
> + location:
> + LHS = RHS
> + ~~~~^~~~~
> + is the location of the '=' token as the
> + caret, ranging from the start of the lhs to the
> + end of the rhs. */
> saved_input_location = input_location;
> + loc = make_location (loc,
> + expr.get_start (),
> + rhs.get_finish ());
> input_location = loc;
> expr = build_x_modify_expr (loc, expr,
> assignment_operator,
> rhs,
> complain_flags (decltype_p));
> + protected_set_expr_location (expr, loc);
> input_location = saved_input_location;
Do we still need to mess with input_location here? If so, please add a
FIXME explaining what still needs to be fixed.
Jason
next prev parent reply other threads:[~2015-11-21 7:16 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-07 3:40 [PATCH/RFC] C++ FE: expression ranges (work in progress) David Malcolm
2015-11-15 4:43 ` [PATCH/RFC] C++ FE: expression ranges (v2) David Malcolm
2015-11-19 20:46 ` Jason Merrill
2015-11-21 8:22 ` Jason Merrill [this message]
2015-11-21 8:22 ` Jakub Jelinek
2015-11-23 10:02 ` Richard Biener
2015-11-23 16:58 ` David Malcolm
2015-11-23 17:08 ` Jakub Jelinek
2015-11-23 17:09 ` Marek Polacek
2015-11-23 19:45 ` Jason Merrill
2015-11-24 9:42 ` Richard Biener
2015-11-24 11:08 ` David Malcolm
2015-11-24 11:50 ` Richard Biener
2015-11-24 12:15 ` Marek Polacek
2015-11-25 20:32 ` [PATCH/RFC 0/2] C++ FE: expression ranges (v3) David Malcolm
2015-11-25 20:32 ` [PATCH 1/2] RFC: C++: attempt to provide location_t in more places David Malcolm
2015-11-25 21:33 ` Jason Merrill
2015-12-03 14:36 ` [PATCH 00/10] C++ expression ranges v4 David Malcolm
2015-12-03 14:36 ` [PATCH 04/10] Fix g++.dg/template/crash55.C David Malcolm
2015-12-03 14:37 ` [PATCH 03/10] Fix g++.dg/gomp/loop-1.C David Malcolm
2015-12-03 14:37 ` [PATCH 02/10] Fix g++.dg/cpp0x/nsdmi-template14.C David Malcolm
2015-12-03 20:33 ` Jason Merrill
2015-12-03 21:43 ` David Malcolm
2015-12-03 22:17 ` Jason Merrill
2015-12-04 14:22 ` [PATCH 02/10 v2] Fix g++.dg/cpp0x/nsdmi-template14.C (v2) David Malcolm
2015-12-03 14:37 ` [PATCH 07/10] Fix g++.dg/template/ref3.C David Malcolm
2015-12-03 20:38 ` Jason Merrill
2015-12-03 22:08 ` David Malcolm
2015-12-04 16:01 ` Jason Merrill
2015-12-04 16:45 ` [PATCH] Add XFAIL to g++.dg/template/ref3.C (PR c++/68699) David Malcolm
2015-12-04 17:09 ` Jason Merrill
2015-12-03 14:37 ` [PATCH 01/10] C++ FE: expression ranges v4 David Malcolm
2015-12-04 17:10 ` Jason Merrill
2015-12-04 18:13 ` David Malcolm
2015-12-03 14:37 ` [PATCH 10/10] Fix g++.dg/warn/Wconversion-real-integer2.C David Malcolm
2015-12-03 14:37 ` [PATCH 09/10] Fix g++.dg/warn/pr35635.C David Malcolm
2015-12-03 14:37 ` [PATCH 05/10] Fix location of dg-error within g++.dg/template/pr64100.C David Malcolm
2015-12-03 14:37 ` [PATCH 08/10] Fix g++.dg/ubsan/pr63956.C David Malcolm
2015-12-03 14:53 ` [PATCH 06/10] Fix g++.dg/template/pseudodtor3.C David Malcolm
2015-11-25 20:38 ` [PATCH 2/2] RFC: C++ FE: expression ranges (work in progress) v3 David Malcolm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56501A61.6010806@redhat.com \
--to=jason@redhat.com \
--cc=dmalcolm@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).