Patchwork [google/main,google/gcc-4_7] Fix segfault in linemap lookup

login
register
mail settings
Submitter Cary Coutant
Date Aug. 9, 2012, 10:04 p.m.
Message ID <20120809220443.60C6DE0822@ccoutant.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/176288/
State New
Headers show

Comments

Cary Coutant - Aug. 9, 2012, 10:04 p.m.
This patch is for the google/main and google/gcc-4_7 branches.

New code in GCC 4.7 is calling linemap_lookup with a location_t that
may still represent a location-with-discriminator.  Before using a
location_t value to lookup the line number, it needs to be mapped to
a real location_t value.

Tested with make check-gcc and validate-failures.py.

OK for google/main and google/gcc-4_7?


2012-08-09   Cary Coutant  <ccoutant@google.com>

gcc/
	* tree-diagnostic.c (maybe_unwind_expanded_macro_loc): Check for
	discriminator.
	* diagnostic.c (diagnostic_report_current_module): Likewise.
Diego Novillo - Aug. 10, 2012, 12:38 p.m.
On 12-08-09 18:04 , Cary Coutant wrote:
> This patch is for the google/main and google/gcc-4_7 branches.
>
> New code in GCC 4.7 is calling linemap_lookup with a location_t that
> may still represent a location-with-discriminator.  Before using a
> location_t value to lookup the line number, it needs to be mapped to
> a real location_t value.
>
> Tested with make check-gcc and validate-failures.py.
>
> OK for google/main and google/gcc-4_7?
>
>
> 2012-08-09   Cary Coutant  <ccoutant@google.com>
>
> gcc/
> 	* tree-diagnostic.c (maybe_unwind_expanded_macro_loc): Check for
> 	discriminator.
> 	* diagnostic.c (diagnostic_report_current_module): Likewise.

OK.


Diego.

Patch

Index: gcc/tree-diagnostic.c
===================================================================
--- gcc/tree-diagnostic.c	(revision 190262)
+++ gcc/tree-diagnostic.c	(working copy)
@@ -23,6 +23,7 @@  along with GCC; see the file COPYING3.  
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
+#include "input.h"
 #include "tree.h"
 #include "diagnostic.h"
 #include "tree-diagnostic.h"
@@ -115,6 +116,8 @@  maybe_unwind_expanded_macro_loc (diagnos
   unsigned ix;
   loc_map_pair loc, *iter;
 
+  if (has_discriminator (where))
+    where = map_discriminator_location (where);
   map = linemap_lookup (line_table, where);
   if (!linemap_macro_expansion_map_p (map))
     return;
Index: gcc/diagnostic.c
===================================================================
--- gcc/diagnostic.c	(revision 190262)
+++ gcc/diagnostic.c	(working copy)
@@ -270,6 +270,9 @@  diagnostic_report_current_module (diagno
   if (where <= BUILTINS_LOCATION)
     return;
 
+  if (has_discriminator (where))
+    where = map_discriminator_location (where);
+
   linemap_resolve_location (line_table, where,
 			    LRK_MACRO_DEFINITION_LOCATION,
 			    &map);