View | Details | Raw Unified | Return to bug 7263 | Differences between
and this patch

Collapse All | Expand All | Context: (Patch / File /
)

(-)a/gcc/c-decl.c (-1 / +2 lines)
 Lines 8780-8786   declspecs_add_type (location_t loc, struct c_declspecs *specs, Link Here 
8780
	      break;
8780
	      break;
8781
	    case RID_COMPLEX:
8781
	    case RID_COMPLEX:
8782
	      dupe = specs->complex_p;
8782
	      dupe = specs->complex_p;
8783
	      if (!flag_isoc99 && !in_system_header)
8783
	      if (!flag_isoc99
8784
		  && !linemap_location_originated_from_system_header_p (line_table, loc))
8784
		pedwarn (loc, OPT_pedantic,
8785
		pedwarn (loc, OPT_pedantic,
8785
			 "ISO C90 does not support complex types");
8786
			 "ISO C90 does not support complex types");
8786
	      if (specs->typespec_word == cts_void)
8787
	      if (specs->typespec_word == cts_void)
(-)a/gcc/c-family/c-lex.c (-4 / +18 lines)
 Lines 207-213   fe_file_change (const struct line_map *new_map) Link Here 
207
	    line = SOURCE_LINE (new_map - 1, included_at);
207
	    line = SOURCE_LINE (new_map - 1, included_at);
208
208
209
	  input_location = new_map->start_location;
209
	  input_location = new_map->start_location;
210
	  (*debug_hooks->start_source_file) (line, new_map->to_file);
210
	  (*debug_hooks->start_source_file) (line, LINEMAP_FILE (new_map));
211
#ifndef NO_IMPLICIT_EXTERN_C
211
#ifndef NO_IMPLICIT_EXTERN_C
212
	  if (c_header_level)
212
	  if (c_header_level)
213
	    ++c_header_level;
213
	    ++c_header_level;
 Lines 231-240   fe_file_change (const struct line_map *new_map) Link Here 
231
#endif
231
#endif
232
      input_location = new_map->start_location;
232
      input_location = new_map->start_location;
233
233
234
      (*debug_hooks->end_source_file) (new_map->to_line);
234
      (*debug_hooks->end_source_file) (LINEMAP_LINE (new_map));
235
    }
235
    }
236
236
237
  update_header_times (new_map->to_file);
237
  update_header_times (LINEMAP_FILE (new_map));
238
  input_location = new_map->start_location;
238
  input_location = new_map->start_location;
239
}
239
}
240
240
 Lines 296-305   c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags, Link Here 
296
  const cpp_token *tok;
296
  const cpp_token *tok;
297
  enum cpp_ttype type;
297
  enum cpp_ttype type;
298
  unsigned char add_flags = 0;
298
  unsigned char add_flags = 0;
299
  cpp_options *options = cpp_get_options (parse_in);
299
300
300
  timevar_push (TV_CPP);
301
  timevar_push (TV_CPP);
301
 retry:
302
 retry:
302
  tok = cpp_get_token_with_location (parse_in, loc);
303
  tok = cpp_get_token_with_location (parse_in, loc);
304
305
  /* If -ftrack-macro-location is in effect, use the location embedded
306
     in the token as it now records all the source locations of the
307
     token accross macro expansion.  */
308
  if (options->track_macro_expansion)
309
    *loc = tok->src_loc;
303
  type = tok->type;
310
  type = tok->type;
304
311
305
 retry_after_at:
312
 retry_after_at:
 Lines 350-355   c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags, Link Here 
350
357
351
	retry_at:
358
	retry_at:
352
	  tok = cpp_get_token_with_location (parse_in, &newloc);
359
	  tok = cpp_get_token_with_location (parse_in, &newloc);
360
361
	  /* If -ftrack-macro-location is in effect, use the location
362
	     embedded in the token as it now records all the source
363
	     locations of the token accross macro expansion.  */
364
	  if (options->track_macro_expansion)
365
	    newloc = tok->src_loc;
366
353
	  type = tok->type;
367
	  type = tok->type;
354
	  switch (type)
368
	  switch (type)
355
	    {
369
	    {
 Lines 390-396   c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags, Link Here 
390
404
391
	*cpp_spell_token (parse_in, tok, name, true) = 0;
405
	*cpp_spell_token (parse_in, tok, name, true) = 0;
392
406
393
	error ("stray %qs in program", name);
407
	error_at (*loc, "stray %qs in program", name);
394
      }
408
      }
395
409
396
      goto retry;
410
      goto retry;
(-)a/gcc/c-family/c-opts.c (+8 lines)
 Lines 753-758   c_common_handle_option (size_t scode, const char *arg, int value, Link Here 
753
      cpp_opts->preprocessed = value;
753
      cpp_opts->preprocessed = value;
754
      break;
754
      break;
755
755
756
    case OPT_fdebug_cpp:
757
      cpp_opts->debug = 1;
758
      break;
759
760
    case OPT_ftrack_macro_expansion:
761
      cpp_opts->track_macro_expansion = true;
762
      break;
763
756
    case OPT_frepo:
764
    case OPT_frepo:
757
      flag_use_repository = value;
765
      flag_use_repository = value;
758
      if (value)
766
      if (value)
(-)a/gcc/c-family/c-ppoutput.c (-29 / +73 lines)
 Lines 58-64   static void account_for_newlines (const unsigned char *, size_t); Link Here 
58
static int dump_macro (cpp_reader *, cpp_hashnode *, void *);
58
static int dump_macro (cpp_reader *, cpp_hashnode *, void *);
59
static void dump_queued_macros (cpp_reader *);
59
static void dump_queued_macros (cpp_reader *);
60
60
61
static void print_line_1 (source_location, const char*, FILE *);
61
static void print_line (source_location, const char *);
62
static void print_line (source_location, const char *);
63
static void maybe_print_line_1 (source_location, FILE *);
62
static void maybe_print_line (source_location);
64
static void maybe_print_line (source_location);
63
static void do_line_change (cpp_reader *, const cpp_token *,
65
static void do_line_change (cpp_reader *, const cpp_token *,
64
			    source_location, int);
66
			    source_location, int);
 Lines 171-176   scan_translation_unit (cpp_reader *pfile) Link Here 
171
    {
173
    {
172
      source_location loc;
174
      source_location loc;
173
      const cpp_token *token = cpp_get_token_with_location (pfile, &loc);
175
      const cpp_token *token = cpp_get_token_with_location (pfile, &loc);
176
      
177
      /* If -ftrack-macro-location is in effect, use the location
178
	 embedded in the token as it now records all the source
179
	 locations of the token accross macro expansion.  */
180
      if (CPP_OPTION (pfile, track_macro_expansion))
181
	loc = token->src_loc;
174
182
175
      if (token->type == CPP_PADDING)
183
      if (token->type == CPP_PADDING)
176
	{
184
	{
 Lines 188-196   scan_translation_unit (cpp_reader *pfile) Link Here 
188
      /* Subtle logic to output a space if and only if necessary.  */
196
      /* Subtle logic to output a space if and only if necessary.  */
189
      if (avoid_paste)
197
      if (avoid_paste)
190
	{
198
	{
191
	  const struct line_map *map
199
	  int src_line = linemap_get_source_line (line_table, loc);
192
	    = linemap_lookup (line_table, loc);
193
	  int src_line = SOURCE_LINE (map, loc);
194
200
195
	  if (print.source == NULL)
201
	  if (print.source == NULL)
196
	    print.source = token;
202
	    print.source = token;
 Lines 210-218   scan_translation_unit (cpp_reader *pfile) Link Here 
210
	}
216
	}
211
      else if (token->flags & PREV_WHITE)
217
      else if (token->flags & PREV_WHITE)
212
	{
218
	{
213
	  const struct line_map *map
219
	  int src_line = LOCATION_LINE (loc);
214
	    = linemap_lookup (line_table, loc);
215
	  int src_line = SOURCE_LINE (map, loc);
216
220
217
	  if (src_line != print.src_line
221
	  if (src_line != print.src_line
218
	      && do_line_adjustments
222
	      && do_line_adjustments
 Lines 245-251   scan_translation_unit (cpp_reader *pfile) Link Here 
245
	  in_pragma = false;
249
	  in_pragma = false;
246
	}
250
	}
247
      else
251
      else
248
	cpp_output_token (token, print.outf);
252
	{
253
	  if (cpp_get_options (parse_in)->debug)
254
	      linemap_dump_location (line_table, token->src_loc,
255
				     print.outf);
256
	  cpp_output_token (token, print.outf);
257
	}
249
258
250
      if (token->type == CPP_COMMENT)
259
      if (token->type == CPP_COMMENT)
251
	account_for_newlines (token->val.str.text, token->val.str.len);
260
	account_for_newlines (token->val.str.text, token->val.str.len);
 Lines 299-313   scan_translation_unit_trad (cpp_reader *pfile) Link Here 
299
/* If the token read on logical line LINE needs to be output on a
308
/* If the token read on logical line LINE needs to be output on a
300
   different line to the current one, output the required newlines or
309
   different line to the current one, output the required newlines or
301
   a line marker, and return 1.  Otherwise return 0.  */
310
   a line marker, and return 1.  Otherwise return 0.  */
311
302
static void
312
static void
303
maybe_print_line (source_location src_loc)
313
maybe_print_line_1 (source_location src_loc, FILE *stream)
304
{
314
{
305
  const struct line_map *map = linemap_lookup (line_table, src_loc);
315
  int src_line = LOCATION_LINE (src_loc);
306
  int src_line = SOURCE_LINE (map, src_loc);
307
  /* End the previous line of text.  */
316
  /* End the previous line of text.  */
308
  if (print.printed)
317
  if (print.printed)
309
    {
318
    {
310
      putc ('\n', print.outf);
319
      putc ('\n', stream);
311
      print.src_line++;
320
      print.src_line++;
312
      print.printed = 0;
321
      print.printed = 0;
313
    }
322
    }
 Lines 316-368   maybe_print_line (source_location src_loc) Link Here 
316
    {
325
    {
317
      while (src_line > print.src_line)
326
      while (src_line > print.src_line)
318
	{
327
	{
319
	  putc ('\n', print.outf);
328
	  putc ('\n', stream);
320
	  print.src_line++;
329
	  print.src_line++;
321
	}
330
	}
322
    }
331
    }
323
  else
332
  else
324
    print_line (src_loc, "");
333
    print_line_1 (src_loc, "", stream);
334
335
}
336
337
/* If the token read on logical line LINE needs to be output on a
338
   different line to the current one, output the required newlines or
339
   a line marker, and return 1.  Otherwise return 0.  */
340
341
static void
342
maybe_print_line (source_location src_loc)
343
{
344
  if (cpp_get_options (parse_in)->debug)
345
    linemap_dump_location (line_table, src_loc,
346
			   print.outf);
347
  maybe_print_line_1 (src_loc, print.outf);
325
}
348
}
326
349
327
/* Output a line marker for logical line LINE.  Special flags are "1"
350
/* Output a line marker for logical line LINE.  Special flags are "1"
328
   or "2" indicating entering or leaving a file.  */
351
   or "2" indicating entering or leaving a file.  */
352
329
static void
353
static void
330
print_line (source_location src_loc, const char *special_flags)
354
print_line_1 (source_location src_loc, const char *special_flags, FILE *stream)
331
{
355
{
332
  /* End any previous line of text.  */
356
  /* End any previous line of text.  */
333
  if (print.printed)
357
  if (print.printed)
334
    putc ('\n', print.outf);
358
    putc ('\n', stream);
335
  print.printed = 0;
359
  print.printed = 0;
336
360
337
  if (!flag_no_line_commands)
361
  if (!flag_no_line_commands)
338
    {
362
    {
339
      const struct line_map *map = linemap_lookup (line_table, src_loc);
363
      const char *file_path = LOCATION_FILE (src_loc);
340
364
      int sysp;
341
      size_t to_file_len = strlen (map->to_file);
365
      size_t to_file_len = strlen (file_path);
342
      unsigned char *to_file_quoted =
366
      unsigned char *to_file_quoted =
343
         (unsigned char *) alloca (to_file_len * 4 + 1);
367
         (unsigned char *) alloca (to_file_len * 4 + 1);
344
      unsigned char *p;
368
      unsigned char *p;
345
369
346
      print.src_line = SOURCE_LINE (map, src_loc);
370
      print.src_line = LOCATION_LINE (src_loc);
347
371
348
      /* cpp_quote_string does not nul-terminate, so we have to do it
372
      /* cpp_quote_string does not nul-terminate, so we have to do it
349
	 ourselves.  */
373
	 ourselves.  */
350
      p = cpp_quote_string (to_file_quoted,
374
      p = cpp_quote_string (to_file_quoted,
351
			    (const unsigned char *) map->to_file, to_file_len);
375
			    (const unsigned char *) file_path,
376
			    to_file_len);
352
      *p = '\0';
377
      *p = '\0';
353
      fprintf (print.outf, "# %u \"%s\"%s",
378
      fprintf (stream, "# %u \"%s\"%s",
354
	       print.src_line == 0 ? 1 : print.src_line,
379
	       print.src_line == 0 ? 1 : print.src_line,
355
	       to_file_quoted, special_flags);
380
	       to_file_quoted, special_flags);
356
381
357
      if (map->sysp == 2)
382
      sysp = in_system_header_at (src_loc);
358
	fputs (" 3 4", print.outf);
383
      if (sysp == 2)
359
      else if (map->sysp == 1)
384
	fputs (" 3 4", stream);
360
	fputs (" 3", print.outf);
385
      else if (sysp == 1)
386
	fputs (" 3", stream);
361
387
362
      putc ('\n', print.outf);
388
      putc ('\n', stream);
363
    }
389
    }
364
}
390
}
365
391
392
/* Output a line marker for logical line LINE.  Special flags are "1"
393
   or "2" indicating entering or leaving a file.  */
394
395
static void
396
print_line (source_location src_loc, const char *special_flags)
397
{
398
    if (cpp_get_options (parse_in)->debug)
399
      linemap_dump_location (line_table, src_loc,
400
			     print.outf);
401
    print_line_1 (src_loc, special_flags, print.outf);
402
}
403
366
/* Helper function for cb_line_change and scan_translation_unit.  */
404
/* Helper function for cb_line_change and scan_translation_unit.  */
367
static void
405
static void
368
do_line_change (cpp_reader *pfile, const cpp_token *token,
406
do_line_change (cpp_reader *pfile, const cpp_token *token,
 Lines 385-392   do_line_change (cpp_reader *pfile, const cpp_token *token, Link Here 
385
     ought to care.  Some things do care; the fault lies with them.  */
423
     ought to care.  Some things do care; the fault lies with them.  */
386
  if (!CPP_OPTION (pfile, traditional))
424
  if (!CPP_OPTION (pfile, traditional))
387
    {
425
    {
388
      const struct line_map *map = linemap_lookup (line_table, src_loc);
426
      int spaces = LOCATION_COLUMN (src_loc) - 2;
389
      int spaces = SOURCE_COLUMN (map, src_loc) - 2;
390
      print.printed = 1;
427
      print.printed = 1;
391
428
392
      while (-- spaces >= 0)
429
      while (-- spaces >= 0)
 Lines 415-420   cb_ident (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, Link Here 
415
static void
452
static void
416
cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node)
453
cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node)
417
{
454
{
455
   const struct line_map *map;
456
457
  if (line <= BUILTINS_LOCATION)
458
    return;
418
  maybe_print_line (line);
459
  maybe_print_line (line);
419
  fputs ("#define ", print.outf);
460
  fputs ("#define ", print.outf);
420
461
 Lines 426-432   cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node) Link Here 
426
    fputs ((const char *) NODE_NAME (node), print.outf);
467
    fputs ((const char *) NODE_NAME (node), print.outf);
427
468
428
  putc ('\n', print.outf);
469
  putc ('\n', print.outf);
429
  if (linemap_lookup (line_table, line)->to_line != 0)
470
  linemap_macro_loc_to_exp_point (line_table, line, &map);
471
  if (LINEMAP_LINE (map) != 0)
430
    print.src_line++;
472
    print.src_line++;
431
}
473
}
432
474
 Lines 434-439   static void Link Here 
434
cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
476
cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
435
	  cpp_hashnode *node)
477
	  cpp_hashnode *node)
436
{
478
{
479
  if (line <= BUILTINS_LOCATION)
480
    return;
437
  maybe_print_line (line);
481
  maybe_print_line (line);
438
  fprintf (print.outf, "#undef %s\n", NODE_NAME (node));
482
  fprintf (print.outf, "#undef %s\n", NODE_NAME (node));
439
  print.src_line++;
483
  print.src_line++;
(-)a/gcc/c-family/c.opt (+8 lines)
 Lines 745-750   fpreprocessed Link Here 
745
C ObjC C++ ObjC++
745
C ObjC C++ ObjC++
746
Treat the input file as already preprocessed
746
Treat the input file as already preprocessed
747
747
748
fdebug-cpp
749
C ObjC C++ ObjC++
750
Emit debug annotations during preprocessing
751
752
ftrack-macro-expansion
753
C ObjC C++ ObjC++
754
Track locations of tokens coming from macro expansion and display them in error messages
755
748
fpretty-templates
756
fpretty-templates
749
C++ ObjC++ Var(flag_pretty_templates) Init(1)
757
C++ ObjC++ Var(flag_pretty_templates) Init(1)
750
-fno-pretty-templates Do not pretty-print template specializations as the template signature followed by the arguments
758
-fno-pretty-templates Do not pretty-print template specializations as the template signature followed by the arguments
(-)a/gcc/cp/error.c (-1 / +1 lines)
 Lines 2584-2590   static void Link Here 
2584
cp_diagnostic_starter (diagnostic_context *context,
2584
cp_diagnostic_starter (diagnostic_context *context,
2585
		       diagnostic_info *diagnostic)
2585
		       diagnostic_info *diagnostic)
2586
{
2586
{
2587
  diagnostic_report_current_module (context);
2587
  diagnostic_report_current_module (context, diagnostic->location);
2588
  cp_print_error_function (context, diagnostic);
2588
  cp_print_error_function (context, diagnostic);
2589
  maybe_print_instantiation_context (context);
2589
  maybe_print_instantiation_context (context);
2590
  pp_base_set_prefix (context->printer, diagnostic_build_prefix (context,
2590
  pp_base_set_prefix (context->printer, diagnostic_build_prefix (context,
(-)a/gcc/diagnostic.c (-7 / +68 lines)
 Lines 45-50   static void diagnostic_action_after_output (diagnostic_context *, Link Here 
45
					    diagnostic_info *);
45
					    diagnostic_info *);
46
static void real_abort (void) ATTRIBUTE_NORETURN;
46
static void real_abort (void) ATTRIBUTE_NORETURN;
47
47
48
static void unwind_expanded_macro_location (diagnostic_context *, source_location,
49
					    const struct line_map **);
50
48
/* Name of program invoked, sans directories.  */
51
/* Name of program invoked, sans directories.  */
49
52
50
const char *progname;
53
const char *progname;
 Lines 241-248   diagnostic_action_after_output (diagnostic_context *context, Link Here 
241
    }
244
    }
242
}
245
}
243
246
247
/* Unwind the different macro expansions that lead the to the token
248
   which location is WHERE and emit a message "While expanding
249
   expanding macro <macro-name> at <filename>:<line>" for each macro
250
   that got expanded.  */
251
252
static void
253
unwind_expanded_macro_location (diagnostic_context *context,
254
				source_location where,
255
				const struct line_map **topmost_exp_point_map)
256
{
257
  const struct line_map *map, *resolved_map;
258
  bool unwind = true;
259
  expanded_location l;
260
  source_location resolved_location;
261
262
  map = linemap_lookup (line_table, where);
263
  if (!linemap_macro_expansion_map_p (map))
264
    return;
265
266
  while (unwind)
267
    {
268
      l = linemap_expand_location_full (line_table, where, true,
269
					&resolved_map);
270
      if (!LINEMAP_SYSP (resolved_map))
271
	{
272
	  pp_verbatim (context->printer,
273
		       "While expanding macro %s at %s:%d:%d",
274
		       linemap_map_get_macro_name (map),
275
		       LINEMAP_FILE (resolved_map),
276
		       l.line, l.column);
277
	  pp_newline (context->printer);
278
	}
279
280
      resolved_location =
281
	linemap_macro_map_loc_to_def_point (map, where, false);
282
      resolved_map = linemap_lookup (line_table, resolved_location);
283
284
      if (!linemap_macro_expansion_map_p (resolved_map))
285
	{
286
	  resolved_location =
287
	    linemap_macro_map_loc_to_exp_point (map, where);
288
	  resolved_map = linemap_lookup (line_table, resolved_location);
289
	}
290
291
      where = resolved_location;
292
      map = resolved_map;
293
294
      if (!linemap_macro_expansion_map_p (resolved_map))
295
	unwind = false;
296
    }
297
298
  if (topmost_exp_point_map)
299
    *topmost_exp_point_map = map;
300
}
301
244
void
302
void
245
diagnostic_report_current_module (diagnostic_context *context)
303
diagnostic_report_current_module (diagnostic_context *context, location_t where)
246
{
304
{
247
  const struct line_map *map;
305
  const struct line_map *map;
248
306
 Lines 252-282   diagnostic_report_current_module (diagnostic_context *context) Link Here 
252
      pp_needs_newline (context->printer) = false;
310
      pp_needs_newline (context->printer) = false;
253
    }
311
    }
254
312
255
  if (input_location <= BUILTINS_LOCATION)
313
  if (where <= BUILTINS_LOCATION)
256
    return;
314
    return;
257
315
258
  map = linemap_lookup (line_table, input_location);
316
  map = linemap_lookup (line_table, where);
259
  if (map && diagnostic_last_module_changed (context, map))
317
  if (map && diagnostic_last_module_changed (context, map))
260
    {
318
    {
261
      diagnostic_set_last_module (context, map);
319
      diagnostic_set_last_module (context, map);
320
321
      unwind_expanded_macro_location (context, where, &map);
322
262
      if (! MAIN_FILE_P (map))
323
      if (! MAIN_FILE_P (map))
263
	{
324
	{
264
	  map = INCLUDED_FROM (line_table, map);
325
	  map = INCLUDED_FROM (line_table, map);
265
	  if (context->show_column)
326
	  if (context->show_column)
266
	    pp_verbatim (context->printer,
327
	    pp_verbatim (context->printer,
267
			 "In file included from %s:%d:%d",
328
			 "In file included from %s:%d:%d",
268
			 map->to_file,
329
			 LINEMAP_FILE (map),
269
			 LAST_SOURCE_LINE (map), LAST_SOURCE_COLUMN (map));
330
			 LAST_SOURCE_LINE (map), LAST_SOURCE_COLUMN (map));
270
	  else
331
	  else
271
	    pp_verbatim (context->printer,
332
	    pp_verbatim (context->printer,
272
			 "In file included from %s:%d",
333
			 "In file included from %s:%d",
273
			 map->to_file, LAST_SOURCE_LINE (map));
334
			 LINEMAP_FILE (map), LAST_SOURCE_LINE (map));
274
	  while (! MAIN_FILE_P (map))
335
	  while (! MAIN_FILE_P (map))
275
	    {
336
	    {
276
	      map = INCLUDED_FROM (line_table, map);
337
	      map = INCLUDED_FROM (line_table, map);
277
	      pp_verbatim (context->printer,
338
	      pp_verbatim (context->printer,
278
			   ",\n                 from %s:%d",
339
			   ",\n                 from %s:%d",
279
			   map->to_file, LAST_SOURCE_LINE (map));
340
			   LINEMAP_FILE (map), LAST_SOURCE_LINE (map));
280
	    }
341
	    }
281
	  pp_verbatim (context->printer, ":");
342
	  pp_verbatim (context->printer, ":");
282
	  pp_newline (context->printer);
343
	  pp_newline (context->printer);
 Lines 288-294   void Link Here 
288
default_diagnostic_starter (diagnostic_context *context,
349
default_diagnostic_starter (diagnostic_context *context,
289
			    diagnostic_info *diagnostic)
350
			    diagnostic_info *diagnostic)
290
{
351
{
291
  diagnostic_report_current_module (context);
352
  diagnostic_report_current_module (context, diagnostic->location);
292
  pp_set_prefix (context->printer, diagnostic_build_prefix (context,
353
  pp_set_prefix (context->printer, diagnostic_build_prefix (context,
293
							    diagnostic));
354
							    diagnostic));
294
}
355
}
(-)a/gcc/diagnostic.h (-1 / +1 lines)
 Lines 223-229   extern diagnostic_context *global_dc; Link Here 
223
/* Diagnostic related functions.  */
223
/* Diagnostic related functions.  */
224
extern void diagnostic_initialize (diagnostic_context *, int);
224
extern void diagnostic_initialize (diagnostic_context *, int);
225
extern void diagnostic_finish (diagnostic_context *);
225
extern void diagnostic_finish (diagnostic_context *);
226
extern void diagnostic_report_current_module (diagnostic_context *);
226
extern void diagnostic_report_current_module (diagnostic_context *, location_t);
227
227
228
/* Force diagnostics controlled by OPTIDX to be kind KIND.  */
228
/* Force diagnostics controlled by OPTIDX to be kind KIND.  */
229
extern diagnostic_t diagnostic_classify_diagnostic (diagnostic_context *,
229
extern diagnostic_t diagnostic_classify_diagnostic (diagnostic_context *,
(-)a/gcc/fortran/cpp.c (-7 / +11 lines)
 Lines 780-805   print_line (source_location src_loc, const char *special_flags) Link Here 
780
  if (!gfc_cpp_option.no_line_commands)
780
  if (!gfc_cpp_option.no_line_commands)
781
    {
781
    {
782
      const struct line_map *map = linemap_lookup (line_table, src_loc);
782
      const struct line_map *map = linemap_lookup (line_table, src_loc);
783
      struct expanded_location loc;
783
784
784
      size_t to_file_len = strlen (map->to_file);
785
      size_t to_file_len;
785
      unsigned char *to_file_quoted =
786
      unsigned char *to_file_quoted;
786
         (unsigned char *) alloca (to_file_len * 4 + 1);
787
      unsigned char *p;
787
      unsigned char *p;
788
788
789
      print.src_line = SOURCE_LINE (map, src_loc);
789
      loc = expand_location (src_loc);
790
      to_file_len = strlen (loc.file);
791
      to_file_quoted = (unsigned char *) alloca (to_file_len * 4 + 1);
792
793
      print.src_line = loc.line;
790
794
791
      /* cpp_quote_string does not nul-terminate, so we have to do it
795
      /* cpp_quote_string does not nul-terminate, so we have to do it
792
	 ourselves.  */
796
	 ourselves.  */
793
      p = cpp_quote_string (to_file_quoted,
797
      p = cpp_quote_string (to_file_quoted,
794
			    (const unsigned char *) map->to_file, to_file_len);
798
			    (const unsigned char *) loc.file, to_file_len);
795
      *p = '\0';
799
      *p = '\0';
796
      fprintf (print.outf, "# %u \"%s\"%s",
800
      fprintf (print.outf, "# %u \"%s\"%s",
797
	       print.src_line == 0 ? 1 : print.src_line,
801
	       print.src_line == 0 ? 1 : print.src_line,
798
	       to_file_quoted, special_flags);
802
	       to_file_quoted, special_flags);
799
803
800
      if (map->sysp == 2)
804
      if (loc.sysp == 2)
801
	fputs (" 3 4", print.outf);
805
	fputs (" 3 4", print.outf);
802
      else if (map->sysp == 1)
806
      else if (loc.sysp == 1)
803
	fputs (" 3", print.outf);
807
	fputs (" 3", print.outf);
804
808
805
      putc ('\n', print.outf);
809
      putc ('\n', print.outf);
(-)a/gcc/input.c (-9 / +16 lines)
 Lines 35-53   expand_location (source_location loc) Link Here 
35
{
35
{
36
  expanded_location xloc;
36
  expanded_location xloc;
37
  if (loc <= BUILTINS_LOCATION)
37
  if (loc <= BUILTINS_LOCATION)
38
    {
38
    {      
39
      xloc.file = loc == UNKNOWN_LOCATION ? NULL : _("<built-in>");
39
      /* If LOC is UNKNOWN_LOCATION and there was a map allocated for
40
	 it then XLOC.FILE should be the file path of the map,
41
	 i.e. the file path of the main file being compiled.
42
	 Otherwise [if we are being called before any line map has
43
	 been allocated, e.g. during parsing of commande line
44
	 options] if no line map has been allocated yet, then
45
	 XLOC.FILE should just be NULL.  */
46
      if (loc == UNKNOWN_LOCATION)
47
	{
48
	  const struct line_map *map = linemap_lookup (line_table, UNKNOWN_LOCATION);
49
	  xloc.file = map != NULL ? LINEMAP_FILE (map) : NULL;
50
	}
51
      else
52
	xloc.file = _("<built-in>");
40
      xloc.line = 0;
53
      xloc.line = 0;
41
      xloc.column = 0;
54
      xloc.column = 0;
42
      xloc.sysp = 0;
55
      xloc.sysp = 0;
43
    }
56
    }
44
  else
57
  else
45
    {
58
    xloc = linemap_expand_location_full (line_table, loc, false, NULL);
46
      const struct line_map *map = linemap_lookup (line_table, loc);
47
      xloc.file = map->to_file;
48
      xloc.line = SOURCE_LINE (map, loc);
49
      xloc.column = SOURCE_COLUMN (map, loc);
50
      xloc.sysp = map->sysp != 0;
51
    };
52
  return xloc;
59
  return xloc;
53
}
60
}
(-)a/gcc/input.h (-16 / +4 lines)
 Lines 37-56   extern GTY(()) struct line_maps *line_table; Link Here 
37
extern char builtins_location_check[(BUILTINS_LOCATION
37
extern char builtins_location_check[(BUILTINS_LOCATION
38
				     < RESERVED_LOCATION_COUNT) ? 1 : -1];
38
				     < RESERVED_LOCATION_COUNT) ? 1 : -1];
39
39
40
typedef struct GTY (())
41
{
42
  /* The name of the source file involved.  */
43
  const char *file;
44
45
  /* The line-location in the source file.  */
46
  int line;
47
48
  int column;
49
50
  /* In a system header?. */
51
  bool sysp;
52
} expanded_location;
53
54
extern expanded_location expand_location (source_location);
40
extern expanded_location expand_location (source_location);
55
41
56
/* Historically GCC used location_t, while cpp used source_location.
42
/* Historically GCC used location_t, while cpp used source_location.
 Lines 61-70   extern location_t input_location; Link Here 
61
47
62
#define LOCATION_FILE(LOC) ((expand_location (LOC)).file)
48
#define LOCATION_FILE(LOC) ((expand_location (LOC)).file)
63
#define LOCATION_LINE(LOC) ((expand_location (LOC)).line)
49
#define LOCATION_LINE(LOC) ((expand_location (LOC)).line)
50
#define LOCATION_COLUMN(LOC)((expand_location (LOC)).column)
64
51
65
#define input_line LOCATION_LINE (input_location)
52
#define input_line LOCATION_LINE (input_location)
66
#define input_filename LOCATION_FILE (input_location)
53
#define input_filename LOCATION_FILE (input_location)
67
#define in_system_header_at(LOC) ((expand_location (LOC)).sysp != 0)
54
#define in_system_header_at(LOC) \
68
#define in_system_header (in_system_header_at (input_location))
55
  ((linemap_location_in_system_header_p (line_table, LOC)))
56
#define in_system_header  (in_system_header_at (input_location))
69
57
70
#endif
58
#endif
(-)a/gcc/testsuite/gcc.dg/assign-warn-1.c (-2 / +6 lines)
 Lines 1-7    Link Here 
1
/* Test diagnostics for bad implicit type conversions.  */
1
/* Test diagnostics for bad implicit type conversions.  */
2
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
2
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
3
/* { dg-do compile } */
3
/* { dg-do compile } */
4
/* { dg-options "-pedantic" } */
4
/* { dg-options "-pedantic -ftrack-macro-expansion" } */
5
5
6
#define TESTARG(ID, TL, TR) void ID##F(TL); void ID##F2(TR x) { ID##F(x); } extern int dummy
6
#define TESTARG(ID, TL, TR) void ID##F(TL); void ID##F2(TR x) { ID##F(x); } extern int dummy
7
#define TESTARP(ID, TL, TR) struct { void (*x)(TL); } ID##Fp; void ID##F2(TR x) { ID##Fp.x(x); } extern int dummy
7
#define TESTARP(ID, TL, TR) struct { void (*x)(TL); } ID##Fp; void ID##F2(TR x) { ID##Fp.x(x); } extern int dummy
 Lines 125-128   TESTINI(istrd, int, struct s); /* { dg-error "incompatible types when initializi Link Here 
125
TESTRET(istre, int, struct s); /* { dg-error "incompatible types when returning type 'struct s' but 'int' was expected" } */
125
TESTRET(istre, int, struct s); /* { dg-error "incompatible types when returning type 'struct s' but 'int' was expected" } */
126
126
127
/* Match all extra informative notes.  */
127
/* Match all extra informative notes.  */
128
/* { dg-message "note: expected '\[^\n'\]*' but argument is of type '\[^\n'\]*'" "note: expected" { target *-*-* } 0 } */
128
/* { dg-message "note: expected '\[^\n'\]*' but argument is of type '\[^\n'\]*'" "note: expected" { target *-*-* } 0 }
129
130
  { dg-message "expanding macro" "expanding macro" { target *-*-* } 0 }
131
132
 */
(-)a/gcc/testsuite/gcc.dg/assign-warn-2.c (-1 / +22 lines)
 Lines 2-8    Link Here 
2
   -pedantic-errors test.  */
2
   -pedantic-errors test.  */
3
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
3
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
4
/* { dg-do compile } */
4
/* { dg-do compile } */
5
/* { dg-options "-pedantic-errors" } */
5
/* { dg-options "-pedantic-errors -ftrack-macro-expansion" } */
6
6
7
#define TESTARG(ID, TL, TR) void ID##F(TL); void ID##F2(TR x) { ID##F(x); } extern int dummy
7
#define TESTARG(ID, TL, TR) void ID##F(TL); void ID##F2(TR x) { ID##F(x); } extern int dummy
8
#define TESTARP(ID, TL, TR) struct { void (*x)(TL); } ID##Fp; void ID##F2(TR x) { ID##Fp.x(x); } extern int dummy
8
#define TESTARP(ID, TL, TR) struct { void (*x)(TL); } ID##Fp; void ID##F2(TR x) { ID##Fp.x(x); } extern int dummy
 Lines 123-125   TESTASS(istrc, int, struct s); /* { dg-error "incompatible types when assigning Link Here 
123
TESTINI(istrd, int, struct s); /* { dg-error "incompatible types when initializing type 'int' using type 'struct s'" } */
123
TESTINI(istrd, int, struct s); /* { dg-error "incompatible types when initializing type 'int' using type 'struct s'" } */
124
TESTRET(istre, int, struct s); /* { dg-error "incompatible types when returning type 'struct s' but 'int' was expected" } */
124
TESTRET(istre, int, struct s); /* { dg-error "incompatible types when returning type 'struct s' but 'int' was expected" } */
125
/* { dg-message "note: expected '\[^'\n\]*' but argument is of type '\[^'\n\]*'" "note: expected" { target *-*-* } 0 } */
125
/* { dg-message "note: expected '\[^'\n\]*' but argument is of type '\[^'\n\]*'" "note: expected" { target *-*-* } 0 } */
126
127
/*
128
  { dg-message "expanding macro TESTARP\[^\\n\\r\]*:8:36" "While expanding macro TESTARP" { target *-*-* } 0 }
129
130
  { dg-message "expanding macro TESTASS\[^\\n\\r\]*:9:56" "While expanding macro TESTASS" { target *-*-* } 0 }
131
132
  { dg-message "expanding macro TESTINI\[^\\n\\r\]*:10:55" "While expanding macro TESTINI" { target *-*-* } 0 }
133
134
  { dg-message "expanding macro TESTRET\[^\\n\\r\]*:11:56" "While expanding macro TESTRET" { target *-*-* } 0 }
135
136
  { dg-message "expanding macro TESTARG\[^\\n\\r\]*:7:40" "While expanding macro TESTARG" { target *-*-* } 0 }
137
138
  { dg-message "expanding macro TESTARP\[^\\n\\r\]*:8:48" "While expanding macro TESTARP" { target *-*-* } 0 }
139
140
  { dg-message "expanding macro TESTINI\[^\\n\\r\]*:10:48" "While expanding macro TESTINI" { target *-*-* } 0 }
141
142
  { dg-message "expanding macro TESTARG\[^\\n\\r\]*:7:57" "While expanding macro TESTARG" { target *-*-* } 0 }
143
144
  { dg-message "expanding macro TESTARP\[^\\n\\r\]*:8:75" "While expanding macro TESTARP" { target *-*-* } 0 }
145
146
*/
(-)a/gcc/testsuite/gcc.dg/attr-alloc_size.c (-1 / +5 lines)
 Lines 1-5    Link Here 
1
/* { dg-do compile } */
1
/* { dg-do compile } */
2
/* { dg-options "-O2 -Wall" } */
2
/* { dg-options "-O2 -Wall -ftrack-macro-expansion" } */
3
3
4
extern void abort (void);
4
extern void abort (void);
5
5
 Lines 34-36   test (void) Link Here 
34
  strcpy (p, "Hello World"); /* { dg-warning "will always overflow" "strcpy" } */
34
  strcpy (p, "Hello World"); /* { dg-warning "will always overflow" "strcpy" } */
35
}
35
}
36
36
37
/* Match extra informative messages:
38
39
   { dg-message "expanding macro strcpy at \[^\\n\\r\]*21:26" "While expanding macro strcpy" { target *-*-* } 0 }
40
 */
(-)a/gcc/testsuite/gcc.dg/builtin-stringop-chk-1.c (-1 / +27 lines)
 Lines 1-7    Link Here 
1
/* Test whether buffer overflow warnings for __*_chk builtins
1
/* Test whether buffer overflow warnings for __*_chk builtins
2
   are emitted properly.  */
2
   are emitted properly.  */
3
/* { dg-do compile } */
3
/* { dg-do compile } */
4
/* { dg-options "-O2 -std=gnu99" } */
4
/* { dg-options "-O2 -std=gnu99 -ftrack-macro-expansion" } */
5
/* { dg-options "-mstructure-size-boundary=8 -O2 -std=gnu99" { target arm-*-* } } */
5
/* { dg-options "-mstructure-size-boundary=8 -O2 -std=gnu99" { target arm-*-* } } */
6
6
7
extern void abort (void);
7
extern void abort (void);
 Lines 112-114   test2 (const H h) Link Here 
112
  memset (b1, 0, sizeof (b1));
112
  memset (b1, 0, sizeof (b1));
113
  memset (b2, 0, sizeof (b1)); /* { dg-warning "will always overflow" "memset" } */
113
  memset (b2, 0, sizeof (b1)); /* { dg-warning "will always overflow" "memset" } */
114
}
114
}
115
116
/*
117
  { dg-message "expanding macro memcpy\[^\\n\\r\]*chk.h:9:26" "expanding macro memcpy" { target *-*-* } 0 }
118
119
  { dg-message "expanding macro mempcpy\[^\\n\\r\]*chk.h:12:27" "expanding macro mempcpy" { target *-*-* } 0 }
120
121
  { dg-message "expanding macro memmove\[^\\n\\r\]*chk.h:15:27" "expanding macro memmove" { target *-*-* } 0 }
122
123
  { dg-message "expanding macro memset\[^\\n\\r\]*chk.h:18:26" "expanding macro memset" { target *-*-* } 0 }
124
125
  { dg-message "expanding macro strcpy\[^\\n\\r\]*chk.h:21:26" "expanding macro strcpy" { target *-*-* } 0 }
126
127
  { dg-message "expanding macro stpcpy\[^\\n\\r\]*chk.h:24:26" "expanding macro stpcpy" { target *-*-* } 0 }
128
129
  { dg-message "expanding macro strncpy\[^\\n\\r\]*chk.h:30:27" "expanding macro strncpy" { target *-*-* } 0 }
130
  
131
  { dg-message "expanding macro strcat\[^\\n\\r\]*chk.h:27:26" "expanding macro strcat" { target *-*-* } 0 }
132
133
  { dg-message "expanding macro sprintf\[^\\n\\r\]*chk.h:36:27" "expanding macro sprintf" { target *-*-* } 0 }
134
135
  { dg-message "expanding macro snprintf\[^\\n\\r\]*chk.h:42:28" "expanding macro snprintf" { target *-*-* } 0 }
136
137
  { dg-message "expanding macro vsprintf\[^\\n\\r\]*chk.h:39:28" "expanding macro vsprintf" { target *-*-* } 0 }
138
139
  { dg-message "expanding macro vsnprintf\[^\\n\\r\]*chk.h:45:29" "expanding macro vsnprintf" { target *-*-* } 0 }
140
 */
(-)a/gcc/testsuite/gcc.dg/builtin-stringop-chk-2.c (-1 / +5 lines)
 Lines 3-9    Link Here 
3
   incorrectly determined to be 0 while it should be (size_t) -1
3
   incorrectly determined to be 0 while it should be (size_t) -1
4
   (== unknown).  */
4
   (== unknown).  */
5
/* { dg-do compile } */
5
/* { dg-do compile } */
6
/* { dg-options "-O2" } */
6
/* { dg-options "-O2 -ftrack-macro-expansion" } */
7
7
8
#include "../gcc.c-torture/execute/builtins/chk.h"
8
#include "../gcc.c-torture/execute/builtins/chk.h"
9
   
9
   
 Lines 135-137   baz (const struct A *x, const unsigned char *z) Link Here 
135
    }
135
    }
136
  return c;
136
  return c;
137
}
137
}
138
139
/*
140
  { dg-message "expanding macro memcpy at\[^\\n\\r\]*chk.h:9:26" "While expanding macro memcpy" { target *-*-* } 0 }
141
*/
(-)a/gcc/testsuite/gcc.dg/builtin-strncat-chk-1.c (-1 / +6 lines)
 Lines 1-7    Link Here 
1
/* Test whether buffer overflow warnings for __strncat_chk builtin
1
/* Test whether buffer overflow warnings for __strncat_chk builtin
2
   are emitted properly.  */
2
   are emitted properly.  */
3
/* { dg-do compile } */
3
/* { dg-do compile } */
4
/* { dg-options "-O2 -std=gnu99" } */
4
/* { dg-options "-O2 -std=gnu99 -ftrack-macro-expansion" } */
5
5
6
extern void abort (void);
6
extern void abort (void);
7
7
 Lines 36-38   test (int arg, ...) Link Here 
36
  *p = 0;
36
  *p = 0;
37
  strncat (p, q, 11); /* { dg-warning "might overflow" } */
37
  strncat (p, q, 11); /* { dg-warning "might overflow" } */
38
}
38
}
39
40
/*
41
   { dg-message "expanding macro strncat at\[^\\n\\r\]*chk.h:33:27" "expanding macro strncat" { target *-*-* } 0 }
42
43
 */
(-)a/gcc/testsuite/gcc.dg/c90-const-expr-9.c (-1 / +5 lines)
 Lines 3-9    Link Here 
3
   expansion.  */
3
   expansion.  */
4
/* Origin: Joseph Myers <joseph@codesourcery.com> */
4
/* Origin: Joseph Myers <joseph@codesourcery.com> */
5
/* { dg-do compile } */
5
/* { dg-do compile } */
6
/* { dg-options "-std=iso9899:1990 -pedantic-errors" } */
6
/* { dg-options "-std=iso9899:1990 -pedantic-errors -ftrack-macro-expansion" } */
7
7
8
struct s {
8
struct s {
9
  int a;
9
  int a;
 Lines 26-28   enum e { Link Here 
26
  E5 = __builtin_offsetof (struct t, a.a),
26
  E5 = __builtin_offsetof (struct t, a.a),
27
  E6 = __builtin_offsetof (struct t, b[1])
27
  E6 = __builtin_offsetof (struct t, b[1])
28
};
28
};
29
30
/*
31
  { dg-message "expanding macro old_offsetof at\[^\\n\\r\]*:19:36" "expanding macro old_offsetof" { target *-*-* } 0 }
32
 */
(-)a/gcc/testsuite/gcc.dg/c99-const-expr-9.c (-1 / +6 lines)
 Lines 3-9    Link Here 
3
   expansion.  */
3
   expansion.  */
4
/* Origin: Joseph Myers <joseph@codesourcery.com> */
4
/* Origin: Joseph Myers <joseph@codesourcery.com> */
5
/* { dg-do compile } */
5
/* { dg-do compile } */
6
/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
6
/* { dg-options "-std=iso9899:1999 -pedantic-errors -ftrack-macro-expansion" } */
7
7
8
struct s {
8
struct s {
9
  int a;
9
  int a;
 Lines 24-26   enum e { Link Here 
24
  E5 = __builtin_offsetof (struct t, a.a),
24
  E5 = __builtin_offsetof (struct t, a.a),
25
  E6 = __builtin_offsetof (struct t, b[1])
25
  E6 = __builtin_offsetof (struct t, b[1])
26
};
26
};
27
28
/*
29
  { dg-message "expanding macro old_offsetof at\[^\\n\\r\]*:17:36" "expanding macro old_offsetof" { target *-*-* } 0 }
30
31
*/
(-)a/gcc/testsuite/gcc.dg/cpp/direct2.c (-3 / +18 lines)
 Lines 4-10    Link Here 
4
/* Test of prohibition on directives which result from macro expansion.
4
/* Test of prohibition on directives which result from macro expansion.
5
   See also direct2s.c */
5
   See also direct2s.c */
6
6
7
/* { dg-do compile } */
7
/*
8
  { dg-options "-ftrack-macro-expansion" }
9
  { dg-do compile }
10
11
 */
8
12
9
#define HASH #
13
#define HASH #
10
#define HASHDEFINE #define
14
#define HASHDEFINE #define
 Lines 12-18    Link Here 
12
16
13
HASH include "somerandomfile" /*{ dg-error "stray" "non-include" }*/
17
HASH include "somerandomfile" /*{ dg-error "stray" "non-include" }*/
14
/*{ dg-bogus "No such" "don't execute non-include" { target *-*-* } 13 }*/
18
/*{ dg-bogus "No such" "don't execute non-include" { target *-*-* } 13 }*/
15
int resync_parser_1; /*{ dg-error "parse|syntax|expected" "" { target *-*-* } 13 }*/
19
int resync_parser_1; /*{ dg-error "parse|syntax|expected" "" { target *-*-* } 17 }*/
16
20
17
HASHINCLUDE <somerandomfile> /*{ dg-error "stray|expected" "non-include 2" }*/
21
HASHINCLUDE <somerandomfile> /*{ dg-error "stray|expected" "non-include 2" }*/
18
/*{ dg-bogus "No such" "don't execute non-include 2" { target *-*-* } 17 }*/
22
/*{ dg-bogus "No such" "don't execute non-include 2" { target *-*-* } 17 }*/
 Lines 43-46   void f () Link Here 
43
#define starslash *##/
47
#define starslash *##/
44
48
45
slashstar starslash /* { dg-error "parse error|syntax error|expected" "not a comment" } */
49
slashstar starslash /* { dg-error "parse error|syntax error|expected" "not a comment" } */
46
/* { dg-error "does not give" "paste warning(s)" { target *-*-* } 45 } */
50
/* { dg-error "does not give" "paste warning(s)" { target *-*-* } 49 } */
51
52
/* The messages below are preambles of error messages emitted when expanding
53
   macros HASH in g1 and HASHDEFINE in g2.
54
   They doesn't have any line number associated because they are part of the
55
   "module" information: They have the form:
56
   While expanding macro foo at file.c:2:10
57
   This is similar to the test for " syshdr.c in t*/
58
/* { dg-message "expanding macro HASH at \[^\\n\\r\]*direct2.c:13:14" "While expanding macro HASH"  { target *-*-* } 0 } */
59
/* { dg-message "expanding macro HASHDEFINE at \[^\\n\\r\]*direct2.c:14:20" "While expanding macro HASHDEFINE"  { target *-*-* } 0 } */
60
/* { dg-message "expanding macro HASHINCLUDE at \[^\\n\\r\]*direct2.c:15:21" "While expanding macro HASHINCLUDE"  { target *-*-* } 0 } */
61
(-)a/gcc/testsuite/gcc.dg/dfp/composite-type.c (-1 / +10 lines)
 Lines 1-5    Link Here 
1
/* { dg-do compile } */
1
/* { dg-do compile } */
2
/* { dg-options "-O -Wall" } */
2
/* { dg-options "-O -Wall -ftrack-macro-expansion" } */
3
3
4
/* C99 6.2.7: Compatible type and composite type.  */
4
/* C99 6.2.7: Compatible type and composite type.  */
5
5
 Lines 53-55   int main() Link Here 
53
53
54
  return 0;
54
  return 0;
55
}
55
}
56
57
/* The messages below are preambles of error messages emitted when expanding
58
   macros.
59
   They doesn't have any line number associated because they are part of the
60
   "module" information: They have the form:
61
   While expanding macro foo at file.c:2:10.  */
62
63
/* { dg-message "expanding macro DECIMAL_COMPOSITE_DECL at \[^\\n\\r\]*composite-type.c:18:14" "While expanding macro DECIMAL_COMPOSITE_DECL"  { target *-*-* } 0 } */
64
(-)a/gcc/testsuite/gcc.dg/dfp/operator-bitwise.c (-1 / +20 lines)
 Lines 1-4    Link Here 
1
/* { dg-do compile } */
1
/* { dg-do compile }
2
   { dg-options "-ftrack-macro-expansion" } */
2
3
3
/* C99 6.5.10: Bitwise AND operator.
4
/* C99 6.5.10: Bitwise AND operator.
4
   C99 6.5.11: Bitwise exclusive OR operator.
5
   C99 6.5.11: Bitwise exclusive OR operator.
 Lines 61-63   void operator_notfor_decimal() Link Here 
61
  DECIMAL_BITWISE_OPERATOR(^,d64); /* { dg-error "invalid operands to binary" } */
62
  DECIMAL_BITWISE_OPERATOR(^,d64); /* { dg-error "invalid operands to binary" } */
62
  DECIMAL_BITWISE_OPERATOR(^,d128); /* { dg-error "invalid operands to binary" } */
63
  DECIMAL_BITWISE_OPERATOR(^,d128); /* { dg-error "invalid operands to binary" } */
63
}
64
}
65
66
/*
67
68
{ dg-message "expanding macro OPERATE at \[^\\n\\r\]*operator-bitwise.c:13:9" "While expanding macro OPERATE"  { target *-*-* } 0 }
69
70
{ dg-message "expanding macro DECIMAL_BITWISE_OPERATOR at \[^\\n\\r\]*operator-bitwise.c:21:14" "While expanding macro DECIMAL_BITWISE_OPERATOR"  { target *-*-* } 0 }
71
72
{ dg-message "expanding macro DECIMAL_BITWISE_OPERATOR at \[^\\n\\r\]*operator-bitwise.c:22:14" "While expanding macro DECIMAL_BITWISE_OPERATOR"  { target *-*-* } 0 }
73
74
{ dg-message "expanding macro DECIMAL_BITWISE_OPERATOR at \[^\\n\\r\]*operator-bitwise.c:23:14" "While expanding macro DECIMAL_BITWISE_OPERATOR"  { target *-*-* } 0 }
75
76
{ dg-message "expanding macro DECIMAL_BITWISE_OPERATOR at \[^\\n\\r\]*operator-bitwise.c:24:11" "While expanding macro DECIMAL_BITWISE_OPERATOR"  { target *-*-* } 0 }
77
78
{ dg-message "expanding macro DECIMAL_BITWISE_OPERATOR at \[^\\n\\r\]*operator-bitwise.c:25:11" "While expanding macro DECIMAL_BITWISE_OPERATOR"  { target *-*-* } 0 }
79
80
{ dg-message "expanding macro DECIMAL_BITWISE_OPERATOR at \[^\\n\\r\]*operator-bitwise.c:26:14" "While expanding macro DECIMAL_BITWISE_OPERATOR"  { target *-*-* } 0 }
81
82
*/
(-)a/gcc/testsuite/gcc.dg/uninit-6-O0.c (-1 / +5 lines)
 Lines 2-8    Link Here 
2
   This one inspired by java/class.c:build_utf8_ref.  */
2
   This one inspired by java/class.c:build_utf8_ref.  */
3
3
4
/* { dg-do compile } */
4
/* { dg-do compile } */
5
/* { dg-options "-Wuninitialized" } */
5
/* { dg-options "-Wuninitialized -ftrack-macro-expansion" } */
6
6
7
#include <stddef.h>
7
#include <stddef.h>
8
8
 Lines 45-47   make_something(int a, int b, int c) Link Here 
45
45
46
    return rv;
46
    return rv;
47
}
47
}
48
49
/*
50
  { dg-message "expanding macro APPEND at\[^\\n\\r\]*uninit-6-O0.c:27:13" "expanding macro APPEND" { target *-*-* } 0 }
51
 */
(-)a/gcc/testsuite/gcc.target/i386/sse-vect-types.c (-1 / +5 lines)
 Lines 11-14   __m128d foo1(__m128d z, __m128d a, int N) { Link Here 
11
  }
11
  }
12
  return a;
12
  return a;
13
}
13
}
14
/* { dg-message "note: expected '\[^'\n\]*' but argument is of type '\[^'\n\]*'" "note: expected" { target *-*-* } 0 } */
14
/* { dg-message "note: expected '\[^'\n\]*' but argument is of type '\[^'\n\]*'" "note: expected" { target *-*-* } 0 }
15
   
16
   { dg-message "file included from \[^\\n\\r\]*sse-vect-types.c:5" "In file included from" { target *-*-* } 0 }
17
18
 */
(-)a/gcc/toplev.c (+1 lines)
 Lines 2431-2433   toplev_main (int argc, char **argv) Link Here 
2431
2431
2432
  return (SUCCESS_EXIT_CODE);
2432
  return (SUCCESS_EXIT_CODE);
2433
}
2433
}
2434
(-)a/gcc/tree-diagnostic.c (-1 / +1 lines)
 Lines 35-41   void Link Here 
35
diagnostic_report_current_function (diagnostic_context *context,
35
diagnostic_report_current_function (diagnostic_context *context,
36
				    diagnostic_info *diagnostic)
36
				    diagnostic_info *diagnostic)
37
{
37
{
38
  diagnostic_report_current_module (context);
38
  diagnostic_report_current_module (context, diagnostic->location);
39
  lang_hooks.print_error_function (context, input_filename, diagnostic);
39
  lang_hooks.print_error_function (context, input_filename, diagnostic);
40
}
40
}
41
41
(-)a/libcpp/directives.c (-5 / +5 lines)
 Lines 887-895   do_line (cpp_reader *pfile) Link Here 
887
  /* skip_rest_of_line() may cause line table to be realloc()ed so note down
887
  /* skip_rest_of_line() may cause line table to be realloc()ed so note down
888
     sysp right now.  */
888
     sysp right now.  */
889
889
890
  unsigned char map_sysp = map->sysp;
890
  unsigned char map_sysp = map->d.ordinary.sysp;
891
  const cpp_token *token;
891
  const cpp_token *token;
892
  const char *new_file = map->to_file;
892
  const char *new_file = map->d.ordinary.to_file;
893
  linenum_type new_lineno;
893
  linenum_type new_lineno;
894
894
895
  /* C99 raised the minimum limit on #line numbers.  */
895
  /* C99 raised the minimum limit on #line numbers.  */
 Lines 946-954   do_linemarker (cpp_reader *pfile) Link Here 
946
  const struct line_maps *line_table = pfile->line_table;
946
  const struct line_maps *line_table = pfile->line_table;
947
  const struct line_map *map = &line_table->maps[line_table->used - 1];
947
  const struct line_map *map = &line_table->maps[line_table->used - 1];
948
  const cpp_token *token;
948
  const cpp_token *token;
949
  const char *new_file = map->to_file;
949
  const char *new_file = map->d.ordinary.to_file;
950
  linenum_type new_lineno;
950
  linenum_type new_lineno;
951
  unsigned int new_sysp = map->sysp;
951
  unsigned int new_sysp = map->d.ordinary.sysp;
952
  enum lc_reason reason = LC_RENAME_VERBATIM;
952
  enum lc_reason reason = LC_RENAME_VERBATIM;
953
  int flag;
953
  int flag;
954
  bool wrapped;
954
  bool wrapped;
 Lines 1036-1042   _cpp_do_file_change (cpp_reader *pfile, enum lc_reason reason, Link Here 
1036
  const struct line_map *map = linemap_add (pfile->line_table, reason, sysp,
1036
  const struct line_map *map = linemap_add (pfile->line_table, reason, sysp,
1037
					    to_file, file_line);
1037
					    to_file, file_line);
1038
  if (map != NULL)
1038
  if (map != NULL)
1039
    linemap_line_start (pfile->line_table, map->to_line, 127);
1039
    linemap_line_start (pfile->line_table, map->d.ordinary.to_line, 127);
1040
1040
1041
  if (pfile->cb.file_change)
1041
  if (pfile->cb.file_change)
1042
    pfile->cb.file_change (pfile, map);
1042
    pfile->cb.file_change (pfile, map);
(-)a/libcpp/files.c (-1 / +1 lines)
 Lines 1227-1233   cpp_make_system_header (cpp_reader *pfile, int syshdr, int externc) Link Here 
1227
  if (syshdr)
1227
  if (syshdr)
1228
    flags = 1 + (externc != 0);
1228
    flags = 1 + (externc != 0);
1229
  pfile->buffer->sysp = flags;
1229
  pfile->buffer->sysp = flags;
1230
  _cpp_do_file_change (pfile, LC_RENAME, map->to_file,
1230
  _cpp_do_file_change (pfile, LC_RENAME, map->d.ordinary.to_file,
1231
		       SOURCE_LINE (map, pfile->line_table->highest_line), flags);
1231
		       SOURCE_LINE (map, pfile->line_table->highest_line), flags);
1232
}
1232
}
1233
1233
(-)a/libcpp/include/cpp-id-data.h (+6 lines)
 Lines 34-39   struct GTY(()) answer { Link Here 
34
/* Each macro definition is recorded in a cpp_macro structure.
34
/* Each macro definition is recorded in a cpp_macro structure.
35
   Variadic macros cannot occur with traditional cpp.  */
35
   Variadic macros cannot occur with traditional cpp.  */
36
struct GTY(()) cpp_macro {
36
struct GTY(()) cpp_macro {
37
  /* Name of this macro.  Used only for error reporting.  */
38
  cpp_hashnode * GTY ((nested_ptr (union tree_node,
39
		"%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
40
				   "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL")))
41
    name;
42
37
  /* Parameters, if any.  */
43
  /* Parameters, if any.  */
38
  cpp_hashnode ** GTY ((nested_ptr (union tree_node,
44
  cpp_hashnode ** GTY ((nested_ptr (union tree_node,
39
		"%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
45
		"%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
(-)a/libcpp/include/cpplib.h (-2 / +10 lines)
 Lines 388-393   struct cpp_options Link Here 
388
  /* Nonzero means we're looking at already preprocessed code, so don't
388
  /* Nonzero means we're looking at already preprocessed code, so don't
389
     bother trying to do macro expansion and whatnot.  */
389
     bother trying to do macro expansion and whatnot.  */
390
  unsigned char preprocessed;
390
  unsigned char preprocessed;
391
  
392
  /* Nonzero means we are going to emit debugging logs during
393
     preprocessing.  */
394
  unsigned char debug;
395
396
  /* Nonzero means we are tracking locations of tokens involved in
397
     macro expansion.  */
398
  unsigned char track_macro_expansion;
391
399
392
  /* Nonzero means handle C++ alternate operator names.  */
400
  /* Nonzero means handle C++ alternate operator names.  */
393
  unsigned char operator_names;
401
  unsigned char operator_names;
 Lines 723-730   extern void cpp_register_deferred_pragma (cpp_reader *, const char *, Link Here 
723
extern int cpp_avoid_paste (cpp_reader *, const cpp_token *,
731
extern int cpp_avoid_paste (cpp_reader *, const cpp_token *,
724
			    const cpp_token *);
732
			    const cpp_token *);
725
extern const cpp_token *cpp_get_token (cpp_reader *);
733
extern const cpp_token *cpp_get_token (cpp_reader *);
726
extern const cpp_token *cpp_get_token_with_location (cpp_reader *,
734
extern const cpp_token * cpp_get_token_with_location (cpp_reader *,
727
						     source_location *);
735
						      source_location *);
728
extern const unsigned char *cpp_macro_definition (cpp_reader *,
736
extern const unsigned char *cpp_macro_definition (cpp_reader *,
729
						  const cpp_hashnode *);
737
						  const cpp_hashnode *);
730
extern void _cpp_backup_tokens (cpp_reader *, unsigned int);
738
extern void _cpp_backup_tokens (cpp_reader *, unsigned int);
(-)a/libcpp/include/line-map.h (-37 / +290 lines)
 Lines 33-88   along with this program; see the file COPYING3. If not see Link Here 
33
   name or line number changes for neither of the above reasons
33
   name or line number changes for neither of the above reasons
34
   (e.g. a #line directive in C); LC_RENAME_VERBATIM is like LC_RENAME
34
   (e.g. a #line directive in C); LC_RENAME_VERBATIM is like LC_RENAME
35
   but a filename of "" is not specially interpreted as standard input.  */
35
   but a filename of "" is not specially interpreted as standard input.  */
36
enum lc_reason {LC_ENTER = 0, LC_LEAVE, LC_RENAME, LC_RENAME_VERBATIM};
36
enum lc_reason
37
{
38
  LC_ENTER = 0,
39
  LC_LEAVE,
40
  LC_RENAME,
41
  LC_RENAME_VERBATIM,
42
  LC_ENTER_MACRO
43
  /* stringize */
44
  /* paste */
45
};
37
46
38
/* The type of line numbers.  */
47
/* The type of line numbers.  */
39
typedef unsigned int linenum_type;
48
typedef unsigned int linenum_type;
40
49
41
/* A logical line/column number, i.e. an "index" into a line_map.  */
50
/* A logical line/column number, i.e. an "index" into a line_map.  */
42
/* Long-term, we want to use this to replace struct location_s (in input.h),
43
   and effectively typedef source_location location_t.  */
44
typedef unsigned int source_location;
51
typedef unsigned int source_location;
45
52
46
/* Memory allocation function typedef.  Works like xrealloc.  */
53
/* Memory allocation function typedef.  Works like xrealloc.  */
47
typedef void *(*line_map_realloc) (void *, size_t);
54
typedef void *(*line_map_realloc) (void *, size_t);
48
55
49
/* Physical source file TO_FILE at line TO_LINE at column 0 is represented
56
/* An ordinary line map encodes physical source locations.
57
   
58
   Physical source file TO_FILE at line TO_LINE at column 0 is represented
50
   by the logical START_LOCATION.  TO_LINE+L at column C is represented by
59
   by the logical START_LOCATION.  TO_LINE+L at column C is represented by
51
   START_LOCATION+(L*(1<<column_bits))+C, as long as C<(1<<column_bits),
60
   START_LOCATION+(L*(1<<column_bits))+C, as long as C<(1<<column_bits),
52
   and the result_location is less than the next line_map's start_location.
61
   and the result_location is less than the next line_map's start_location.
53
   (The top line is line 1 and the leftmost column is column 1; line/column 0
62
   (The top line is line 1 and the leftmost column is column 1; line/column 0
54
   means "entire file/line" or "unknown line/column" or "not applicable".)
63
   means "entire file/line" or "unknown line/column" or "not applicable".)
55
   INCLUDED_FROM is an index into the set that gives the line mapping
64
*/
56
   at whose end the current one was included.  File(s) at the bottom
65
struct GTY(()) line_map_ordinary
57
   of the include stack have this set to -1.  REASON is the reason for
66
{
58
   creation of this line map, SYSP is one for a system header, two for
59
   a C system header file that therefore needs to be extern "C"
60
   protected in C++, and zero otherwise.  */
61
struct GTY(()) line_map {
62
  const char *to_file;
67
  const char *to_file;
63
  linenum_type to_line;
68
  linenum_type to_line;
64
  source_location start_location;
69
70
  /* An index into the set that gives the line mapping at whose end
71
     the current one was included.  File(s) at the bottom of the
72
     include stack have this set to -1.  */
65
  int included_from;
73
  int included_from;
66
  ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;
74
67
  /* The sysp field isn't really needed now that it's in cpp_buffer.  */
75
  /* SYSP is one for a system header, two for a C system header file
76
     that therefore needs to be extern "C" protected in C++, and zero
77
     otherwise.  This field isn't really needed now that it's in
78
     cpp_buffer.  */
68
  unsigned char sysp;
79
  unsigned char sysp;
69
  /* Number of the low-order source_location bits used for a column number.  */
80
81
  /* Number of the low-order source_location bits used for a column
82
     number.  */
70
  unsigned int column_bits : 8;
83
  unsigned int column_bits : 8;
71
};
84
};
72
85
86
struct GTY(()) cpp_macro;
87
88
/* A macro line map encodes locations coming from a macro expansion.
89
   
90
   Please note that this struct line_map_macro is a field of struct
91
   line_map below, go read the comments of struct line_map below and
92
   then come back here.
93
   
94
   The offset from START_LOCATION is used to index into
95
   MACRO_LOCATIONS; this holds the original location of the token.  */
96
struct GTY(()) line_map_macro
97
{
98
  /* The cpp macro which expansion gave birth to this macro map.  */
99
  struct cpp_macro *macro;
100
101
  /* The number of tokens inside the replacement-list of MACRO.  */
102
  unsigned int n_tokens;
103
104
  /* This array of location is actually an array of pairs of
105
     locations. The elements inside it thus look like:
106
107
           x0,y0, x1,y1, x2,y2, ...., xn,yn.
108
109
     where n == (n_token - 1)/ 2
110
111
     Remember we are at the expansion point of MACRO.  Each xI is the
112
     source location of the Ith token of the replacement-list. Now it
113
     gets confusing. the xI is the source location of the Ith token of
114
     the replacement-list at the macro *definition* point. Not at the
115
     macro replacement point. Okay, let's try to explain this below.
116
117
     Imagine this:
118
119
        #define OPERATION(OP0, OPERATOR, OP1) \
120
                OP0 OPERATOR OP1 <-- #0
121
122
	#define PLUS(A, B) OPERATION (A, +, B)  <--- #1
123
124
	int a = PLUS (1,2); <--- #2
125
     
126
     In #2, there is a macro map for the expansion of PLUS. PLUS is
127
     expanded into the replacement-list made of the tokens:
128
     
129
        OPERATION, (, A, +, B, )
130
131
     and then further expanded into the tokens:
132
133
        1, +, 2.
134
135
     Let's consider the case of token "+" here. That will help us
136
     understand what the xI we were talking about earlier means.
137
138
     The token '+' has two locations, so to speak. One in the context
139
     of the macro *expansion* of PLUS in #2 and one in the context of
140
     the macro *definition* of PLUS in #1. These two locations are
141
     encoded in the the latter context, somehow in the xI we are
142
     talking about.
143
144
     The index of xI is more or less the index of the token inside the
145
     replacement-list at the expansion point. So for '+', it's index
146
     would then be 1 [The index of token '1' would be 0 and the index
147
     of token 2 would be 1]. So if '+' is our current xI, it is
148
     actualy an x1.
149
150
     The value of x1 is the location of the token '+' inside the
151
     replacement-list of PLUS at the definition point of PLUS. It is
152
     its source location in #1.
153
154
     So x0 would have described the token '1', x1 describes the token
155
     '+' and x2 describes the token '2'.
156
157
     Now what's the y1 then? Remember, we said macro_locations is an
158
     array of pairs (xI,yI). We now know what the xI is, now let's
159
     look at the yI.
160
161
     Let's look at the token '+' again. We said it has two locations
162
     somehow. Actually it has 3. Kind of. As '+' is an argument passed
163
     to the macro OPERATION [at the definition point of the macro
164
     PLUS], it would be nice to record the source location of the
165
     *parameter* of OPERATION that is replaced by the argument '+'.
166
     In other words, we want to record the location of the token
167
     "OPERATOR" in the replacement-list of OPERATION, at the
168
     /definition/ point of OPERATION in #0. And that is y1.
169
170
     So when (xI,yI) describes a token that is passed as an argument
171
     to a macro M, the yI is the location of the macro parameter that
172
     the argument replaces, at the definition point of M. If (xI,yI)
173
     does not describe a token that is passed as an argument to a
174
     macro, xI == yI.
175
   */
176
  source_location * GTY((length ("%h.n_tokens"))) macro_locations;
177
178
  /* This is the location of the expansion point of the current macro
179
     map.  That expansion point location is hold by the map that was
180
     current right before the current one. It could have been either
181
     a macro or an ordinary map, depending on if we are in a
182
     nested expansion context not.  */
183
  source_location expansion;
184
};
185
186
/* A line_map encodes a sequence of locations.
187
   There are two kinds of maps. Ordinary maps and macro expansion
188
   maps, a.k.a macro maps.
189
190
   A macro map encodes source locations of tokens that are part of a
191
   macro replacement-list, at a macro expansion point. E.g, in:
192
193
            #define PLUS(A,B) A + B
194
195
   No macro map is going to be created there, because we are not at a
196
   macro expansion point. We are at a macro /definition/ point. So the
197
   locations of the tokens of the macro replacement-list (i.e, A + B)
198
   will be locations in an ordinary map, not a macro map.
199
200
   On the other hand, if we later do:
201
202
        int a = PLUS (1,2);
203
204
   The invocation of PLUS here is a macro expansion. So we are at a
205
   macro expansion point. The preprocessor expands PLUS (1,2) and
206
   replaces it with the tokens of its replacement-list: 1 + 2. A macro
207
   map is going to be created to hold (or rather to map, haha ...) the
208
   locations of the tokens 1, + and 2. The macro map also records the
209
   location of the expansion point of PLUS. That location is mapped in
210
   the map that active right before the location of the invocation of
211
   PLUS.  */
212
struct GTY(()) line_map {
213
  source_location start_location;
214
215
  /* The index of this map into its set.  */
216
  int index;
217
218
  /* The reason for creation of this line map.  */
219
  ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;
220
221
  union {
222
    struct line_map_ordinary GTY((tag ("0"))) ordinary;
223
    struct line_map_macro GTY((tag ("1"))) macro;
224
  } GTY((desc ("%1.reason == LC_ENTER_MACRO"))) d;
225
};
226
73
/* A set of chronological line_map structures.  */
227
/* A set of chronological line_map structures.  */
74
struct GTY(()) line_maps {
228
struct GTY(()) line_maps {
229
  /* This array contains the different line maps.
230
     A line map is created for the following events:
231
       - when a new preprocessing unit start. 
232
       - when a preprocessing unit ends.
233
       - when a macro expansion occurs
234
  */
75
  struct line_map * GTY ((length ("%h.used"))) maps;
235
  struct line_map * GTY ((length ("%h.used"))) maps;
236
237
  /* The allocated size of maps.  */
76
  unsigned int allocated;
238
  unsigned int allocated;
239
240
  /* The number of elements used in maps. This number is smaller
241
     or equal to allocated.  */
77
  unsigned int used;
242
  unsigned int used;
78
243
79
  unsigned int cache;
244
  unsigned int cache;
80
245
81
  /* The most recently listed include stack, if any, starts with
82
     LAST_LISTED as the topmost including file.  -1 indicates nothing
83
     has been listed yet.  */
84
  int last_listed;
85
86
  /* Depth of the include stack, including the current file.  */
246
  /* Depth of the include stack, including the current file.  */
87
  unsigned int depth;
247
  unsigned int depth;
88
248
 Lines 105-118   struct GTY(()) line_maps { Link Here 
105
};
265
};
106
266
107
/* Initialize a line map set.  */
267
/* Initialize a line map set.  */
108
extern void linemap_init (struct line_maps *);
268
void linemap_init (struct line_maps *);
109
269
110
/* Free a line map set.  */
270
/* Free a line map set.  */
111
extern void linemap_free (struct line_maps *);
271
void linemap_free (struct line_maps *);
112
272
113
/* Check for and warn about line_maps entered but not exited.  */
273
/* Check for and warn about line_maps entered but not exited.  */
114
274
115
extern void linemap_check_files_exited (struct line_maps *);
275
void linemap_check_files_exited (struct line_maps *);
116
276
117
/* Return a source_location for the start (i.e. column==0) of
277
/* Return a source_location for the start (i.e. column==0) of
118
   (physical) line TO_LINE in the current source file (as in the
278
   (physical) line TO_LINE in the current source file (as in the
 Lines 120-126   extern void linemap_check_files_exited (struct line_maps *); Link Here 
120
   number we expect to use in this line (but it does not change
280
   number we expect to use in this line (but it does not change
121
   the highest_location).  */
281
   the highest_location).  */
122
282
123
extern source_location linemap_line_start
283
source_location linemap_line_start
124
(struct line_maps *set, linenum_type to_line,  unsigned int max_column_hint);
284
(struct line_maps *set, linenum_type to_line,  unsigned int max_column_hint);
125
285
126
/* Add a mapping of logical source line to physical source file and
286
/* Add a mapping of logical source line to physical source file and
 Lines 134-159   extern source_location linemap_line_start Link Here 
134
294
135
   A call to this function can relocate the previous set of
295
   A call to this function can relocate the previous set of
136
   maps, so any stored line_map pointers should not be used.  */
296
   maps, so any stored line_map pointers should not be used.  */
137
extern const struct line_map *linemap_add
297
const struct line_map *linemap_add
138
  (struct line_maps *, enum lc_reason, unsigned int sysp,
298
  (struct line_maps *, enum lc_reason, unsigned int sysp,
139
   const char *to_file, linenum_type to_line);
299
   const char *to_file, linenum_type to_line);
140
300
301
const struct line_map *linemap_enter_macro (struct line_maps *,
302
						   struct cpp_macro*,
303
						   source_location,
304
						   unsigned int);
305
306
source_location linemap_add_macro_token (const struct line_map *,
307
						unsigned int,
308
						source_location,
309
						source_location);
310
311
void linemap_leave_macro (struct line_maps *, source_location);
312
141
/* Given a logical line, returns the map from which the corresponding
313
/* Given a logical line, returns the map from which the corresponding
142
   (source file, line) pair can be deduced.  */
314
   (source file, line) pair can be deduced.  */
143
extern const struct line_map *linemap_lookup
315
const struct line_map *linemap_lookup
144
  (struct line_maps *, source_location);
316
  (struct line_maps *, source_location);
145
317
318
int linemap_check_ordinary (const struct line_map *);
319
320
bool linemap_macro_expansion_map_p (const struct line_map *);
321
322
source_location linemap_macro_loc_to_exp_point (struct line_maps *,
323
						       source_location,
324
						       const struct line_map **);
325
326
source_location linemap_macro_loc_to_def_point (struct line_maps *,
327
						source_location,
328
						const struct line_map **,
329
						bool);
330
331
source_location linemap_macro_map_loc_to_def_point (const struct line_map*,
332
						    source_location,
333
						    bool);
334
335
source_location linemap_macro_map_loc_to_exp_point (const struct line_map*,
336
						    source_location);
337
338
int linemap_get_source_line (struct line_maps *,
339
			     source_location);
340
341
int linemap_get_source_column (struct line_maps *,
342
			       source_location);
343
344
const char* linemap_map_get_macro_name (const struct line_map*);
345
346
const char* linemap_get_file_path (struct line_maps *,
347
				   source_location);
348
349
bool linemap_location_in_system_header_p (struct line_maps *,
350
					  source_location);
351
352
bool linemap_location_originated_from_system_header_p (struct line_maps *,
353
						       source_location);
354
355
bool linemap_location_from_macro_expansion_p (struct line_maps *,
356
					      source_location);
357
146
/* source_location values from 0 to RESERVED_LOCATION_COUNT-1 will
358
/* source_location values from 0 to RESERVED_LOCATION_COUNT-1 will
147
   be reserved for libcpp user as special values, no token from libcpp
359
   be reserved for libcpp user as special values, no token from libcpp
148
   will contain any of those locations.  */
360
   will contain any of those locations.  */
149
#define RESERVED_LOCATION_COUNT	2
361
#define RESERVED_LOCATION_COUNT	2
150
362
151
/* Converts a map and a source_location to source line.  */
363
/* Converts a map and a source_location to source line.  */
152
#define SOURCE_LINE(MAP, LOC) \
364
#define SOURCE_LINE(MAP, LOC)						\
153
  ((((LOC) - (MAP)->start_location) >> (MAP)->column_bits) + (MAP)->to_line)
365
  (linemap_check_ordinary (MAP),					\
366
   ((((LOC) - (MAP)->start_location)					\
367
     >> (MAP)->d.ordinary.column_bits) + (MAP)->d.ordinary.to_line))
154
368
155
#define SOURCE_COLUMN(MAP, LOC) \
369
#define SOURCE_COLUMN(MAP, LOC)				\
156
  (((LOC) - (MAP)->start_location) & ((1 << (MAP)->column_bits) - 1))
370
  (linemap_check_ordinary (MAP),			\
371
  (((LOC) - (MAP)->start_location)			\
372
   & ((1 << (MAP)->d.ordinary.column_bits) - 1)))
157
373
158
/* Returns the last source line within a map.  This is the (last) line
374
/* Returns the last source line within a map.  This is the (last) line
159
   of the #include, or other directive, that caused a map change.  */
375
   of the #include, or other directive, that caused a map change.  */
 Lines 161-176   extern const struct line_map *linemap_lookup Link Here 
161
  SOURCE_LINE (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
377
  SOURCE_LINE (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
162
#define LAST_SOURCE_COLUMN(MAP) \
378
#define LAST_SOURCE_COLUMN(MAP) \
163
  SOURCE_COLUMN (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
379
  SOURCE_COLUMN (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
164
#define LAST_SOURCE_LINE_LOCATION(MAP) \
380
#define LAST_SOURCE_LINE_LOCATION(MAP)				\
165
  ((((MAP)[1].start_location - 1 - (MAP)->start_location) \
381
  (linemap_check_ordinary (MAP),				\
166
    & ~((1 << (MAP)->column_bits) - 1))			  \
382
   ((((MAP)[1].start_location - 1 - (MAP)->start_location)	\
167
   + (MAP)->start_location)
383
     & ~((1 << (MAP)->d.ordinary.column_bits) - 1))		\
384
    + (MAP)->start_location))
168
385
169
/* Returns the map a given map was included from.  */
386
/* Returns the map a given map was included from.  */
170
#define INCLUDED_FROM(SET, MAP) (&(SET)->maps[(MAP)->included_from])
387
#define INCLUDED_FROM(SET, MAP)				\
388
  (linemap_check_ordinary (MAP),			\
389
   (&(SET)->maps[(MAP)->d.ordinary.included_from]))
171
390
172
/* Nonzero if the map is at the bottom of the include stack.  */
391
/* Nonzero if the map is at the bottom of the include stack.  */
173
#define MAIN_FILE_P(MAP) ((MAP)->included_from < 0)
392
#define MAIN_FILE_P(MAP)			\
393
  (linemap_check_ordinary (MAP),		\
394
   ((MAP)->d.ordinary.included_from < 0))
174
395
175
/* Set LOC to a source position that is the same line as the most recent
396
/* Set LOC to a source position that is the same line as the most recent
176
   linemap_line_start, but with the specified TO_COLUMN column number.  */
397
   linemap_line_start, but with the specified TO_COLUMN column number.  */
 Lines 189-195   extern const struct line_map *linemap_lookup Link Here 
189
  }} while (0)
410
  }} while (0)
190
    
411
    
191
412
192
extern source_location
413
source_location
193
linemap_position_for_column (struct line_maps *set, unsigned int to_column);
414
linemap_position_for_column (struct line_maps *set, unsigned int to_column);
194
415
416
417
#define LINEMAP_FILE(MAP)					\
418
  (linemap_check_ordinary (MAP), (MAP)->d.ordinary.to_file)
419
420
#define LINEMAP_LINE(MAP)					\
421
  (linemap_check_ordinary (MAP), (MAP)->d.ordinary.to_line)
422
423
#define LINEMAP_SYSP(MAP)					\
424
  (linemap_check_ordinary (MAP), (MAP)->d.ordinary.sysp)
425
426
typedef struct GTY (())
427
{
428
  /* The name of the source file involved.  */
429
  const char *file;
430
431
  /* The line-location in the source file.  */
432
  int line;
433
434
  int column;
435
436
  /* In a system header?. */
437
  bool sysp;
438
} expanded_location;
439
440
expanded_location linemap_expand_location (struct line_maps *,
441
						  source_location);
442
expanded_location linemap_expand_location_full (struct line_maps *,
443
						       source_location,
444
						       bool,
445
						       const struct line_map**);
446
void linemap_dump_location (struct line_maps *, source_location, FILE *);
447
195
#endif /* !LIBCPP_LINE_MAP_H  */
448
#endif /* !LIBCPP_LINE_MAP_H  */
(-)a/libcpp/init.c (-1 / +1 lines)
 Lines 574-580   cpp_read_main_file (cpp_reader *pfile, const char *fname) Link Here 
574
  if (CPP_OPTION (pfile, preprocessed))
574
  if (CPP_OPTION (pfile, preprocessed))
575
    {
575
    {
576
      read_original_filename (pfile);
576
      read_original_filename (pfile);
577
      fname = pfile->line_table->maps[pfile->line_table->used-1].to_file;
577
      fname = pfile->line_table->maps[pfile->line_table->used-1].d.ordinary.to_file;
578
    }
578
    }
579
  return fname;
579
  return fname;
580
}
580
}
(-)a/libcpp/line-map.c (-58 / +637 lines)
 Lines 23-28   along with this program; see the file COPYING3. If not see Link Here 
23
#include "config.h"
23
#include "config.h"
24
#include "system.h"
24
#include "system.h"
25
#include "line-map.h"
25
#include "line-map.h"
26
#include "cpp-id-data.h"
27
28
#define linemap_assert(EXPR)			\
29
  do {						\
30
    if (! (EXPR))				\
31
      abort ();					\
32
  } while (0)
26
33
27
static void trace_include (const struct line_maps *, const struct line_map *);
34
static void trace_include (const struct line_maps *, const struct line_map *);
28
35
 Lines 34-40   linemap_init (struct line_maps *set) Link Here 
34
  set->maps = NULL;
41
  set->maps = NULL;
35
  set->allocated = 0;
42
  set->allocated = 0;
36
  set->used = 0;
43
  set->used = 0;
37
  set->last_listed = -1;
38
  set->trace_includes = false;
44
  set->trace_includes = false;
39
  set->depth = 0;
45
  set->depth = 0;
40
  set->cache = 0;
46
  set->cache = 0;
 Lines 55-61   linemap_check_files_exited (struct line_maps *set) Link Here 
55
  for (map = &set->maps[set->used - 1]; ! MAIN_FILE_P (map);
61
  for (map = &set->maps[set->used - 1]; ! MAIN_FILE_P (map);
56
       map = INCLUDED_FROM (set, map))
62
       map = INCLUDED_FROM (set, map))
57
    fprintf (stderr, "line-map.c: file \"%s\" entered but not left\n",
63
    fprintf (stderr, "line-map.c: file \"%s\" entered but not left\n",
58
	     map->to_file);
64
	     map->d.ordinary.to_file);
59
}
65
}
60
 
66
 
61
/* Free a line map set.  */
67
/* Free a line map set.  */
 Lines 71-98   linemap_free (struct line_maps *set) Link Here 
71
    }
77
    }
72
}
78
}
73
79
74
/* Add a mapping of logical source line to physical source file and
80
/* Create a new line map in the line map set SET, and return it.  */
75
   line number.
76
77
   The text pointed to by TO_FILE must have a lifetime
78
   at least as long as the final call to lookup_line ().  An empty
79
   TO_FILE means standard input.  If reason is LC_LEAVE, and
80
   TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
81
   natural values considering the file we are returning to.
82
83
   FROM_LINE should be monotonic increasing across calls to this
84
   function.  A call to this function can relocate the previous set of
85
   maps, so any stored line_map pointers should not be used.  */
86
81
87
const struct line_map *
82
static struct line_map *
88
linemap_add (struct line_maps *set, enum lc_reason reason,
83
new_linemap (struct line_maps *set)
89
	     unsigned int sysp, const char *to_file, linenum_type to_line)
90
{
84
{
91
  struct line_map *map;
85
  struct line_map *result;
92
  source_location start_location = set->highest_location + 1;
93
94
  if (set->used && start_location < set->maps[set->used - 1].start_location)
95
    abort ();
96
86
97
  if (set->used == set->allocated)
87
  if (set->used == set->allocated)
98
    {
88
    {
 Lines 107-113   linemap_add (struct line_maps *set, enum lc_reason reason, Link Here 
107
					 * sizeof (struct line_map)));
97
					 * sizeof (struct line_map)));
108
    }
98
    }
109
99
110
  map = &set->maps[set->used];
100
  result = &set->maps[set->used];
101
  result->index = set->used;
102
  set->used++;
103
  return result;
104
}
105
106
/* Create a line map -- a mapping between a logical source location
107
   and physical source file and line number.
108
109
   SET is the set of line maps the new map will belong to.  The text
110
   pointed to by TO_FILE must have a lifetime at least as long as the
111
   lifetime of SET.  An empty TO_FILE means standard input.  If reason
112
   is LC_LEAVE, and TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP
113
   are given their natural values considering the file we are
114
   returning to.
115
116
   A call to this function can relocate the previous set of
117
   maps, so any stored line_map pointers should not be used.
118
119
   This function is a subroutine of linemap_add and
120
   linemap_enter_macro.  */
121
122
static const struct line_map *
123
do_add (struct line_maps *set, enum lc_reason reason,
124
	unsigned int sysp, const char *to_file, linenum_type to_line,
125
	const struct line_map *previous)
126
{
127
  struct line_map *map = NULL;
128
  /* When we are just leaving an "included" file, and jump to the next
129
     location inside the "includer" right after the #include
130
     "included", this variable points the map in use right before the
131
     #include "included", inside the same "includer" file.
132
  */
133
  struct line_map *prev_map_same_file = NULL;
134
  source_location start_location = set->highest_location + 1;
135
  int previous_index = -1;
136
137
  linemap_assert (!(set->used
138
		    && start_location < set->maps[set->used - 1].start_location));
139
140
  /* If we are leaving the main file, return a NULL map.  */
141
  if (reason == LC_LEAVE
142
      && MAIN_FILE_P (&set->maps[set->used - 1])
143
      && to_file == NULL)
144
    return NULL;
145
146
  /*
147
     *Kludge* ahead. new_linemap uses ggc_realloc to enlarge
148
     line_maps::maps. ggc_realloc frees the previous storage of
149
     line_maps::maps. So struct line_map* pointers that where pointing
150
     into line_maps::maps prior to new_linemap can become dangling
151
     after new_linemap. previous is such a pointer that can become
152
     dangling after new_linemap. Let's make sure we make it point into
153
     the newly allocated line_maps::maps.
154
  */
155
  if (previous)
156
    previous_index = previous->index;
157
  map = new_linemap (set);
158
  if (previous_index > -1)
159
    previous = &set->maps[previous_index];
111
160
112
  if (to_file && *to_file == '\0' && reason != LC_RENAME_VERBATIM)
161
  if (to_file && *to_file == '\0' && reason != LC_RENAME_VERBATIM)
113
    to_file = "<stdin>";
162
    to_file = "<stdin>";
 Lines 121-144   linemap_add (struct line_maps *set, enum lc_reason reason, Link Here 
121
    reason = LC_ENTER;
170
    reason = LC_ENTER;
122
  else if (reason == LC_LEAVE)
171
  else if (reason == LC_LEAVE)
123
    {
172
    {
124
      struct line_map *from;
125
      bool error;
173
      bool error;
126
174
127
      if (MAIN_FILE_P (map - 1))
175
      if (MAIN_FILE_P (map - 1))
128
	{
176
	{
129
	  if (to_file == NULL)
177
	  /* So this _should_ means we are leaving the main file --
130
	    {
178
	     effectively ending the compilation unit. But to_file not
131
	      set->depth--;
179
	     being NULL means the caller thinks we are leaving to
132
	      return NULL;
180
	     another file. This is an erratic behaviour but we'll try
133
	    }
181
	     to recover from it. Let's pretend we are not leaving the
182
	     main file.  */
134
	  error = true;
183
	  error = true;
135
          reason = LC_RENAME;
184
	  reason = LC_RENAME;
136
          from = map - 1;
185
	  prev_map_same_file = map - 1;
137
	}
186
	}
138
      else
187
      else
139
	{
188
	{
140
	  from = INCLUDED_FROM (set, map - 1);
189
	  /* (MAP - 1) points to the map we are leaving. The
141
	  error = to_file && strcmp (from->to_file, to_file);
190
	     map from which (MAP - 1) got included should be the map
191
	     that comes right before MAP in the same file.  */
192
	  prev_map_same_file = INCLUDED_FROM (set, map - 1);
193
	  linemap_check_ordinary (prev_map_same_file);
194
	  error = to_file && strcmp (prev_map_same_file->d.ordinary.to_file,
195
				     to_file);
142
	}
196
	}
143
197
144
      /* Depending upon whether we are handling preprocessed input or
198
      /* Depending upon whether we are handling preprocessed input or
 Lines 150-190   linemap_add (struct line_maps *set, enum lc_reason reason, Link Here 
150
      /* A TO_FILE of NULL is special - we use the natural values.  */
204
      /* A TO_FILE of NULL is special - we use the natural values.  */
151
      if (error || to_file == NULL)
205
      if (error || to_file == NULL)
152
	{
206
	{
153
	  to_file = from->to_file;
207
	  linemap_check_ordinary (prev_map_same_file);
154
	  to_line = SOURCE_LINE (from, from[1].start_location);
208
	  to_file = prev_map_same_file->d.ordinary.to_file;
155
	  sysp = from->sysp;
209
	  to_line = SOURCE_LINE (prev_map_same_file,
210
				 prev_map_same_file[1].start_location);
211
	  sysp = prev_map_same_file->d.ordinary.sysp;
156
	}
212
	}
157
    }
213
    }
158
214
215
  linemap_assert (reason != LC_ENTER_MACRO);
159
  map->reason = reason;
216
  map->reason = reason;
160
  map->sysp = sysp;
217
  map->d.ordinary.sysp = sysp;
161
  map->start_location = start_location;
218
  map->start_location = start_location;
162
  map->to_file = to_file;
219
  map->d.ordinary.to_file = to_file;
163
  map->to_line = to_line;
220
  map->d.ordinary.to_line = to_line;
164
  set->cache = set->used++;
221
  set->cache = set->used - 1;
165
  map->column_bits = 0;
222
  map->d.ordinary.column_bits = 0;
166
  set->highest_location = start_location;
223
  set->highest_location = start_location;
167
  set->highest_line = start_location;
224
  set->highest_line = start_location;
168
  set->max_column_hint = 0;
225
  set->max_column_hint = 0;
169
226
170
  if (reason == LC_ENTER)
227
  if (reason == LC_ENTER)
171
    {
228
    {
172
      map->included_from = set->depth == 0 ? -1 : (int) (set->used - 2);
229
      map->d.ordinary.included_from
230
	= set->depth == 0 ? -1 : (int) (set->used - 2);
173
      set->depth++;
231
      set->depth++;
174
      if (set->trace_includes)
232
      if (set->trace_includes)
175
	trace_include (set, map);
233
	trace_include (set, map);
176
    }
234
    }
177
  else if (reason == LC_RENAME)
235
  else if (reason == LC_RENAME)
178
    map->included_from = map[-1].included_from;
236
    {
237
      if (previous == NULL)
238
	previous = &map[-1];
239
      linemap_check_ordinary (previous);
240
      map->d.ordinary.included_from = previous->d.ordinary.included_from;
241
    }
179
  else if (reason == LC_LEAVE)
242
  else if (reason == LC_LEAVE)
180
    {
243
    {
244
      linemap_assert (prev_map_same_file != NULL);
181
      set->depth--;
245
      set->depth--;
182
      map->included_from = INCLUDED_FROM (set, map - 1)->included_from;
246
      map->d.ordinary.included_from =
247
		prev_map_same_file->d.ordinary.included_from;
183
    }
248
    }
184
249
185
  return map;
250
  return map;
186
}
251
}
187
252
253
/* Add a mapping of logical source line to physical source file and
254
   line number. This function creates an "ordinary map", which is a
255
   map that records locations of tokens that are not part of macro
256
   replacement-lists present at a macro expansion point.
257
258
   The text pointed to by TO_FILE must have a lifetime
259
   at least as long as the lifetime of SET.  An empty
260
   TO_FILE means standard input.  If reason is LC_LEAVE, and
261
   TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
262
   natural values considering the file we are returning to.
263
264
   A call to this function can relocate the previous set of
265
   maps, so any stored line_map pointers should not be used.  */
266
267
const struct line_map *
268
linemap_add (struct line_maps *set, enum lc_reason reason,
269
	     unsigned int sysp, const char *to_file, linenum_type to_line)
270
{
271
  return do_add (set, reason, sysp, to_file, to_line, NULL);
272
}
273
274
/*
275
   Create a macro map. A macro map encodes source locations of tokens
276
   that are part of a macro replacement-list, at a macro expansion
277
   point. See the extensive comments of struct line_map and struct
278
   line_map_macro, in line-map.h.
279
280
   This map shall be created when the macro is expanded. The map
281
   encodes the source location of the expansion point of the macro as
282
   well as the "original" source location of each token that is part
283
   of the macro replacement-list. If a macro is defined but never
284
   expanded, it has no macro map.  SET is the set of maps the macro
285
   map should be part of.  MACRO is the macro which the new macro map
286
   should encode source locations for.  EXPANSION is the location of
287
   the expansion point of MACRO. For function-like macros invocations,
288
   it's best to make it point to the closing parenthesis of the macro,
289
   rather than the the location of the first character of the macro.
290
   NUM_TOKENS is the number of tokens that are part of the
291
   replacement-list of MACRO.  */
292
293
const struct line_map *
294
linemap_enter_macro (struct line_maps *set, struct cpp_macro *macro,
295
		     source_location expansion, unsigned int num_tokens)
296
{
297
  struct line_map *map;
298
  source_location start_location = set->highest_location + 1;
299
  line_map_realloc reallocator
300
    = set->reallocator ? set->reallocator : xrealloc;
301
302
  map = new_linemap (set);
303
304
  map->start_location = start_location;
305
  map->reason = LC_ENTER_MACRO;
306
  map->d.macro.macro = macro;
307
  map->d.macro.n_tokens = num_tokens;
308
  map->d.macro.macro_locations
309
    = (source_location*) reallocator (NULL,
310
				      2 * num_tokens
311
				      * sizeof (source_location));
312
  map->d.macro.expansion = expansion;
313
  memset (map->d.macro.macro_locations, 0,
314
	  num_tokens * sizeof (source_location));
315
316
  set->cache = set->used - 1;
317
  set->max_column_hint = 0;
318
  set->highest_location = start_location + num_tokens;
319
  set->highest_line = start_location + num_tokens;
320
321
  return map;
322
}
323
324
/* Create and return a source location for a token that is part of a
325
   macro replacement-list at a macro expansion point.
326
327
   A call to this function must come after a call to
328
   linemap_enter_macro.
329
330
   MAP is the map into which the source location is created.  TOKEN_NO
331
   is the index of the token in the macro replacement-list, starting
332
   at number 0.
333
334
   ORIG_LOC is the orginal location of the token at the definition
335
   point of the macro. If you read the extensive comments of struct
336
   line_map_macro in line-map.h, this is the xI.
337
338
   If the token is part of a macro argument, ORIG_PARM_REPLACEMENT_LOC
339
   is the location of the point at wich the token (the argument)
340
   replaces the macro parameter in the context of the relevant macro
341
   definition. If you read the comments of struct line_map_macro in
342
   line-map.h, this is the yI.  */
343
344
source_location
345
linemap_add_macro_token (const struct line_map *map,
346
			 unsigned int token_no,
347
			 source_location orig_loc,
348
			 source_location orig_parm_replacement_loc)
349
{
350
  linemap_assert (linemap_macro_expansion_map_p (map));
351
  map->d.macro.macro_locations[2 * token_no] = orig_loc;
352
  map->d.macro.macro_locations[2 * token_no + 1] = orig_parm_replacement_loc;
353
  return map->start_location + token_no;
354
}
355
356
/* Create an ordinary map coming right after the macro map holding the
357
   locations of the tokens of the macro replacement-list at a macro
358
   expansion point. The current map must be a macro map.
359
   
360
   This function must be called right after the series of calls to
361
   linemap_add_macro_token. It thus ends the creation of locations for
362
   macro replacement-list tokens at a macro expansion point.
363
364
   SET is the set of line maps to consider.
365
   EXPANSION_POINT_LOC is the location of the expansion point.  */
366
367
void
368
linemap_leave_macro (struct line_maps *set,
369
		     source_location expansion_point_loc)
370
{
371
  /* The ordinary (non-macro) map that comes right before the current
372
     macro map.  */
373
  const struct line_map *previous;
374
  /* Then map that encodes the expansion point of the current macro.  */
375
  const struct line_map *expansion_point;
376
377
  /* The current macro must be a macro map.  */
378
  linemap_assert (linemap_macro_expansion_map_p (&set->maps[set->used - 1]));
379
380
  previous = &set->maps[set->used - 2];
381
  /* The previous map cannot be a macro map.  */
382
  linemap_assert (!linemap_macro_expansion_map_p (previous));
383
384
  expansion_point_loc =
385
    linemap_macro_loc_to_exp_point (set, expansion_point_loc,
386
				    &expansion_point);
387
  linemap_assert (!linemap_macro_expansion_map_p (expansion_point));
388
389
  do_add (set, LC_RENAME, previous->d.ordinary.sysp,
390
	  previous->d.ordinary.to_file,
391
	  SOURCE_LINE (expansion_point, expansion_point_loc),
392
	  previous);
393
}
394
188
source_location
395
source_location
189
linemap_line_start (struct line_maps *set, linenum_type to_line,
396
linemap_line_start (struct line_maps *set, linenum_type to_line,
190
		    unsigned int max_column_hint)
397
		    unsigned int max_column_hint)
 Lines 195-204   linemap_line_start (struct line_maps *set, linenum_type to_line, Link Here 
195
  linenum_type last_line = SOURCE_LINE (map, set->highest_line);
402
  linenum_type last_line = SOURCE_LINE (map, set->highest_line);
196
  int line_delta = to_line - last_line;
403
  int line_delta = to_line - last_line;
197
  bool add_map = false;
404
  bool add_map = false;
405
406
  linemap_check_ordinary (map);
407
198
  if (line_delta < 0
408
  if (line_delta < 0
199
      || (line_delta > 10 && line_delta * map->column_bits > 1000)
409
      || (line_delta > 10 && line_delta * map->d.ordinary.column_bits > 1000)
200
      || (max_column_hint >= (1U << map->column_bits))
410
      || (max_column_hint >= (1U << map->d.ordinary.column_bits))
201
      || (max_column_hint <= 80 && map->column_bits >= 10))
411
      || (max_column_hint <= 80 && map->d.ordinary.column_bits >= 10))
202
    {
412
    {
203
      add_map = true;
413
      add_map = true;
204
    }
414
    }
 Lines 226-241   linemap_line_start (struct line_maps *set, linenum_type to_line, Link Here 
226
      /* Allocate the new line_map.  However, if the current map only has a
436
      /* Allocate the new line_map.  However, if the current map only has a
227
	 single line we can sometimes just increase its column_bits instead. */
437
	 single line we can sometimes just increase its column_bits instead. */
228
      if (line_delta < 0
438
      if (line_delta < 0
229
	  || last_line != map->to_line
439
	  || last_line != map->d.ordinary.to_line
230
	  || SOURCE_COLUMN (map, highest) >= (1U << column_bits))
440
	  || SOURCE_COLUMN (map, highest) >= (1U << column_bits))
231
	map = (struct line_map *) linemap_add (set, LC_RENAME, map->sysp,
441
	map = (struct line_map *) linemap_add (set, LC_RENAME,
232
					       map->to_file, to_line);
442
					       map->d.ordinary.sysp,
233
      map->column_bits = column_bits;
443
					       map->d.ordinary.to_file,
234
      r = map->start_location + ((to_line - map->to_line) << column_bits);
444
					       to_line);
445
      map->d.ordinary.column_bits = column_bits;
446
      r = map->start_location + ((to_line - map->d.ordinary.to_line)
447
				 << column_bits);
235
    }
448
    }
236
  else
449
  else
237
    r = highest - SOURCE_COLUMN (map, highest)
450
    r = highest - SOURCE_COLUMN (map, highest)
238
      + (line_delta << map->column_bits);
451
      + (line_delta << map->d.ordinary.column_bits);
239
  set->highest_line = r;
452
  set->highest_line = r;
240
  if (r > set->highest_location)
453
  if (r > set->highest_location)
241
    set->highest_location = r;
454
    set->highest_location = r;
 Lines 247-252   source_location Link Here 
247
linemap_position_for_column (struct line_maps *set, unsigned int to_column)
460
linemap_position_for_column (struct line_maps *set, unsigned int to_column)
248
{
461
{
249
  source_location r = set->highest_line;
462
  source_location r = set->highest_line;
463
464
  linemap_assert (!linemap_macro_expansion_map_p (&set->maps[set->used - 1]));
465
250
  if (to_column >= set->max_column_hint)
466
  if (to_column >= set->max_column_hint)
251
    {
467
    {
252
      if (r >= 0xC000000 || to_column > 100000)
468
      if (r >= 0xC000000 || to_column > 100000)
 Lines 266-275   linemap_position_for_column (struct line_maps *set, unsigned int to_column) Link Here 
266
  return r;
482
  return r;
267
}
483
}
268
484
269
/* Given a logical line, returns the map from which the corresponding
485
/* Given a logical source location, returns the map which the
270
   (source file, line) pair can be deduced.  Since the set is built
486
   corresponding (source file, line, column) triplet can be deduced
271
   chronologically, the logical lines are monotonic increasing, and so
487
   from. Since the set is built chronologically, the logical lines
272
   the list is sorted and we can use a binary search.  */
488
   are monotonic increasing, and so the list is sorted and we can use
489
   a binary search. If no line map have been allocated yet, this
490
   function returns NULL.  */
273
491
274
const struct line_map *
492
const struct line_map *
275
linemap_lookup (struct line_maps *set, source_location line)
493
linemap_lookup (struct line_maps *set, source_location line)
 Lines 277-282   linemap_lookup (struct line_maps *set, source_location line) Link Here 
277
  unsigned int md, mn, mx;
495
  unsigned int md, mn, mx;
278
  const struct line_map *cached;
496
  const struct line_map *cached;
279
497
498
  linemap_assert (set != NULL);
499
  if (set->maps == NULL)
500
    return NULL;
501
280
  mn = set->cache;
502
  mn = set->cache;
281
  mx = set->used;
503
  mx = set->used;
282
  
504
  
 Lines 306-311   linemap_lookup (struct line_maps *set, source_location line) Link Here 
306
  return &set->maps[mn];
528
  return &set->maps[mn];
307
}
529
}
308
530
531
/* Return TRUE if MAP encodes locations coming from a macro
532
   replacement-list at macro expansion point.  */
533
534
bool
535
linemap_macro_expansion_map_p (const struct line_map *map)
536
{
537
  if (!map)
538
    return false;
539
  return (map->reason == LC_ENTER_MACRO);
540
}
541
542
/* Assert that MAP encodes locations of tokens that are not part of the
543
   replacement-list of a macro expansion.  */
544
545
int
546
linemap_check_ordinary (const struct line_map *map)
547
{
548
  linemap_assert (!linemap_macro_expansion_map_p (map));
549
  /* Return any old value.  */
550
  return 0;
551
}
552
553
/* If LOCATION is the locus of a token in a replacement-list of a
554
   macro expansion return the location of the macro expansion point.
555
556
   Read the comments of struct line_map and struct line_map_macro in
557
   line-map.h to understand what a macro expansion point is.  */
558
559
source_location
560
linemap_macro_map_loc_to_exp_point (const struct line_map *map,
561
				    source_location location)
562
{
563
  linemap_assert (linemap_macro_expansion_map_p (map)
564
		  && location >= map->start_location);
565
566
  location = location - map->start_location;
567
  linemap_assert (location < map->d.macro.n_tokens);
568
  return map->d.macro.expansion;
569
}
570
571
/* If LOCATION is the locus of a token in a replacement-list of a
572
   macro expansion return the location of said token in the
573
   definition of the macro.
574
575
   Read the comments of struct line_map and struct line_map_macro
576
   in line-map.h to understand what a macro expansion point is.
577
578
   If RETURN_MACRO_PARM_USAGE_POINT_P is TRUE and if LOCATION is the
579
   locus of a token that is an argument of a macro M, this function
580
   returns the locus of the parameter replaced by the argument, in the
581
   definition of M. This is the yI in the comments of struct
582
   line_map_macro in line-map.h.
583
584
   Note that if the token is a builtin the function returns the
585
   location of the expansion point of the macro.  */
586
587
source_location
588
linemap_macro_map_loc_to_def_point (const struct line_map *map,
589
				    source_location location,
590
				    bool return_macro_parm_usage_point_p)
591
{
592
  linemap_assert (linemap_macro_expansion_map_p (map)
593
		  && location >= map->start_location);
594
595
  location = location - map->start_location;
596
  linemap_assert (location < map->d.macro.n_tokens);
597
598
  if (return_macro_parm_usage_point_p)
599
    location = map->d.macro.macro_locations[2 * location + 1];
600
  else
601
    location = map->d.macro.macro_locations[2 * location];
602
603
  if (location >= RESERVED_LOCATION_COUNT)
604
    return location;
605
  else
606
    /* If LOCATION is reserved for the user of libcpp, it means,
607
     e.g. for gcc that it's the location of a built-in token. In that
608
     case, let's say that the final location is the macro expansion
609
     point because otherwise, the built-in location would not make
610
     any sense and would violate the invariant that says that every
611
     single location must be >= to the MAP->start_location of its
612
     map.  */
613
    return map->d.macro.expansion;
614
}
615
616
617
/* If LOCATION is the source location of a token that belongs to a
618
   macro replacement-list -- at a macro expansion point-- then
619
   return the location of the topmost expansion point of the macro.
620
   We say topmost because if we are in the context of a nested macro
621
   expansion, the function returns the source location of the first
622
   macro expansion that triggered the nested expansions.
623
624
   Otherwise, return LOCATION.  SET is the set of maps location come
625
   from.  ORIGINAL_MAP is an output parm. If non NULL, the function
626
   sets *ORIGINAL_MAP to the ordinary (non-macro) map the returned
627
   location comes from.  */
628
629
source_location
630
linemap_macro_loc_to_exp_point (struct line_maps *set,
631
				source_location location,
632
				const struct line_map **original_map)
633
{
634
  struct line_map *map;
635
636
  linemap_assert (set && location >= RESERVED_LOCATION_COUNT);
637
638
  while (true)
639
    {
640
      map = (struct line_map*) linemap_lookup (set, location);
641
      if (!linemap_macro_expansion_map_p (map))
642
	break;
643
      location = linemap_macro_map_loc_to_exp_point (map, location);
644
    }
645
646
  if (original_map)
647
    *original_map = map;
648
  return location;
649
}
650
651
/* If LOCATION is the source location of a token that belongs to a
652
   macro replacement-list -- as part of a macro expansion -- then
653
   return the location of the token at the definition point of the
654
   macro. Otherwise, return LOCATION.  SET is the set of maps location
655
   come from.  ORIGINAL_MAP is an output parm. If non NULL, the
656
   function sets *ORIGINAL_MAP to the ordinary (non-macro) map
657
   the returned location comes from.  */
658
659
source_location
660
linemap_macro_loc_to_def_point (struct line_maps *set,
661
				source_location location,
662
				const struct line_map **original_map,
663
				bool return_macro_parm_usage_point_p)
664
{
665
  struct line_map *map;
666
667
  linemap_assert (set && location >= RESERVED_LOCATION_COUNT);
668
669
  while (true)
670
    {
671
      map = (struct line_map*) linemap_lookup (set, location);
672
      if (!linemap_macro_expansion_map_p (map))
673
	break;
674
      location = linemap_macro_map_loc_to_def_point (map, location,
675
						     return_macro_parm_usage_point_p);
676
    }
677
678
  if (original_map)
679
    *original_map = map;
680
  return location;
681
}
682
683
/* Return the source line number corresponding to source location
684
   LOCATION.  SET is the line map set LOCATION comes from.  If
685
   LOCATION is the source location of token that is part of the
686
   replacement-list of a macro expansion return the line number of the
687
   macro expansion point.  */
688
689
int
690
linemap_get_source_line (struct line_maps *set,
691
			 source_location location)
692
{
693
  const struct line_map *map = NULL;
694
695
  if (location < RESERVED_LOCATION_COUNT)
696
    return 0;
697
698
  location =
699
    linemap_macro_loc_to_exp_point (set, location, &map);
700
  linemap_check_ordinary (map);
701
702
  return ((location - map->start_location)
703
	    >> map->d.ordinary.column_bits)
704
	 + map->d.ordinary.to_line;
705
}
706
707
/* Return the column number corresponding to location LOCATION.
708
709
   If LOCATION is the source location of token that is part of the
710
   replacement-list of a macro expansion return the column number of
711
   the macro expansion point.
712
713
   SET is the line map set LOCATION comes from.  */
714
715
int
716
linemap_get_source_column (struct line_maps *set,
717
			   source_location location)
718
{
719
  const struct line_map *map = NULL;
720
721
  if (location < RESERVED_LOCATION_COUNT)
722
    return 0;
723
724
  location =
725
    linemap_macro_loc_to_exp_point (set, location, &map);
726
  linemap_check_ordinary (map);
727
728
  return (location - map->start_location)
729
	  & ((1 << map->d.ordinary.column_bits) - 1);
730
}
731
732
/* Return the path of the file corresponding to source code location
733
   LOCATION.
734
735
   If LOCATION is the source location of token that is part of the
736
   replacement-list of a macro expansion return the file path of the
737
   macro expansion point.
738
739
   SET is the line map set LOCATION comes from.  */
740
741
const char*
742
linemap_get_file_path (struct line_maps *set,
743
		       source_location location)
744
{
745
  const struct line_map *map = NULL;
746
747
  if (location < RESERVED_LOCATION_COUNT)
748
    return NULL;
749
750
  location =
751
    linemap_macro_loc_to_exp_point (set, location, &map);
752
  linemap_check_ordinary (map);
753
  return LINEMAP_FILE (map);
754
}
755
756
/* Return the name of the macro associated to MACRO_MAP.  */
757
758
const char*
759
linemap_map_get_macro_name (const struct line_map* macro_map)
760
{
761
  linemap_assert (macro_map && linemap_macro_expansion_map_p (macro_map));
762
  return (const char*) NODE_NAME ((macro_map)->d.macro.macro->name);
763
}
764
765
/* Return TRUE if LOCATION is the locus of a token is located in a system
766
   header, FALSE otherwise.
767
768
   Note that this function returns FALSE if LOCATION belongs to a
769
   token that is part of a macro replacement-list defined in a system
770
   header, but expanded in a non-system file.  */
771
772
bool
773
linemap_location_in_system_header_p (struct line_maps *set,
774
				     source_location location)
775
{
776
  const struct line_map *map = NULL;
777
778
  if (location < RESERVED_LOCATION_COUNT)
779
    return false;
780
781
  location =
782
    linemap_macro_loc_to_exp_point (set, location, &map);
783
  linemap_check_ordinary (map);
784
  return LINEMAP_SYSP (map);
785
}
786
787
/* Return TRUE if LOCATION is the locus of a token that comes from a
788
   system header, FALSE otherwise.
789
790
   Note that this function returns TRUE if LOCATION belongs to a
791
   token that is part of a macro replacement-list defined in a system
792
   header, but expanded in a non-system file.  */
793
794
bool
795
linemap_location_originated_from_system_header_p (struct line_maps *set,
796
						  source_location location)
797
{
798
  const struct line_map *map = NULL;
799
800
  if (location < RESERVED_LOCATION_COUNT)
801
    return false;
802
803
  location =
804
    linemap_macro_loc_to_def_point (set, location, &map, false);
805
  linemap_check_ordinary (map);
806
  return LINEMAP_SYSP (map);
807
}
808
809
/* Return TRUE if LOCATION is a source code location of a token
810
   coming from a macro replacement-list at a macro expansion point,
811
   FALSE otherwise.  */
812
813
bool
814
linemap_location_from_macro_expansion_p (struct line_maps *set,
815
					 source_location location)
816
{
817
  const struct line_map *map;
818
819
  if (location < RESERVED_LOCATION_COUNT)
820
    return false;
821
822
  map = linemap_lookup (set, location);
823
  return linemap_macro_expansion_map_p (map);
824
}
825
309
/* Print an include trace, for e.g. the -H option of the preprocessor.  */
826
/* Print an include trace, for e.g. the -H option of the preprocessor.  */
310
827
311
static void
828
static void
 Lines 315-319   trace_include (const struct line_maps *set, const struct line_map *map) Link Here 
315
832
316
  while (--i)
833
  while (--i)
317
    putc ('.', stderr);
834
    putc ('.', stderr);
318
  fprintf (stderr, " %s\n", map->to_file);
835
  linemap_check_ordinary (map);
836
  fprintf (stderr, " %s\n", map->d.ordinary.to_file);
837
}
838
839
/* Expand source code location LOC and return user readable source
840
   code location. If TO_MACRO_DEF_LOC_P is TRUE and LOC is a
841
   location of a token inside a macro replacement-list at an expansion
842
   point, the function expands the location to the source locus of
843
   the token in the relevant macro definition.  */
844
845
expanded_location
846
linemap_expand_location_full (struct line_maps *set,
847
			      source_location loc,
848
			      bool to_macro_def_loc_p,
849
			      const struct line_map **loc_map)
850
{
851
  const struct line_map *map;
852
  expanded_location xloc;
853
854
  linemap_assert (set && loc >= RESERVED_LOCATION_COUNT);
855
856
  loc = (to_macro_def_loc_p)
857
    ? linemap_macro_loc_to_def_point (set, loc, &map, true)
858
    : linemap_macro_loc_to_exp_point (set, loc, &map);      
859
  xloc.file = LINEMAP_FILE (map);
860
  xloc.line = SOURCE_LINE (map, loc);
861
  xloc.column = SOURCE_COLUMN (map, loc);
862
  xloc.sysp = LINEMAP_SYSP (map) != 0;
863
  if (loc_map)
864
    *loc_map = map;
865
866
  return xloc;
867
}
868
869
/* Dump debugging information about source location LOC into the file
870
   stream STREAM. SET is the line map set LOC comes from.  */
871
872
void
873
linemap_dump_location (struct line_maps *set,
874
		       source_location loc,
875
		       FILE *stream)
876
{
877
  const struct line_map *map;
878
  source_location location;
879
  const char *p;
880
  int l,c,s,e;
881
882
  if (loc == 0)
883
    return;
884
885
  location =
886
    linemap_macro_loc_to_def_point (set, loc, &map, true);
887
  p = LINEMAP_FILE (map);
888
889
  l = SOURCE_LINE (map, location);
890
  c = SOURCE_COLUMN (map, location);
891
  s = LINEMAP_SYSP (map) != 0;
892
  e = (location != loc);
893
  
894
  /* P: path, L: line, C: column, S: in-system-header, M: map address,
895
     E: macro expansion?.   */
896
  fprintf (stream, "{P:%s;L:%d;C:%d;S:%d;M:%p;E:%d,LOC:%d}",
897
	   p, l, c, s, (void*)map, e, loc);
319
}
898
}
(-)a/libcpp/macro.c (-34 / +116 lines)
 Lines 47-53   static int builtin_macro (cpp_reader *, cpp_hashnode *); Link Here 
47
static void push_ptoken_context (cpp_reader *, cpp_hashnode *, _cpp_buff *,
47
static void push_ptoken_context (cpp_reader *, cpp_hashnode *, _cpp_buff *,
48
				 const cpp_token **, unsigned int);
48
				 const cpp_token **, unsigned int);
49
static _cpp_buff *collect_args (cpp_reader *, const cpp_hashnode *,
49
static _cpp_buff *collect_args (cpp_reader *, const cpp_hashnode *,
50
				_cpp_buff **);
50
				_cpp_buff **, source_location *);
51
static cpp_context *next_context (cpp_reader *);
51
static cpp_context *next_context (cpp_reader *);
52
static const cpp_token *padding_token (cpp_reader *, const cpp_token *);
52
static const cpp_token *padding_token (cpp_reader *, const cpp_token *);
53
static void expand_arg (cpp_reader *, macro_arg *);
53
static void expand_arg (cpp_reader *, macro_arg *);
 Lines 56-64   static const cpp_token *stringify_arg (cpp_reader *, macro_arg *); Link Here 
56
static void paste_all_tokens (cpp_reader *, const cpp_token *);
56
static void paste_all_tokens (cpp_reader *, const cpp_token *);
57
static bool paste_tokens (cpp_reader *, const cpp_token **, const cpp_token *);
57
static bool paste_tokens (cpp_reader *, const cpp_token **, const cpp_token *);
58
static void replace_args (cpp_reader *, cpp_hashnode *, cpp_macro *,
58
static void replace_args (cpp_reader *, cpp_hashnode *, cpp_macro *,
59
			  macro_arg *);
59
			  macro_arg *, source_location, source_location);
60
static _cpp_buff *funlike_invocation_p (cpp_reader *, cpp_hashnode *,
60
static _cpp_buff *funlike_invocation_p (cpp_reader *, cpp_hashnode *,
61
					_cpp_buff **);
61
					_cpp_buff **, source_location *);
62
static bool create_iso_definition (cpp_reader *, cpp_macro *);
62
static bool create_iso_definition (cpp_reader *, cpp_macro *);
63
63
64
/* #define directive parsing and handling.  */
64
/* #define directive parsing and handling.  */
 Lines 177-183   _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node) Link Here 
177
	  while (! MAIN_FILE_P (map))
177
	  while (! MAIN_FILE_P (map))
178
	    map = INCLUDED_FROM (pfile->line_table, map);
178
	    map = INCLUDED_FROM (pfile->line_table, map);
179
179
180
	name = map->to_file;
180
	linemap_check_ordinary (map);
181
	name = map->d.ordinary.to_file;
181
	len = strlen (name);
182
	len = strlen (name);
182
	buf = _cpp_unaligned_alloc (pfile, len * 2 + 3);
183
	buf = _cpp_unaligned_alloc (pfile, len * 2 + 3);
183
	result = buf;
184
	result = buf;
 Lines 200-209   _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node) Link Here 
200
      /* If __LINE__ is embedded in a macro, it must expand to the
201
      /* If __LINE__ is embedded in a macro, it must expand to the
201
	 line of the macro's invocation, not its definition.
202
	 line of the macro's invocation, not its definition.
202
	 Otherwise things like assert() will not work properly.  */
203
	 Otherwise things like assert() will not work properly.  */
203
      number = SOURCE_LINE (map, 
204
      number = linemap_get_source_line (pfile->line_table,
205
					CPP_OPTION (pfile, traditional)
206
					? pfile->line_table->highest_line
207
					: pfile->cur_token[-1].src_loc);
208
      /*number = SOURCE_LINE (map, 
204
			    CPP_OPTION (pfile, traditional) 
209
			    CPP_OPTION (pfile, traditional) 
205
			    ? pfile->line_table->highest_line
210
			    ? pfile->line_table->highest_line
206
			    : pfile->cur_token[-1].src_loc);
211
			    : pfile->cur_token[-1].src_loc);*/
207
      break;
212
      break;
208
213
209
      /* __STDC__ has the value 1 under normal circumstances.
214
      /* __STDC__ has the value 1 under normal circumstances.
 Lines 587-593   _cpp_arguments_ok (cpp_reader *pfile, cpp_macro *macro, const cpp_hashnode *node Link Here 
587
   CPP_PRAGMA ... CPP_PRAGMA_EOL tokens into *PRAGMA_BUFF buffer.  */
592
   CPP_PRAGMA ... CPP_PRAGMA_EOL tokens into *PRAGMA_BUFF buffer.  */
588
static _cpp_buff *
593
static _cpp_buff *
589
collect_args (cpp_reader *pfile, const cpp_hashnode *node,
594
collect_args (cpp_reader *pfile, const cpp_hashnode *node,
590
	      _cpp_buff **pragma_buff)
595
	      _cpp_buff **pragma_buff, source_location *paren_loc)
591
{
596
{
592
  _cpp_buff *buff, *base_buff;
597
  _cpp_buff *buff, *base_buff;
593
  cpp_macro *macro;
598
  cpp_macro *macro;
 Lines 736-741   collect_args (cpp_reader *pfile, const cpp_hashnode *node, Link Here 
736
    }
741
    }
737
  else
742
  else
738
    {
743
    {
744
      *paren_loc = token->src_loc;
739
      /* A single empty argument is counted as no argument.  */
745
      /* A single empty argument is counted as no argument.  */
740
      if (argc == 1 && macro->paramc == 0 && args[0].count == 0)
746
      if (argc == 1 && macro->paramc == 0 && args[0].count == 0)
741
	argc = 0;
747
	argc = 0;
 Lines 768-774   collect_args (cpp_reader *pfile, const cpp_hashnode *node, Link Here 
768
   argument is the same as in collect_args.  */
774
   argument is the same as in collect_args.  */
769
static _cpp_buff *
775
static _cpp_buff *
770
funlike_invocation_p (cpp_reader *pfile, cpp_hashnode *node,
776
funlike_invocation_p (cpp_reader *pfile, cpp_hashnode *node,
771
		      _cpp_buff **pragma_buff)
777
		      _cpp_buff **pragma_buff, source_location *paren_loc)
772
{
778
{
773
  const cpp_token *token, *padding = NULL;
779
  const cpp_token *token, *padding = NULL;
774
780
 Lines 785-791   funlike_invocation_p (cpp_reader *pfile, cpp_hashnode *node, Link Here 
785
  if (token->type == CPP_OPEN_PAREN)
791
  if (token->type == CPP_OPEN_PAREN)
786
    {
792
    {
787
      pfile->state.parsing_args = 2;
793
      pfile->state.parsing_args = 2;
788
      return collect_args (pfile, node, pragma_buff);
794
      return collect_args (pfile, node, pragma_buff, paren_loc);
789
    }
795
    }
790
796
791
  /* CPP_EOF can be the end of macro arguments, or the end of the
797
  /* CPP_EOF can be the end of macro arguments, or the end of the
 Lines 844-849   enter_macro_context (cpp_reader *pfile, cpp_hashnode *node, Link Here 
844
    {
850
    {
845
      cpp_macro *macro = node->value.macro;
851
      cpp_macro *macro = node->value.macro;
846
      _cpp_buff *pragma_buff = NULL;
852
      _cpp_buff *pragma_buff = NULL;
853
      source_location paren_loc = result->src_loc;
847
854
848
      if (macro->fun_like)
855
      if (macro->fun_like)
849
	{
856
	{
 Lines 852-858   enter_macro_context (cpp_reader *pfile, cpp_hashnode *node, Link Here 
852
	  pfile->state.prevent_expansion++;
859
	  pfile->state.prevent_expansion++;
853
	  pfile->keep_tokens++;
860
	  pfile->keep_tokens++;
854
	  pfile->state.parsing_args = 1;
861
	  pfile->state.parsing_args = 1;
855
	  buff = funlike_invocation_p (pfile, node, &pragma_buff);
862
	  buff = funlike_invocation_p (pfile, node, &pragma_buff,
863
				       &paren_loc);
856
	  pfile->state.parsing_args = 0;
864
	  pfile->state.parsing_args = 0;
857
	  pfile->keep_tokens--;
865
	  pfile->keep_tokens--;
858
	  pfile->state.prevent_expansion--;
866
	  pfile->state.prevent_expansion--;
 Lines 871-877   enter_macro_context (cpp_reader *pfile, cpp_hashnode *node, Link Here 
871
	    }
879
	    }
872
880
873
	  if (macro->paramc > 0)
881
	  if (macro->paramc > 0)
874
	    replace_args (pfile, node, macro, (macro_arg *) buff->base);
882
	    replace_args (pfile, node, macro, (macro_arg *) buff->base,
883
			  result->src_loc, paren_loc);
875
	  _cpp_release_buff (pfile, buff);
884
	  _cpp_release_buff (pfile, buff);
876
	}
885
	}
877
886
 Lines 891-898   enter_macro_context (cpp_reader *pfile, cpp_hashnode *node, Link Here 
891
      macro->used = 1;
900
      macro->used = 1;
892
901
893
      if (macro->paramc == 0)
902
      if (macro->paramc == 0)
894
	_cpp_push_token_context (pfile, node, macro->exp.tokens,
903
	{
895
				 macro_real_token_count (macro));
904
	  if (CPP_OPTION (pfile, track_macro_expansion))
905
	    {
906
	      unsigned int i, count = macro_real_token_count (macro);
907
	      _cpp_buff *buff = _cpp_get_buff (pfile,
908
					       count * sizeof (cpp_token));
909
	      const cpp_token *src = macro->exp.tokens;
910
	      cpp_token *first = (cpp_token *) buff->base;
911
	      cpp_token *dest = first;
912
	      /* Create a macro map to record the locations of the tokens
913
		 that are involved in the expansion. Note that the
914
		 expansion point is set to the location closing
915
		 parenthesis. Otherwise, the subsequent map created for
916
		 the first token that comes after the macro map might have
917
		 a wrong line number. What would lead to tokens having
918
		 with wrong line numbers after the macro expansion.  */
919
	      const struct line_map *map = NULL;
920
	  
921
	      map  = linemap_enter_macro (pfile->line_table, macro,
922
					  paren_loc, count);
923
	      for (i = 0; i < count; ++i)
924
		{
925
		  *dest = *src;
926
		  dest->src_loc = linemap_add_macro_token (map, i,
927
							   dest->src_loc,
928
							   dest->src_loc);
929
		  ++dest;
930
		  ++src;
931
		}
932
	      linemap_leave_macro (pfile->line_table, paren_loc);
933
	      /* FIXME freeing  */
934
	      _cpp_push_token_context (pfile, node, first, count);
935
	    }
936
	  else
937
	    _cpp_push_token_context (pfile, node, macro->exp.tokens,
938
				     macro_real_token_count (macro));
939
	}
896
940
897
      if (pragma_buff)
941
      if (pragma_buff)
898
	{
942
	{
 Lines 925-938   enter_macro_context (cpp_reader *pfile, cpp_hashnode *node, Link Here 
925
   Expand each argument before replacing, unless it is operated upon
969
   Expand each argument before replacing, unless it is operated upon
926
   by the # or ## operators.  */
970
   by the # or ## operators.  */
927
static void
971
static void
928
replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, macro_arg *args)
972
replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro,
973
	      macro_arg *args, source_location macro_loc,
974
	      source_location paren_loc)
929
{
975
{
930
  unsigned int i, total;
976
  unsigned int i, total;
931
  const cpp_token *src, *limit;
977
  const cpp_token *src, *limit;
932
  const cpp_token **dest, **first;
978
  cpp_token *dest, *first;
933
  macro_arg *arg;
979
  macro_arg *arg;
934
  _cpp_buff *buff;
980
  _cpp_buff *buff;
935
  unsigned int count;
981
  unsigned int count;
982
  const struct line_map *map = NULL;
936
983
937
  /* First, fully macro-expand arguments, calculating the number of
984
  /* First, fully macro-expand arguments, calculating the number of
938
     tokens in the final expansion as we go.  The ordering of the if
985
     tokens in the final expansion as we go.  The ordering of the if
 Lines 970-987   replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, macro_arg Link Here 
970
1017
971
  /* Now allocate space for the expansion, copy the tokens and replace
1018
  /* Now allocate space for the expansion, copy the tokens and replace
972
     the arguments.  */
1019
     the arguments.  */
973
  buff = _cpp_get_buff (pfile, total * sizeof (cpp_token *));
1020
  buff = _cpp_get_buff (pfile, total * sizeof (cpp_token));
974
  first = (const cpp_token **) buff->base;
1021
  first = (cpp_token *) buff->base;
975
  dest = first;
1022
  dest = first;
976
1023
  macro_loc = macro_loc;
977
  for (src = macro->exp.tokens; src < limit; src++)
1024
  /* Create a macro map to record the locations of the tokens that are
1025
     involved in the expansion. Note that the expansion point
1026
     is set to the location closing parenthesis. Otherwise,
1027
     the subsequent map created for the first token that comes
1028
     after the macro map might have a wrong line number. What
1029
     would lead to tokens having with wrong line numbers after
1030
     the macro expansion.  */
1031
  if (CPP_OPTION (pfile, track_macro_expansion))
1032
    map = linemap_enter_macro (pfile->line_table, macro, paren_loc, total);
1033
  i = 0;
1034
  for (src = macro->exp.tokens; src < limit; src++, i++)
978
    {
1035
    {
979
      unsigned int count;
1036
      unsigned int count;
980
      const cpp_token **from, **paste_flag;
1037
      const cpp_token **from;
1038
      cpp_token *paste_flag;
981
1039
982
      if (src->type != CPP_MACRO_ARG)
1040
      if (src->type != CPP_MACRO_ARG)
983
	{
1041
	{
984
	  *dest++ = src;
1042
	  *dest = *src;
1043
	  if (CPP_OPTION (pfile, track_macro_expansion))
1044
	    dest->src_loc = linemap_add_macro_token (map, i, dest->src_loc,
1045
						     dest->src_loc);
1046
	  ++dest;
985
	  continue;
1047
	  continue;
986
	}
1048
	}
987
1049
 Lines 996-1002   replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, macro_arg Link Here 
996
	  count = arg->count, from = arg->first;
1058
	  count = arg->count, from = arg->first;
997
	  if (dest != first)
1059
	  if (dest != first)
998
	    {
1060
	    {
999
	      if (dest[-1]->type == CPP_COMMA
1061
	      if (dest[-1].type == CPP_COMMA
1000
		  && macro->variadic
1062
		  && macro->variadic
1001
		  && src->val.macro_arg.arg_no == macro->paramc)
1063
		  && src->val.macro_arg.arg_no == macro->paramc)
1002
		{
1064
		{
 Lines 1018-1029   replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, macro_arg Link Here 
1018
      /* Padding on the left of an argument (unless RHS of ##).  */
1080
      /* Padding on the left of an argument (unless RHS of ##).  */
1019
      if ((!pfile->state.in_directive || pfile->state.directive_wants_padding)
1081
      if ((!pfile->state.in_directive || pfile->state.directive_wants_padding)
1020
	  && src != macro->exp.tokens && !(src[-1].flags & PASTE_LEFT))
1082
	  && src != macro->exp.tokens && !(src[-1].flags & PASTE_LEFT))
1021
	*dest++ = padding_token (pfile, src);
1083
	{
1084
	  *dest = *padding_token (pfile, src);
1085
	  if (CPP_OPTION (pfile, track_macro_expansion))
1086
	    dest->src_loc = linemap_add_macro_token (map, i, dest->src_loc,
1087
						     dest->src_loc);
1088
	  ++dest;
1089
	}
1022
1090
1023
      if (count)
1091
      if (count)
1024
	{
1092
	{
1025
	  memcpy (dest, from, count * sizeof (cpp_token *));
1093
	  unsigned int j;
1026
	  dest += count;
1094
	  for (j = 0; j < count; ++j)
1095
	    {
1096
	      *dest = *from[j];
1097
	      if (CPP_OPTION (pfile, track_macro_expansion))
1098
		dest->src_loc = linemap_add_macro_token (map, i, dest->src_loc,
1099
							 src->src_loc);
1100
	      ++dest;
1101
	    }
1027
1102
1028
	  /* With a non-empty argument on the LHS of ##, the last
1103
	  /* With a non-empty argument on the LHS of ##, the last
1029
	     token should be flagged PASTE_LEFT.  */
1104
	     token should be flagged PASTE_LEFT.  */
 Lines 1044-1071   replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, macro_arg Link Here 
1044
1119
1045
      /* Avoid paste on RHS (even case count == 0).  */
1120
      /* Avoid paste on RHS (even case count == 0).  */
1046
      if (!pfile->state.in_directive && !(src->flags & PASTE_LEFT))
1121
      if (!pfile->state.in_directive && !(src->flags & PASTE_LEFT))
1047
	*dest++ = &pfile->avoid_paste;
1122
	{
1123
	  *dest = pfile->avoid_paste;
1124
	  /* Don't bother changing the location here.  */
1125
	  ++dest;
1126
	}
1048
1127
1049
      /* Add a new paste flag, or remove an unwanted one.  */
1128
      /* Add a new paste flag, or remove an unwanted one.  */
1050
      if (paste_flag)
1129
      if (paste_flag)
1051
	{
1130
	{
1052
	  cpp_token *token = _cpp_temp_token (pfile);
1053
	  token->type = (*paste_flag)->type;
1054
	  token->val = (*paste_flag)->val;
1055
	  if (src->flags & PASTE_LEFT)
1131
	  if (src->flags & PASTE_LEFT)
1056
	    token->flags = (*paste_flag)->flags | PASTE_LEFT;
1132
	    paste_flag->flags |= PASTE_LEFT;
1057
	  else
1133
	  else
1058
	    token->flags = (*paste_flag)->flags & ~PASTE_LEFT;
1134
	    paste_flag->flags &= ~PASTE_LEFT;
1059
	  *paste_flag = token;
1060
	}
1135
	}
1061
    }
1136
    }
1137
  if (CPP_OPTION (pfile, track_macro_expansion))
1138
    linemap_leave_macro (pfile->line_table, paren_loc);
1062
1139
1063
  /* Free the expanded arguments.  */
1140
  /* Free the expanded arguments.  */
1064
  for (i = 0; i < macro->paramc; i++)
1141
  for (i = 0; i < macro->paramc; i++)
1065
    if (args[i].expanded)
1142
    if (args[i].expanded)
1066
      free (args[i].expanded);
1143
      free (args[i].expanded);
1067
1144
1068
  push_ptoken_context (pfile, node, buff, first, dest - first);
1145
  /* FIXME: doesn't handle BUFF */
1146
  _cpp_push_token_context (pfile, node, first, dest - first);
1069
}
1147
}
1070
1148
1071
/* Return a special padding token, with padding inherited from SOURCE.  */
1149
/* Return a special padding token, with padding inherited from SOURCE.  */
 Lines 1340-1346   cpp_get_token (cpp_reader *pfile) Link Here 
1340
   is set to the location "as expected by the user".  This matters
1418
   is set to the location "as expected by the user".  This matters
1341
   when a token results from macro expansion -- the token's location
1419
   when a token results from macro expansion -- the token's location
1342
   will indicate where the macro is defined, but *LOC will be the
1420
   will indicate where the macro is defined, but *LOC will be the
1343
   location of the start of the expansion.  */
1421
   location of the start of the expansion.
1422
1423
   Note that this function should only be used when macro expansion
1424
   location tracking is disabled.  */
1344
const cpp_token *
1425
const cpp_token *
1345
cpp_get_token_with_location (cpp_reader *pfile, source_location *loc)
1426
cpp_get_token_with_location (cpp_reader *pfile, source_location *loc)
1346
{
1427
{
 Lines 1851-1856   _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node) Link Here 
1851
      (sizeof (cpp_macro));
1932
      (sizeof (cpp_macro));
1852
  else
1933
  else
1853
    macro = (cpp_macro *) _cpp_aligned_alloc (pfile, sizeof (cpp_macro));
1934
    macro = (cpp_macro *) _cpp_aligned_alloc (pfile, sizeof (cpp_macro));
1935
  macro->name = node;
1854
  macro->line = pfile->directive_line;
1936
  macro->line = pfile->directive_line;
1855
  macro->params = 0;
1937
  macro->params = 0;
1856
  macro->paramc = 0;
1938
  macro->paramc = 0;

Return to bug 7263