diff mbox

[GOOGLE] Updates highest_location when updating next_discriminator_location

Message ID CAO2gOZVAgnYUUUdWRAzv+yH4QZNbfyyg=OTKveciD=1L++jhsQ@mail.gmail.com
State New
Headers show

Commit Message

Dehao Chen May 13, 2014, 5:43 p.m. UTC
As discussed offline, this is actually due to missing parts of the
previous patch (some changes does not appear in the change log of
r199154). I've updated the patch to include those missing pieces.
Testing on going.

Dehao

On Tue, May 13, 2014 at 10:04 AM, Cary Coutant <ccoutant@google.com> wrote:
>> The problem is that linemap_location_from_macro_expansion_p will
>> always return true if locus has discriminator. And in linemap_lookup,
>> this will lead to call linemap_macro_map_lookup, in which there is an
>> assertion:
>>
>> linemap_assert (line >= LINEMAPS_MACRO_LOWEST_LOCATION (set));
>>
>> However, line is actually not a macro location.
>
> That sounds like we're leaking a discriminator location into the
> linemap code. Before you can call
> linemap_location_from_macro_expansion_p, you need to do this (as in
> expand_location_1):
>
>   /* If LOC describes a location with a discriminator, extract the
>      discriminator and map it to the real location.  */
>   if (min_discriminator_location != UNKNOWN_LOCATION
>       && loc >= min_discriminator_location
>       && loc < next_discriminator_location)
>     loc = map_discriminator_location (loc);
>
> -cary
diff mbox

Patch

Index: gcc/tree-ssa-uninit.c
===================================================================
--- gcc/tree-ssa-uninit.c	(revision 210386)
+++ gcc/tree-ssa-uninit.c	(working copy)
@@ -149,6 +149,7 @@  warn_uninit (enum opt_code wc, tree t,
   location = (context != NULL && gimple_has_location (context))
 	     ? gimple_location (context)
 	     : DECL_SOURCE_LOCATION (var);
+  location = map_discriminator_location (location);
   location = linemap_resolve_location (line_table, location,
 				       LRK_SPELLING_LOCATION,
 				       NULL);
Index: gcc/tree-diagnostic.c
===================================================================
--- gcc/tree-diagnostic.c	(revision 210386)
+++ gcc/tree-diagnostic.c	(working copy)
@@ -108,6 +108,8 @@  maybe_unwind_expanded_macro_loc (diagnostic_contex
   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/builtins.c
===================================================================
--- gcc/builtins.c	(revision 210386)
+++ gcc/builtins.c	(working copy)
@@ -59,6 +59,7 @@  along with GCC; see the file COPYING3.  If not see
 #include "builtins.h"
 #include "ubsan.h"
 #include "cilk.h"
+#include "input.h"
 
 
 static tree do_mpc_arg1 (tree, tree, int (*)(mpc_ptr, mpc_srcptr, mpc_rnd_t));
@@ -12064,6 +12065,10 @@  fold_builtin_next_arg (tree exp, bool va_start_p)
   tree fntype = TREE_TYPE (current_function_decl);
   int nargs = call_expr_nargs (exp);
   tree arg;
+  location_t loc = LOCATION_LOCUS (input_location);
+  if (has_discriminator (loc))
+    loc = map_discriminator_location (loc);
+
   /* There is good chance the current input_location points inside the
      definition of the va_start macro (perhaps on the token for
      builtin) in a system header, so warnings will not be emitted.
Index: gcc/diagnostic.c
===================================================================
--- gcc/diagnostic.c	(revision 210386)
+++ gcc/diagnostic.c	(working copy)
@@ -188,6 +188,7 @@  diagnostic_set_info_translated (diagnostic_info *d
 				va_list *args, location_t location,
 				diagnostic_t kind)
 {
+  location = map_discriminator_location (location);
   diagnostic->message.err_no = errno;
   diagnostic->message.args_ptr = args;
   diagnostic->message.format_spec = msg;
@@ -514,6 +515,9 @@  diagnostic_report_current_module (diagnostic_conte
   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);