diff mbox

Followup fix for PR69650

Message ID 570CE0FB.8020409@redhat.com
State New
Headers show

Commit Message

Bernd Schmidt April 12, 2016, 11:50 a.m. UTC
As shown by Roger Orr in the comments of this PR, cpp_get_token can 
cause a reallocation that invalidates some of the variables in 
do_linemarker. It seems to occur in this call to linemap_add:

       /* Allocate the new line_map.  However, if the current map only has a
	 single line we can sometimes just increase its column_bits instead. */
       if (line_delta < 0
	  || last_line != ORDINARY_MAP_STARTING_LINE_NUMBER (map)
	  || SOURCE_COLUMN (map, highest) >= (1U << column_bits)
	  || range_bits < map->m_range_bits)
	map = linemap_check_ordinary
	        (const_cast <line_map *>
		  (linemap_add (set, LC_RENAME,
				ORDINARY_MAP_IN_SYSTEM_HEADER_P (map),
				ORDINARY_MAP_FILE_NAME (map),
				to_line)));

I'm still not very familiar with this code, but I believe with LC_RENAME 
we'll retain the right information in INCLUDED_FROM even if map changes.

I've put his patch, slightly adapted, through a bootstrap and test cycle 
on x86_64-linux. Ok to apply?


Bernd

Comments

Jakub Jelinek April 12, 2016, 12:01 p.m. UTC | #1
On Tue, Apr 12, 2016 at 01:50:19PM +0200, Bernd Schmidt wrote:
> 	PR preprocessor/69650
> 	* directives.c (do_linemarker): Reread map after calling
> 	cpp_get_token.

Ok, thanks.

> --- libcpp/directives.c	(revision 234831)
> +++ libcpp/directives.c	(working copy)
> @@ -1048,6 +1048,9 @@ do_linemarker (cpp_reader *pfile)
>  
>    if (reason == LC_LEAVE)
>      {
> +      /* Reread map since cpp_get_token can invalidate it with a
> +	 reallocation.  */
> +      map = LINEMAPS_LAST_ORDINARY_MAP (line_table);
>        const line_map_ordinary *from;      
>        if (MAIN_FILE_P (map)
>  	  || (new_file
> @@ -1055,7 +1058,8 @@ do_linemarker (cpp_reader *pfile)
>  	      && filename_cmp (ORDINARY_MAP_FILE_NAME (from), new_file) != 0))
>  	{
>  	  cpp_warning (pfile, CPP_W_NONE,
> -		     "file \"%s\" linemarker ignored due to incorrect nesting", new_file);
> +		       "file \"%s\" linemarker ignored due to "
> +		       "incorrect nesting", new_file);
>  	  return;
>  	}
>      }


	Jakub
diff mbox

Patch

	PR preprocessor/69650
	* directives.c (do_linemarker): Reread map after calling
	cpp_get_token.

Index: libcpp/directives.c
===================================================================
--- libcpp/directives.c	(revision 234831)
+++ libcpp/directives.c	(working copy)
@@ -1048,6 +1048,9 @@  do_linemarker (cpp_reader *pfile)
 
   if (reason == LC_LEAVE)
     {
+      /* Reread map since cpp_get_token can invalidate it with a
+	 reallocation.  */
+      map = LINEMAPS_LAST_ORDINARY_MAP (line_table);
       const line_map_ordinary *from;      
       if (MAIN_FILE_P (map)
 	  || (new_file
@@ -1055,7 +1058,8 @@  do_linemarker (cpp_reader *pfile)
 	      && filename_cmp (ORDINARY_MAP_FILE_NAME (from), new_file) != 0))
 	{
 	  cpp_warning (pfile, CPP_W_NONE,
-		     "file \"%s\" linemarker ignored due to incorrect nesting", new_file);
+		       "file \"%s\" linemarker ignored due to "
+		       "incorrect nesting", new_file);
 	  return;
 	}
     }