Index: gcc/tree-diagnostic.c
===================================================================
--- gcc/tree-diagnostic.c	(revision 192379)
+++ gcc/tree-diagnostic.c	(working copy)
@@ -100,11 +100,11 @@ DEF_VEC_ALLOC_O (loc_map_pair, heap);
    unwound macro expansion trace.  That's the part generated by this
    function.  */
 
 static void
 maybe_unwind_expanded_macro_loc (diagnostic_context *context,
-                                 diagnostic_info *diagnostic,
+                                 const diagnostic_info *diagnostic_orig,
                                  source_location where)
 {
   const struct line_map *map;
   VEC(loc_map_pair,heap) *loc_vec = NULL;
   unsigned ix;
@@ -142,18 +142,21 @@ maybe_unwind_expanded_macro_loc (diagnos
      first triggered the macro expansion.  This must be an ordinary map.  */
 
   /* Walk LOC_VEC and print the macro expansion trace, unless the
      first macro which expansion triggered this trace was expanded
      inside a system header.  */
+  const char *saved_prefix = pp_get_prefix (context->printer);
+  diagnostic_info diagnostic = *diagnostic_orig;
+  diagnostic.kind = DK_NOTE;
+  int saved_location_line =
+    expand_location_to_spelling_point (diagnostic.location).line;
+
   if (!LINEMAP_SYSP (map))
     FOR_EACH_VEC_ELT (loc_map_pair, loc_vec, ix, iter)
       {
-        source_location resolved_def_loc = 0, resolved_exp_loc = 0,
-	  saved_location = 0;
-	int resolved_def_loc_line = 0, saved_location_line = 0;
-        diagnostic_t saved_kind;
-        const char *saved_prefix;
+        source_location resolved_def_loc = 0, resolved_exp_loc = 0;
+	int resolved_def_loc_line = 0;
 	/* Sometimes, in the unwound macro expansion trace, we want to
 	   print a part of the context that shows where, in the
 	   definition of the relevant macro, is the token (we are
 	   looking at) used.  That is the case in the introductory
 	   comment of this function, where we print:
@@ -211,55 +214,45 @@ maybe_unwind_expanded_macro_loc (diagnos
         resolved_exp_loc =
           linemap_resolve_location (line_table,
                                     MACRO_MAP_EXPANSION_POINT_LOCATION (iter->map),
                                     LRK_MACRO_DEFINITION_LOCATION, NULL);
 
-        saved_kind = diagnostic->kind;
-        saved_prefix = pp_get_prefix (context->printer);
-        saved_location = diagnostic->location;
-	saved_location_line =
-	  expand_location_to_spelling_point (saved_location).line;
-
-        diagnostic->kind = DK_NOTE;
 
 	/* We need to print the context of the macro definition only
 	   when the locus of the first displayed diagnostic (displayed
 	   before this trace) was inside the definition of the
 	   macro.  */
 	print_definition_context_p =
 	  (ix == 0 && (saved_location_line != resolved_def_loc_line));
 
 	if (print_definition_context_p)
 	  {
-	    diagnostic->location = resolved_def_loc;
+	    diagnostic.location = resolved_def_loc;
 	    pp_set_prefix (context->printer,
-			   diagnostic_build_prefix (context, diagnostic));
+			   diagnostic_build_prefix (context, &diagnostic));
 	    pp_newline (context->printer);
 	    pp_printf (context->printer, "in definition of macro '%s'",
 		       linemap_map_get_macro_name (iter->map));
 	    pp_destroy_prefix (context->printer);
-	    diagnostic_show_locus (context, diagnostic);
+	    diagnostic_show_locus (context, &diagnostic);
 	    /* At this step, as we've printed the context of the macro
 	       definition, we don't want to print the context of its
 	       expansion, otherwise, it'd be redundant.  */
 	    continue;
 	  }
 
-	diagnostic->location = resolved_exp_loc;
+	diagnostic.location = resolved_exp_loc;
 	pp_set_prefix (context->printer,
-                       diagnostic_build_prefix (context, diagnostic));
+                       diagnostic_build_prefix (context, &diagnostic));
 	pp_newline (context->printer);
 	pp_printf (context->printer, "in expansion of macro '%s'",
 		   linemap_map_get_macro_name (iter->map));
         pp_destroy_prefix (context->printer);
-        diagnostic_show_locus (context, diagnostic);
-
-        diagnostic->kind = saved_kind;
-        diagnostic->location = saved_location;
-        pp_set_prefix (context->printer, saved_prefix);
+        diagnostic_show_locus (context, &diagnostic);
       }
 
+  pp_set_prefix (context->printer, saved_prefix);
   VEC_free (loc_map_pair, heap, loc_vec);
 }
 
 /*  This is a diagnostic finalizer implementation that is aware of
     virtual locations produced by libcpp.
