diff mbox

[libcpp] Do not modify a token once it has been initialized

Message ID 86oapg1v26.fsf@redhat.com
State New
Headers show

Commit Message

Dodji Seketeli Jan. 30, 2015, 9:23 a.m. UTC
Hello,

While looking at PR preprocessor/64803, I noticed that builtin_macro
was changing the location a token after it was been handed out by
_cpp_lex_direct().  Use the combination of cpp_force_token_locations()
and cpp_stop_forcing_token_locations() that are intended for exactly
that use case.

Boostrapped and tested on x86_64-unknown-linux-gnu.

libcpp/ChangeLog:

	* macro.c (builtin_macro): Use the combination of
	cpp_force_token_locations() and cpp_stop_forcing_token_locations()
	instead of modifying the location of the token after its
	initialization.

OK to for trunk when stage 1 re-opens?

Cheers,

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
---
 libcpp/macro.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Andreas Schwab Jan. 30, 2015, 10:34 a.m. UTC | #1
Dodji Seketeli <dodji@redhat.com> writes:

> +  /* force the location of the token emitted by _cpp_lex_direct() to

s/force/Force/

Andreas.
Dodji Seketeli Jan. 30, 2015, 10:54 a.m. UTC | #2
Andreas Schwab <schwab@linux-m68k.org> writes:

>> +  /* force the location of the token emitted by _cpp_lex_direct() to
>
> s/force/Force/

Thanks for noticing this, Andreas!

I have updated my local copy of the patch to fix that.

Cheers!
Jason Merrill Jan. 30, 2015, 6:04 p.m. UTC | #3
OK.

Jason
diff mbox

Patch

diff --git a/libcpp/macro.c b/libcpp/macro.c
index 9571345..ca199ba 100644
--- a/libcpp/macro.c
+++ b/libcpp/macro.c
@@ -442,9 +442,12 @@  builtin_macro (cpp_reader *pfile, cpp_hashnode *node, source_location loc)
 
   /* Set pfile->cur_token as required by _cpp_lex_direct.  */
   pfile->cur_token = _cpp_temp_token (pfile);
+  /* force the location of the token emitted by _cpp_lex_direct() to
+     have the location LOC.  */
+  cpp_force_token_locations (pfile, &loc);
   cpp_token *token = _cpp_lex_direct (pfile);
-  /* We should point to the expansion point of the builtin macro.  */
-  token->src_loc = loc;
+  cpp_stop_forcing_token_locations (pfile);
+
   if (pfile->context->tokens_kind == TOKENS_KIND_EXTENDED)
     {
       /* We are tracking tokens resulting from macro expansion.