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

Collapse All | Expand All

(-)a/gcc/c-decl.c (-1 / +2 lines)
Lines 8785-8791 declspecs_add_type (location_t loc, struct c_declspecs *specs, Link Here
8785
	      break;
8785
	      break;
8786
	    case RID_COMPLEX:
8786
	    case RID_COMPLEX:
8787
	      dupe = specs->complex_p;
8787
	      dupe = specs->complex_p;
8788
	      if (!flag_isoc99 && !in_system_header)
8788
	      if (!flag_isoc99
8789
		  && !linemap_location_originated_from_system_header_p (line_table, loc))
8789
		pedwarn (loc, OPT_pedantic,
8790
		pedwarn (loc, OPT_pedantic,
8790
			 "ISO C90 does not support complex types");
8791
			 "ISO C90 does not support complex types");
8791
	      if (specs->typespec_word == cts_void)
8792
	      if (specs->typespec_word == cts_void)
(-)a/gcc/c-lex.c (-9 / +10 lines)
Lines 1-6 Link Here
1
/* Mainly the interface between cpplib and the C front ends.
1
/* Mainly the interface between cpplib and the C front ends.
2
   Copyright (C) 1987, 1988, 1989, 1992, 1994, 1995, 1996, 1997
2
   Copyright (C) 1987, 1988, 1989, 1992, 1994, 1995, 1996, 1997
3
   1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
3
   1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
4
   2010
4
   Free Software Foundation, Inc.
5
   Free Software Foundation, Inc.
5
6
6
This file is part of GCC.
7
This file is part of GCC.
Lines 207-213 fe_file_change (const struct line_map *new_map) Link Here
207
	    line = SOURCE_LINE (new_map - 1, included_at);
208
	    line = SOURCE_LINE (new_map - 1, included_at);
208
209
209
	  input_location = new_map->start_location;
210
	  input_location = new_map->start_location;
210
	  (*debug_hooks->start_source_file) (line, new_map->to_file);
211
	  (*debug_hooks->start_source_file) (line, LINEMAP_FILE (new_map));
211
#ifndef NO_IMPLICIT_EXTERN_C
212
#ifndef NO_IMPLICIT_EXTERN_C
212
	  if (c_header_level)
213
	  if (c_header_level)
213
	    ++c_header_level;
214
	    ++c_header_level;
Lines 231-240 fe_file_change (const struct line_map *new_map) Link Here
231
#endif
232
#endif
232
      input_location = new_map->start_location;
233
      input_location = new_map->start_location;
233
234
234
      (*debug_hooks->end_source_file) (new_map->to_line);
235
      (*debug_hooks->end_source_file) (LINEMAP_LINE (new_map));
235
    }
236
    }
236
237
237
  update_header_times (new_map->to_file);
238
  update_header_times (LINEMAP_FILE (new_map));
238
  input_location = new_map->start_location;
239
  input_location = new_map->start_location;
239
}
240
}
240
241
Lines 299-305 c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags, Link Here
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 (parse_in);
304
  *loc = tok->src_loc;
303
  type = tok->type;
305
  type = tok->type;
304
306
305
 retry_after_at:
307
 retry_after_at:
Lines 346-355 c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags, Link Here
346
      if (c_dialect_objc ())
348
      if (c_dialect_objc ())
347
	{
349
	{
348
	  location_t atloc = *loc;
350
	  location_t atloc = *loc;
349
	  location_t newloc;
350
351
351
	retry_at:
352
	retry_at:
352
	  tok = cpp_get_token_with_location (parse_in, &newloc);
353
	  tok = cpp_get_token (parse_in);
353
	  type = tok->type;
354
	  type = tok->type;
354
	  switch (type)
355
	  switch (type)
355
	    {
356
	    {
Lines 376-382 c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags, Link Here
376
	    default:
377
	    default:
377
	      /* ... or not.  */
378
	      /* ... or not.  */
378
	      error_at (atloc, "stray %<@%> in program");
379
	      error_at (atloc, "stray %<@%> in program");
379
	      *loc = newloc;
380
	      *loc = tok->src_loc;
380
	      goto retry_after_at;
381
	      goto retry_after_at;
381
	    }
382
	    }
382
	  break;
383
	  break;
Lines 390-396 c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags, Link Here
390
391
391
	*cpp_spell_token (parse_in, tok, name, true) = 0;
392
	*cpp_spell_token (parse_in, tok, name, true) = 0;
392
393
393
	error ("stray %qs in program", name);
394
	error_at (tok->src_loc, "stray %qs in program", name);
394
      }
395
      }
395
396
396
      goto retry;
397
      goto retry;
(-)a/gcc/c-opts.c (+4 lines)
Lines 856-861 c_common_handle_option (size_t scode, const char *arg, int value, Link Here
856
      cpp_opts->preprocessed = value;
856
      cpp_opts->preprocessed = value;
857
      break;
857
      break;
858
858
859
    case OPT_fdebug_cpp:
860
      cpp_opts->debug = 1;
861
      break;
862
859
    case OPT_freplace_objc_classes:
863
    case OPT_freplace_objc_classes:
860
      flag_replace_objc_classes = value;
864
      flag_replace_objc_classes = value;
861
      break;
865
      break;
(-)a/gcc/c-ppoutput.c (-30 / +69 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 170-176 scan_translation_unit (cpp_reader *pfile) Link Here
170
  for (;;)
172
  for (;;)
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 (pfile);
176
      loc = token->src_loc;
174
177
175
      if (token->type == CPP_PADDING)
178
      if (token->type == CPP_PADDING)
176
	{
179
	{
Lines 188-196 scan_translation_unit (cpp_reader *pfile) Link Here
188
      /* Subtle logic to output a space if and only if necessary.  */
191
      /* Subtle logic to output a space if and only if necessary.  */
189
      if (avoid_paste)
192
      if (avoid_paste)
190
	{
193
	{
191
	  const struct line_map *map
194
	  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
195
195
	  if (print.source == NULL)
196
	  if (print.source == NULL)
196
	    print.source = token;
197
	    print.source = token;
Lines 210-218 scan_translation_unit (cpp_reader *pfile) Link Here
210
	}
211
	}
211
      else if (token->flags & PREV_WHITE)
212
      else if (token->flags & PREV_WHITE)
212
	{
213
	{
213
	  const struct line_map *map
214
	  int src_line = linemap_get_source_line (line_table, loc);
214
	    = linemap_lookup (line_table, loc);
215
	  int src_line = SOURCE_LINE (map, loc);
216
215
217
	  if (src_line != print.src_line
216
	  if (src_line != print.src_line
218
	      && do_line_adjustments
217
	      && do_line_adjustments
Lines 245-251 scan_translation_unit (cpp_reader *pfile) Link Here
245
	  in_pragma = false;
244
	  in_pragma = false;
246
	}
245
	}
247
      else
246
      else
248
	cpp_output_token (token, print.outf);
247
	{
248
	  if (cpp_get_options (parse_in)->debug)
249
	      linemap_dump_location (line_table, token->src_loc,
250
				     print.outf);
251
	  cpp_output_token (token, print.outf);
252
	}
249
253
250
      if (token->type == CPP_COMMENT)
254
      if (token->type == CPP_COMMENT)
251
	account_for_newlines (token->val.str.text, token->val.str.len);
255
	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
303
/* 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
304
   different line to the current one, output the required newlines or
301
   a line marker, and return 1.  Otherwise return 0.  */
305
   a line marker, and return 1.  Otherwise return 0.  */
306
302
static void
307
static void
303
maybe_print_line (source_location src_loc)
308
maybe_print_line_1 (source_location src_loc, FILE *stream)
304
{
309
{
305
  const struct line_map *map = linemap_lookup (line_table, src_loc);
310
  int src_line = linemap_get_source_line (line_table, src_loc);
306
  int src_line = SOURCE_LINE (map, src_loc);
307
  /* End the previous line of text.  */
311
  /* End the previous line of text.  */
308
  if (print.printed)
312
  if (print.printed)
309
    {
313
    {
310
      putc ('\n', print.outf);
314
      putc ('\n', stream);
311
      print.src_line++;
315
      print.src_line++;
312
      print.printed = 0;
316
      print.printed = 0;
313
    }
317
    }
Lines 316-368 maybe_print_line (source_location src_loc) Link Here
316
    {
320
    {
317
      while (src_line > print.src_line)
321
      while (src_line > print.src_line)
318
	{
322
	{
319
	  putc ('\n', print.outf);
323
	  putc ('\n', stream);
320
	  print.src_line++;
324
	  print.src_line++;
321
	}
325
	}
322
    }
326
    }
323
  else
327
  else
324
    print_line (src_loc, "");
328
    print_line_1 (src_loc, "", stream);
329
330
}
331
332
/* If the token read on logical line LINE needs to be output on a
333
   different line to the current one, output the required newlines or
334
   a line marker, and return 1.  Otherwise return 0.  */
335
336
static void
337
maybe_print_line (source_location src_loc)
338
{
339
  if (cpp_get_options (parse_in)->debug)
340
    linemap_dump_location (line_table, src_loc,
341
			   print.outf);
342
  maybe_print_line_1 (src_loc, print.outf);
325
}
343
}
326
344
327
/* Output a line marker for logical line LINE.  Special flags are "1"
345
/* Output a line marker for logical line LINE.  Special flags are "1"
328
   or "2" indicating entering or leaving a file.  */
346
   or "2" indicating entering or leaving a file.  */
347
329
static void
348
static void
330
print_line (source_location src_loc, const char *special_flags)
349
print_line_1 (source_location src_loc, const char *special_flags, FILE *stream)
331
{
350
{
332
  /* End any previous line of text.  */
351
  /* End any previous line of text.  */
333
  if (print.printed)
352
  if (print.printed)
334
    putc ('\n', print.outf);
353
    putc ('\n', stream);
335
  print.printed = 0;
354
  print.printed = 0;
336
355
337
  if (!flag_no_line_commands)
356
  if (!flag_no_line_commands)
338
    {
357
    {
339
      const struct line_map *map = linemap_lookup (line_table, src_loc);
358
      const char *file_path = linemap_get_file_path (line_table, src_loc);
340
359
      int sysp;
341
      size_t to_file_len = strlen (map->to_file);
360
      size_t to_file_len = strlen (file_path);
342
      unsigned char *to_file_quoted =
361
      unsigned char *to_file_quoted =
343
         (unsigned char *) alloca (to_file_len * 4 + 1);
362
         (unsigned char *) alloca (to_file_len * 4 + 1);
344
      unsigned char *p;
363
      unsigned char *p;
345
364
346
      print.src_line = SOURCE_LINE (map, src_loc);
365
      print.src_line = linemap_get_source_line (line_table, src_loc);
347
366
348
      /* cpp_quote_string does not nul-terminate, so we have to do it
367
      /* cpp_quote_string does not nul-terminate, so we have to do it
349
	 ourselves.  */
368
	 ourselves.  */
350
      p = cpp_quote_string (to_file_quoted,
369
      p = cpp_quote_string (to_file_quoted,
351
			    (const unsigned char *) map->to_file, to_file_len);
370
			    (const unsigned char *) file_path,
371
			    to_file_len);
352
      *p = '\0';
372
      *p = '\0';
353
      fprintf (print.outf, "# %u \"%s\"%s",
373
      fprintf (stream, "# %u \"%s\"%s",
354
	       print.src_line == 0 ? 1 : print.src_line,
374
	       print.src_line == 0 ? 1 : print.src_line,
355
	       to_file_quoted, special_flags);
375
	       to_file_quoted, special_flags);
356
376
357
      if (map->sysp == 2)
377
      sysp = linemap_location_in_system_header_p (line_table, src_loc);
358
	fputs (" 3 4", print.outf);
378
      if (sysp == 2)
359
      else if (map->sysp == 1)
379
	fputs (" 3 4", stream);
360
	fputs (" 3", print.outf);
380
      else if (sysp == 1)
381
	fputs (" 3", stream);
361
382
362
      putc ('\n', print.outf);
383
      putc ('\n', stream);
363
    }
384
    }
364
}
385
}
365
386
387
/* Output a line marker for logical line LINE.  Special flags are "1"
388
   or "2" indicating entering or leaving a file.  */
389
390
static void
391
print_line (source_location src_loc, const char *special_flags)
392
{
393
    if (cpp_get_options (parse_in)->debug)
394
      linemap_dump_location (line_table, src_loc,
395
			     print.outf);
396
    print_line_1 (src_loc, special_flags, print.outf);
397
}
398
366
/* Helper function for cb_line_change and scan_translation_unit.  */
399
/* Helper function for cb_line_change and scan_translation_unit.  */
367
static void
400
static void
368
do_line_change (cpp_reader *pfile, const cpp_token *token,
401
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.  */
418
     ought to care.  Some things do care; the fault lies with them.  */
386
  if (!CPP_OPTION (pfile, traditional))
419
  if (!CPP_OPTION (pfile, traditional))
387
    {
420
    {
388
      const struct line_map *map = linemap_lookup (line_table, src_loc);
421
      int spaces = linemap_get_source_column (line_table, src_loc) - 2;
389
      int spaces = SOURCE_COLUMN (map, src_loc) - 2;
390
      print.printed = 1;
422
      print.printed = 1;
391
423
392
      while (-- spaces >= 0)
424
      while (-- spaces >= 0)
Lines 415-420 cb_ident (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, Link Here
415
static void
447
static void
416
cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node)
448
cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node)
417
{
449
{
450
   const struct line_map *map;
451
452
  if (line <= BUILTINS_LOCATION)
453
    return;
418
  maybe_print_line (line);
454
  maybe_print_line (line);
419
  fputs ("#define ", print.outf);
455
  fputs ("#define ", print.outf);
420
456
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);
462
    fputs ((const char *) NODE_NAME (node), print.outf);
427
463
428
  putc ('\n', print.outf);
464
  putc ('\n', print.outf);
429
  if (linemap_lookup (line_table, line)->to_line != 0)
465
  linemap_macro_loc_to_exp_point (line_table, line, &map);
466
  if (LINEMAP_LINE (map) != 0)
430
    print.src_line++;
467
    print.src_line++;
431
}
468
}
432
469
Lines 434-439 static void Link Here
434
cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
471
cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
435
	  cpp_hashnode *node)
472
	  cpp_hashnode *node)
436
{
473
{
474
  if (line <= BUILTINS_LOCATION)
475
    return;
437
  maybe_print_line (line);
476
  maybe_print_line (line);
438
  fprintf (print.outf, "#undef %s\n", NODE_NAME (node));
477
  fprintf (print.outf, "#undef %s\n", NODE_NAME (node));
439
  print.src_line++;
478
  print.src_line++;
(-)a/gcc/c.opt (+4 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
748
fpretty-templates
752
fpretty-templates
749
C++ ObjC++
753
C++ ObjC++
750
-fno-pretty-templates Do not pretty-print template specializations as the template signature followed by the arguments
754
-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 2547-2553 static void Link Here
2547
cp_diagnostic_starter (diagnostic_context *context,
2547
cp_diagnostic_starter (diagnostic_context *context,
2548
		       diagnostic_info *diagnostic)
2548
		       diagnostic_info *diagnostic)
2549
{
2549
{
2550
  diagnostic_report_current_module (context);
2550
  diagnostic_report_current_module (context, diagnostic->location);
2551
  cp_print_error_function (context, diagnostic);
2551
  cp_print_error_function (context, diagnostic);
2552
  maybe_print_instantiation_context (context);
2552
  maybe_print_instantiation_context (context);
2553
  pp_base_set_prefix (context->printer, diagnostic_build_prefix (context,
2553
  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 (-5 / +1 lines)
Lines 43-53 expand_location (source_location loc) Link Here
43
    }
43
    }
44
  else
44
  else
45
    {
45
    {
46
      const struct line_map *map = linemap_lookup (line_table, loc);
46
      return linemap_expand_location_full (line_table, loc, false, NULL);
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
    };
47
    };
52
  return xloc;
48
  return xloc;
53
}
49
}
(-)a/gcc/input.h (-18 / +5 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 59-70 typedef source_location location_t; Link Here
59
45
60
extern location_t input_location;
46
extern location_t input_location;
61
47
62
#define LOCATION_FILE(LOC) ((expand_location (LOC)).file)
48
#define LOCATION_FILE(LOC) (linemap_get_file_path (line_table, LOC))
63
#define LOCATION_LINE(LOC) ((expand_location (LOC)).line)
49
#define LOCATION_LINE(LOC) (linemap_get_source_line (line_table, LOC))
64
50
65
#define input_line LOCATION_LINE (input_location)
51
#define input_line LOCATION_LINE (input_location)
66
#define input_filename LOCATION_FILE (input_location)
52
#define input_filename LOCATION_FILE (input_location)
67
#define in_system_header_at(LOC) ((expand_location (LOC)).sysp != 0)
53
#define in_system_header_at(LOC) \
68
#define in_system_header (in_system_header_at (input_location))
54
  ((linemap_location_in_system_header_p (line_table, LOC)))
55
#define in_system_header  (in_system_header_at (input_location))
69
56
70
#endif
57
#endif
(-)a/gcc/testsuite/gcc.dg/assign-warn-1.c (-1 / +5 lines)
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 (+21 lines)
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 (+4 lines)
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 (+26 lines)
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 (+4 lines)
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 (+5 lines)
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 (+4 lines)
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 (+5 lines)
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 (+11 lines)
Lines 44-46 void f () Link Here
44
44
45
slashstar starslash /* { dg-error "parse error|syntax error|expected" "not a comment" } */
45
slashstar starslash /* { dg-error "parse error|syntax error|expected" "not a comment" } */
46
/* { dg-error "does not give" "paste warning(s)" { target *-*-* } 45 } */
46
/* { dg-error "does not give" "paste warning(s)" { target *-*-* } 45 } */
47
48
/* The messages below are preambles of error messages emitted when expanding
49
   macros HASH in g1 and HASHDEFINE in g2.
50
   They doesn't have any line number associated because they are part of the
51
   "module" information: They have the form:
52
   While expanding macro foo at file.c:2:10
53
   This is similar to the test for " syshdr.c in t*/
54
/* { dg-message "expanding macro HASH at \[^\\n\\r\]*direct2.c:9:14" "While expanding macro HASH"  { target *-*-* } 0 } */
55
/* { dg-message "expanding macro HASHDEFINE at \[^\\n\\r\]*direct2.c:10:20" "While expanding macro HASHDEFINE"  { target *-*-* } 0 } */
56
/* { dg-message "expanding macro HASHINCLUDE at \[^\\n\\r\]*direct2.c:11:21" "While expanding macro HASHINCLUDE"  { target *-*-* } 0 } */
57
(-)a/gcc/testsuite/gcc.dg/debug/dwarf2/pr41445-5.c (-1 / +1 lines)
Lines 9-14 Link Here
9
#define B , varj
9
#define B , varj
10
int A(B) ;
10
int A(B) ;
11
11
12
/* { dg-final { scan-assembler "DW_TAG_variable\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\"vari\[^\\r\\n\]*DW_AT_name(\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*DW_AT_)*\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\[^0-9a-fA-FxX](0x)?7\[^0-9a-fA-FxX]\[^\\r\\n\]*DW_AT_decl_line" } } */
12
/* { dg-final { scan-assembler "DW_TAG_variable\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\"vari\[^\\r\\n\]*DW_AT_name(\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*DW_AT_)*\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\[^0-9a-fA-FxX](0xa|10)\[^0-9a-fA-FxX]\[^\\r\\n\]*DW_AT_decl_line" } } */
13
/* { dg-final { scan-assembler "DW_TAG_variable\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\"varj\[^\\r\\n\]*DW_AT_name(\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*DW_AT_)*\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\[^0-9a-fA-FxX](0xa|10)\[^0-9a-fA-FxX]\[^\\r\\n\]*DW_AT_decl_line" } } */
13
/* { dg-final { scan-assembler "DW_TAG_variable\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\"varj\[^\\r\\n\]*DW_AT_name(\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*DW_AT_)*\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\[^0-9a-fA-FxX](0xa|10)\[^0-9a-fA-FxX]\[^\\r\\n\]*DW_AT_decl_line" } } */
14
/* { dg-final { cleanup-saved-temps } } */
14
/* { dg-final { cleanup-saved-temps } } */
(-)a/gcc/testsuite/gcc.dg/debug/dwarf2/pr41445-6.c (-1 / +1 lines)
Lines 4-8 Link Here
4
4
5
#include "pr41445-5.c"
5
#include "pr41445-5.c"
6
6
7
/* { dg-final { scan-assembler "DW_TAG_variable\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\"vari\[^\\r\\n\]*DW_AT_name(\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*DW_AT_)*\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\[^0-9a-fA-FxX](0x)?7\[^0-9a-fA-FxX]\[^\\r\\n\]*DW_AT_decl_line" } } */
7
/* { dg-final { scan-assembler "DW_TAG_variable\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\"vari\[^\\r\\n\]*DW_AT_name(\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*DW_AT_)*\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\[^0-9a-fA-FxX](0xa|10)\[^0-9a-fA-FxX]\[^\\r\\n\]*DW_AT_decl_line" } } */
8
/* { dg-final { scan-assembler "DW_TAG_variable\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\"varj\[^\\r\\n\]*DW_AT_name(\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*DW_AT_)*\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\[^0-9a-fA-FxX](0xa|10)\[^0-9a-fA-FxX]\[^\\r\\n\]*DW_AT_decl_line" } } */
8
/* { dg-final { scan-assembler "DW_TAG_variable\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\"varj\[^\\r\\n\]*DW_AT_name(\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*DW_AT_)*\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\[^0-9a-fA-FxX](0xa|10)\[^0-9a-fA-FxX]\[^\\r\\n\]*DW_AT_decl_line" } } */
(-)a/gcc/testsuite/gcc.dg/dfp/composite-type.c (+9 lines)
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 (+18 lines)
Lines 61-63 void operator_notfor_decimal() Link Here
61
  DECIMAL_BITWISE_OPERATOR(^,d64); /* { dg-error "invalid operands to binary" } */
61
  DECIMAL_BITWISE_OPERATOR(^,d64); /* { dg-error "invalid operands to binary" } */
62
  DECIMAL_BITWISE_OPERATOR(^,d128); /* { dg-error "invalid operands to binary" } */
62
  DECIMAL_BITWISE_OPERATOR(^,d128); /* { dg-error "invalid operands to binary" } */
63
}
63
}
64
65
/*
66
67
{ dg-message "expanding macro OPERATE at \[^\\n\\r\]*operator-bitwise.c:12:9" "While expanding macro OPERATE"  { target *-*-* } 0 }
68
69
{ dg-message "expanding macro DECIMAL_BITWISE_OPERATOR at \[^\\n\\r\]*operator-bitwise.c:20:14" "While expanding macro DECIMAL_BITWISE_OPERATOR"  { target *-*-* } 0 }
70
71
{ dg-message "expanding macro DECIMAL_BITWISE_OPERATOR at \[^\\n\\r\]*operator-bitwise.c:21:14" "While expanding macro DECIMAL_BITWISE_OPERATOR"  { target *-*-* } 0 }
72
73
{ dg-message "expanding macro DECIMAL_BITWISE_OPERATOR at \[^\\n\\r\]*operator-bitwise.c:22:14" "While expanding macro DECIMAL_BITWISE_OPERATOR"  { target *-*-* } 0 }
74
75
{ dg-message "expanding macro DECIMAL_BITWISE_OPERATOR at \[^\\n\\r\]*operator-bitwise.c:23:11" "While expanding macro DECIMAL_BITWISE_OPERATOR"  { target *-*-* } 0 }
76
77
{ dg-message "expanding macro DECIMAL_BITWISE_OPERATOR at \[^\\n\\r\]*operator-bitwise.c:24:11" "While expanding macro DECIMAL_BITWISE_OPERATOR"  { target *-*-* } 0 }
78
79
{ dg-message "expanding macro DECIMAL_BITWISE_OPERATOR at \[^\\n\\r\]*operator-bitwise.c:25:14" "While expanding macro DECIMAL_BITWISE_OPERATOR"  { target *-*-* } 0 }
80
81
*/
(-)a/gcc/testsuite/gcc.dg/uninit-6-O0.c (+4 lines)
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 2461-2463 toplev_main (int argc, char **argv) Link Here
2461
2461
2462
  return (SUCCESS_EXIT_CODE);
2462
  return (SUCCESS_EXIT_CODE);
2463
}
2463
}
2464
(-)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 / +4 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;
391
395
392
  /* Print column number in error messages.  */
396
  /* Print column number in error messages.  */
393
  unsigned char show_column;
397
  unsigned char show_column;
Lines 726-733 extern void cpp_register_deferred_pragma (cpp_reader *, const char *, Link Here
726
extern int cpp_avoid_paste (cpp_reader *, const cpp_token *,
730
extern int cpp_avoid_paste (cpp_reader *, const cpp_token *,
727
			    const cpp_token *);
731
			    const cpp_token *);
728
extern const cpp_token *cpp_get_token (cpp_reader *);
732
extern const cpp_token *cpp_get_token (cpp_reader *);
729
extern const cpp_token *cpp_get_token_with_location (cpp_reader *,
730
						     source_location *);
731
extern const unsigned char *cpp_macro_definition (cpp_reader *,
733
extern const unsigned char *cpp_macro_definition (cpp_reader *,
732
						  const cpp_hashnode *);
734
						  const cpp_hashnode *);
733
extern void _cpp_backup_tokens (cpp_reader *, unsigned int);
735
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 575-581 cpp_read_main_file (cpp_reader *pfile, const char *fname) Link Here
575
  if (CPP_OPTION (pfile, preprocessed))
575
  if (CPP_OPTION (pfile, preprocessed))
576
    {
576
    {
577
      read_original_filename (pfile);
577
      read_original_filename (pfile);
578
      fname = pfile->line_table->maps[pfile->line_table->used-1].to_file;
578
      fname = pfile->line_table->maps[pfile->line_table->used-1].d.ordinary.to_file;
579
    }
579
    }
580
  return fname;
580
  return fname;
581
}
581
}
(-)a/libcpp/internal.h (-8 lines)
Lines 351-364 struct cpp_reader Link Here
351
  /* Token generated while handling a directive, if any. */
351
  /* Token generated while handling a directive, if any. */
352
  cpp_token directive_result;
352
  cpp_token directive_result;
353
353
354
  /* When expanding a macro at top-level, this is the location of the
355
     macro invocation.  */
356
  source_location invocation_location;
357
358
  /* True if this call to cpp_get_token should consider setting
359
     invocation_location.  */
360
  bool set_invocation_location;
361
362
  /* Search paths for include files.  */
354
  /* Search paths for include files.  */
363
  struct cpp_dir *quote_include;	/* "" */
355
  struct cpp_dir *quote_include;	/* "" */
364
  struct cpp_dir *bracket_include;	/* <> */
356
  struct cpp_dir *bracket_include;	/* <> */
(-)a/libcpp/line-map.c (-58 / +636 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.  */
273
490
274
const struct line_map *
491
const struct line_map *
275
linemap_lookup (struct line_maps *set, source_location line)
492
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;
494
  unsigned int md, mn, mx;
278
  const struct line_map *cached;
495
  const struct line_map *cached;
279
496
497
  linemap_assert (set != NULL
498
		  && set->maps != NULL
499
		  && line >= RESERVED_LOCATION_COUNT);
500
280
  mn = set->cache;
501
  mn = set->cache;
281
  mx = set->used;
502
  mx = set->used;
282
  
503
  
Lines 306-311 linemap_lookup (struct line_maps *set, source_location line) Link Here
306
  return &set->maps[mn];
527
  return &set->maps[mn];
307
}
528
}
308
529
530
/* Return TRUE if MAP encodes locations coming from a macro
531
   replacement-list at macro expansion point.  */
532
533
bool
534
linemap_macro_expansion_map_p (const struct line_map *map)
535
{
536
  if (!map)
537
    return false;
538
  return (map->reason == LC_ENTER_MACRO);
539
}
540
541
/* Assert that MAP encodes locations of tokens that are not part of the
542
   replacement-list of a macro expansion.  */
543
544
int
545
linemap_check_ordinary (const struct line_map *map)
546
{
547
  linemap_assert (!linemap_macro_expansion_map_p (map));
548
  /* Return any old value.  */
549
  return 0;
550
}
551
552
/* If LOCATION is the locus of a token in a replacement-list of a
553
   macro expansion return the location of the macro expansion point.
554
555
   Read the comments of struct line_map and struct line_map_macro in
556
   line-map.h to understand what a macro expansion point is.  */
557
558
source_location
559
linemap_macro_map_loc_to_exp_point (const struct line_map *map,
560
				    source_location location)
561
{
562
  linemap_assert (linemap_macro_expansion_map_p (map)
563
		  && location >= map->start_location);
564
565
  location = location - map->start_location;
566
  linemap_assert (location < map->d.macro.n_tokens);
567
  return map->d.macro.expansion;
568
}
569
570
/* If LOCATION is the locus of a token in a replacement-list of a
571
   macro expansion return the location of said token in the
572
   definition of the macro.
573
574
   Read the comments of struct line_map and struct line_map_macro
575
   in line-map.h to understand what a macro expansion point is.
576
577
   If RETURN_MACRO_PARM_USAGE_POINT_P is TRUE and if LOCATION is the
578
   locus of a token that is an argument of a macro M, this function
579
   returns the locus of the parameter replaced by the argument, in the
580
   definition of M. This is the yI in the comments of struct
581
   line_map_macro in line-map.h.
582
583
   Note that if the token is a builtin the function returns the
584
   location of the expansion point of the macro.  */
585
586
source_location
587
linemap_macro_map_loc_to_def_point (const struct line_map *map,
588
				    source_location location,
589
				    bool return_macro_parm_usage_point_p)
590
{
591
  linemap_assert (linemap_macro_expansion_map_p (map)
592
		  && location >= map->start_location);
593
594
  location = location - map->start_location;
595
  linemap_assert (location < map->d.macro.n_tokens);
596
597
  if (return_macro_parm_usage_point_p)
598
    location = map->d.macro.macro_locations[2 * location + 1];
599
  else
600
    location = map->d.macro.macro_locations[2 * location];
601
602
  if (location >= RESERVED_LOCATION_COUNT)
603
    return location;
604
  else
605
    /* If LOCATION is reserved for the user of libcpp, it means,
606
     e.g. for gcc that it's the location of a built-in token. In that
607
     case, let's say that the final location is the macro expansion
608
     point because otherwise, the built-in location would not make
609
     any sense and would violate the invariant that says that every
610
     single location must be >= to the MAP->start_location of its
611
     map.  */
612
    return map->d.macro.expansion;
613
}
614
615
616
/* If LOCATION is the source location of a token that belongs to a
617
   macro replacement-list -- at a macro expansion point-- then
618
   return the location of the topmost expansion point of the macro.
619
   We say topmost because if we are in the context of a nested macro
620
   expansion, the function returns the source location of the first
621
   macro expansion that triggered the nested expansions.
622
623
   Otherwise, return LOCATION.  SET is the set of maps location come
624
   from.  ORIGINAL_MAP is an output parm. If non NULL, the function
625
   sets *ORIGINAL_MAP to the ordinary (non-macro) map the returned
626
   location comes from.  */
627
628
source_location
629
linemap_macro_loc_to_exp_point (struct line_maps *set,
630
				source_location location,
631
				const struct line_map **original_map)
632
{
633
  struct line_map *map;
634
635
  linemap_assert (set && location >= RESERVED_LOCATION_COUNT);
636
637
  while (true)
638
    {
639
      map = (struct line_map*) linemap_lookup (set, location);
640
      if (!linemap_macro_expansion_map_p (map))
641
	break;
642
      location = linemap_macro_map_loc_to_exp_point (map, location);
643
    }
644
645
  if (original_map)
646
    *original_map = map;
647
  return location;
648
}
649
650
/* If LOCATION is the source location of a token that belongs to a
651
   macro replacement-list -- as part of a macro expansion -- then
652
   return the location of the token at the definition point of the
653
   macro. Otherwise, return LOCATION.  SET is the set of maps location
654
   come from.  ORIGINAL_MAP is an output parm. If non NULL, the
655
   function sets *ORIGINAL_MAP to the ordinary (non-macro) map
656
   the returned location comes from.  */
657
658
source_location
659
linemap_macro_loc_to_def_point (struct line_maps *set,
660
				source_location location,
661
				const struct line_map **original_map,
662
				bool return_macro_parm_usage_point_p)
663
{
664
  struct line_map *map;
665
666
  linemap_assert (set && location >= RESERVED_LOCATION_COUNT);
667
668
  while (true)
669
    {
670
      map = (struct line_map*) linemap_lookup (set, location);
671
      if (!linemap_macro_expansion_map_p (map))
672
	break;
673
      location = linemap_macro_map_loc_to_def_point (map, location,
674
						     return_macro_parm_usage_point_p);
675
    }
676
677
  if (original_map)
678
    *original_map = map;
679
  return location;
680
}
681
682
/* Return the source line number corresponding to source location
683
   LOCATION.  SET is the line map set LOCATION comes from.  If
684
   LOCATION is the source location of token that is part of the
685
   replacement-list of a macro expansion return the line number of the
686
   macro expansion point.  */
687
688
int
689
linemap_get_source_line (struct line_maps *set,
690
			 source_location location)
691
{
692
  const struct line_map *map = NULL;
693
694
  if (location < RESERVED_LOCATION_COUNT)
695
    return 0;
696
697
  location =
698
    linemap_macro_loc_to_exp_point (set, location, &map);
699
  linemap_check_ordinary (map);
700
701
  return ((location - map->start_location)
702
	    >> map->d.ordinary.column_bits)
703
	 + map->d.ordinary.to_line;
704
}
705
706
/* Return the column number corresponding to location LOCATION.
707
708
   If LOCATION is the source location of token that is part of the
709
   replacement-list of a macro expansion return the column number of
710
   the macro expansion point.
711
712
   SET is the line map set LOCATION comes from.  */
713
714
int
715
linemap_get_source_column (struct line_maps *set,
716
			   source_location location)
717
{
718
  const struct line_map *map = NULL;
719
720
  if (location < RESERVED_LOCATION_COUNT)
721
    return 0;
722
723
  location =
724
    linemap_macro_loc_to_exp_point (set, location, &map);
725
  linemap_check_ordinary (map);
726
727
  return (location - map->start_location)
728
	  & ((1 << map->d.ordinary.column_bits) - 1);
729
}
730
731
/* Return the path of the file corresponding to source code location
732
   LOCATION.
733
734
   If LOCATION is the source location of token that is part of the
735
   replacement-list of a macro expansion return the file path of the
736
   macro expansion point.
737
738
   SET is the line map set LOCATION comes from.  */
739
740
const char*
741
linemap_get_file_path (struct line_maps *set,
742
		       source_location location)
743
{
744
  const struct line_map *map = NULL;
745
746
  if (location < RESERVED_LOCATION_COUNT)
747
    return NULL;
748
749
  location =
750
    linemap_macro_loc_to_exp_point (set, location, &map);
751
  linemap_check_ordinary (map);
752
  return LINEMAP_FILE (map);
753
}
754
755
/* Return the name of the macro associated to MACRO_MAP.  */
756
757
const char*
758
linemap_map_get_macro_name (const struct line_map* macro_map)
759
{
760
  linemap_assert (macro_map && linemap_macro_expansion_map_p (macro_map));
761
  return (const char*) NODE_NAME ((macro_map)->d.macro.macro->name);
762
}
763
764
/* Return TRUE if LOCATION is the locus of a token is located in a system
765
   header, FALSE otherwise.
766
767
   Note that this function returns FALSE if LOCATION belongs to a
768
   token that is part of a macro replacement-list defined in a system
769
   header, but expanded in a non-system file.  */
770
771
bool
772
linemap_location_in_system_header_p (struct line_maps *set,
773
				     source_location location)
774
{
775
  const struct line_map *map = NULL;
776
777
  if (location < RESERVED_LOCATION_COUNT)
778
    return false;
779
780
  location =
781
    linemap_macro_loc_to_exp_point (set, location, &map);
782
  linemap_check_ordinary (map);
783
  return LINEMAP_SYSP (map);
784
}
785
786
/* Return TRUE if LOCATION is the locus of a token that comes from a
787
   system header, FALSE otherwise.
788
789
   Note that this function returns TRUE if LOCATION belongs to a
790
   token that is part of a macro replacement-list defined in a system
791
   header, but expanded in a non-system file.  */
792
793
bool
794
linemap_location_originated_from_system_header_p (struct line_maps *set,
795
						  source_location location)
796
{
797
  const struct line_map *map = NULL;
798
799
  if (location < RESERVED_LOCATION_COUNT)
800
    return false;
801
802
  location =
803
    linemap_macro_loc_to_def_point (set, location, &map, false);
804
  linemap_check_ordinary (map);
805
  return LINEMAP_SYSP (map);
806
}
807
808
/* Return TRUE if LOCATION is a source code location of a token
809
   coming from a macro replacement-list at a macro expansion point,
810
   FALSE otherwise.  */
811
812
bool
813
linemap_location_from_macro_expansion_p (struct line_maps *set,
814
					 source_location location)
815
{
816
  const struct line_map *map;
817
818
  if (location < RESERVED_LOCATION_COUNT)
819
    return false;
820
821
  map = linemap_lookup (set, location);
822
  return linemap_macro_expansion_map_p (map);
823
}
824
309
/* Print an include trace, for e.g. the -H option of the preprocessor.  */
825
/* Print an include trace, for e.g. the -H option of the preprocessor.  */
310
826
311
static void
827
static void
Lines 315-319 trace_include (const struct line_maps *set, const struct line_map *map) Link Here
315
831
316
  while (--i)
832
  while (--i)
317
    putc ('.', stderr);
833
    putc ('.', stderr);
318
  fprintf (stderr, " %s\n", map->to_file);
834
  linemap_check_ordinary (map);
835
  fprintf (stderr, " %s\n", map->d.ordinary.to_file);
836
}
837
838
/* Expand source code location LOC and return user readable source
839
   code location. If TO_MACRO_DEF_LOC_P is TRUE and LOC is a
840
   location of a token inside a macro replacement-list at an expansion
841
   point, the function expands the location to the source locus of
842
   the token in the relevant macro definition.  */
843
844
expanded_location
845
linemap_expand_location_full (struct line_maps *set,
846
			      source_location loc,
847
			      bool to_macro_def_loc_p,
848
			      const struct line_map **loc_map)
849
{
850
  const struct line_map *map;
851
  expanded_location xloc;
852
853
  linemap_assert (set && loc >= RESERVED_LOCATION_COUNT);
854
855
  loc = (to_macro_def_loc_p)
856
    ? linemap_macro_loc_to_def_point (set, loc, &map, true)
857
    : linemap_macro_loc_to_exp_point (set, loc, &map);      
858
  xloc.file = LINEMAP_FILE (map);
859
  xloc.line = SOURCE_LINE (map, loc);
860
  xloc.column = SOURCE_COLUMN (map, loc);
861
  xloc.sysp = LINEMAP_SYSP (map) != 0;
862
  if (loc_map)
863
    *loc_map = map;
864
865
  return xloc;
866
}
867
868
/* Dump debugging information about source location LOC into the file
869
   stream STREAM. SET is the line map set LOC comes from.  */
870
871
void
872
linemap_dump_location (struct line_maps *set,
873
		       source_location loc,
874
		       FILE *stream)
875
{
876
  const struct line_map *map;
877
  source_location location;
878
  const char *p;
879
  int l,c,s,e;
880
881
  if (loc == 0)
882
    return;
883
884
  location =
885
    linemap_macro_loc_to_def_point (set, loc, &map, true);
886
  p = LINEMAP_FILE (map);
887
888
  l = SOURCE_LINE (map, location);
889
  c = SOURCE_COLUMN (map, location);
890
  s = LINEMAP_SYSP (map) != 0;
891
  e = (location != loc);
892
  
893
  /* P: path, L: line, C: column, S: in-system-header, M: map address,
894
     E: macro expansion?.   */
895
  fprintf (stream, "{P:%s;L:%d;C:%d;S:%d;M:%p;E:%d,LOC:%d}",
896
	   p, l, c, s, (void*)map, e, loc);
319
}
897
}
(-)a/libcpp/macro.c (-60 / +100 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
	  unsigned int i, count = macro_real_token_count (macro);
905
	  _cpp_buff *buff = _cpp_get_buff (pfile,
906
					   count * sizeof (cpp_token));
907
	  const cpp_token *src = macro->exp.tokens;
908
	  cpp_token *first = (cpp_token *) buff->base;
909
	  cpp_token *dest = first;
910
	  /* Create a macro map to record the locations of the tokens
911
	     that are involved in the expansion. Note that the
912
	     expansion point is set to the location closing
913
	     parenthesis. Otherwise, the subsequent map created for
914
	     the first token that comes after the macro map might have
915
	     a wrong line number. What would lead to tokens having
916
	     with wrong line numbers after the macro expansion.  */
917
	  const struct line_map *map
918
	    = linemap_enter_macro (pfile->line_table, macro,
919
				   paren_loc, count);
920
	  for (i = 0; i < count; ++i)
921
	    {
922
	      *dest = *src;
923
	      dest->src_loc = linemap_add_macro_token (map, i,
924
						       dest->src_loc,
925
						       dest->src_loc);
926
	      ++dest;
927
	      ++src;
928
	    }
929
	  linemap_leave_macro (pfile->line_table, paren_loc);
930
	  /* FIXME freeing  */
931
	  _cpp_push_token_context (pfile, node, first, count);
932
	}
896
933
897
      if (pragma_buff)
934
      if (pragma_buff)
898
	{
935
	{
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
962
   Expand each argument before replacing, unless it is operated upon
926
   by the # or ## operators.  */
963
   by the # or ## operators.  */
927
static void
964
static void
928
replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, macro_arg *args)
965
replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro,
966
	      macro_arg *args, source_location macro_loc,
967
	      source_location paren_loc)
929
{
968
{
930
  unsigned int i, total;
969
  unsigned int i, total;
931
  const cpp_token *src, *limit;
970
  const cpp_token *src, *limit;
932
  const cpp_token **dest, **first;
971
  cpp_token *dest, *first;
933
  macro_arg *arg;
972
  macro_arg *arg;
934
  _cpp_buff *buff;
973
  _cpp_buff *buff;
935
  unsigned int count;
974
  unsigned int count;
975
  const struct line_map *map;
936
976
937
  /* First, fully macro-expand arguments, calculating the number of
977
  /* First, fully macro-expand arguments, calculating the number of
938
     tokens in the final expansion as we go.  The ordering of the if
978
     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
1010
971
  /* Now allocate space for the expansion, copy the tokens and replace
1011
  /* Now allocate space for the expansion, copy the tokens and replace
972
     the arguments.  */
1012
     the arguments.  */
973
  buff = _cpp_get_buff (pfile, total * sizeof (cpp_token *));
1013
  buff = _cpp_get_buff (pfile, total * sizeof (cpp_token));
974
  first = (const cpp_token **) buff->base;
1014
  first = (cpp_token *) buff->base;
975
  dest = first;
1015
  dest = first;
976
1016
  macro_loc = macro_loc;
977
  for (src = macro->exp.tokens; src < limit; src++)
1017
  /* Create a macro map to record the locations of the tokens that are
1018
     involved in the expansion. Note that the expansion point
1019
     is set to the location closing parenthesis. Otherwise,
1020
     the subsequent map created for the first token that comes
1021
     after the macro map might have a wrong line number. What
1022
     would lead to tokens having with wrong line numbers after
1023
     the macro expansion.  */
1024
  map = linemap_enter_macro (pfile->line_table, macro, paren_loc, total);
1025
  i = 0;
1026
  for (src = macro->exp.tokens; src < limit; src++, i++)
978
    {
1027
    {
979
      unsigned int count;
1028
      unsigned int count;
980
      const cpp_token **from, **paste_flag;
1029
      const cpp_token **from;
1030
      cpp_token *paste_flag;
981
1031
982
      if (src->type != CPP_MACRO_ARG)
1032
      if (src->type != CPP_MACRO_ARG)
983
	{
1033
	{
984
	  *dest++ = src;
1034
	  *dest = *src;
1035
	  dest->src_loc = linemap_add_macro_token (map, i, dest->src_loc,
1036
						   dest->src_loc);
1037
	  ++dest;
985
	  continue;
1038
	  continue;
986
	}
1039
	}
987
1040
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;
1049
	  count = arg->count, from = arg->first;
997
	  if (dest != first)
1050
	  if (dest != first)
998
	    {
1051
	    {
999
	      if (dest[-1]->type == CPP_COMMA
1052
	      if (dest[-1].type == CPP_COMMA
1000
		  && macro->variadic
1053
		  && macro->variadic
1001
		  && src->val.macro_arg.arg_no == macro->paramc)
1054
		  && src->val.macro_arg.arg_no == macro->paramc)
1002
		{
1055
		{
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 ##).  */
1071
      /* Padding on the left of an argument (unless RHS of ##).  */
1019
      if ((!pfile->state.in_directive || pfile->state.directive_wants_padding)
1072
      if ((!pfile->state.in_directive || pfile->state.directive_wants_padding)
1020
	  && src != macro->exp.tokens && !(src[-1].flags & PASTE_LEFT))
1073
	  && src != macro->exp.tokens && !(src[-1].flags & PASTE_LEFT))
1021
	*dest++ = padding_token (pfile, src);
1074
	{
1075
	  *dest = *padding_token (pfile, src);
1076
	  dest->src_loc = linemap_add_macro_token (map, i, dest->src_loc,
1077
						   dest->src_loc);
1078
	  ++dest;
1079
	}
1022
1080
1023
      if (count)
1081
      if (count)
1024
	{
1082
	{
1025
	  memcpy (dest, from, count * sizeof (cpp_token *));
1083
	  unsigned int j;
1026
	  dest += count;
1084
	  for (j = 0; j < count; ++j)
1085
	    {
1086
	      *dest = *from[j];
1087
	      dest->src_loc = linemap_add_macro_token (map, i, dest->src_loc,
1088
						       src->src_loc);
1089
	      ++dest;
1090
	    }
1027
1091
1028
	  /* With a non-empty argument on the LHS of ##, the last
1092
	  /* With a non-empty argument on the LHS of ##, the last
1029
	     token should be flagged PASTE_LEFT.  */
1093
	     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
1108
1045
      /* Avoid paste on RHS (even case count == 0).  */
1109
      /* Avoid paste on RHS (even case count == 0).  */
1046
      if (!pfile->state.in_directive && !(src->flags & PASTE_LEFT))
1110
      if (!pfile->state.in_directive && !(src->flags & PASTE_LEFT))
1047
	*dest++ = &pfile->avoid_paste;
1111
	{
1112
	  *dest = pfile->avoid_paste;
1113
	  /* Don't bother changing the location here.  */
1114
	  ++dest;
1115
	}
1048
1116
1049
      /* Add a new paste flag, or remove an unwanted one.  */
1117
      /* Add a new paste flag, or remove an unwanted one.  */
1050
      if (paste_flag)
1118
      if (paste_flag)
1051
	{
1119
	{
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)
1120
	  if (src->flags & PASTE_LEFT)
1056
	    token->flags = (*paste_flag)->flags | PASTE_LEFT;
1121
	    paste_flag->flags |= PASTE_LEFT;
1057
	  else
1122
	  else
1058
	    token->flags = (*paste_flag)->flags & ~PASTE_LEFT;
1123
	    paste_flag->flags &= ~PASTE_LEFT;
1059
	  *paste_flag = token;
1060
	}
1124
	}
1061
    }
1125
    }
1126
  linemap_leave_macro (pfile->line_table, paren_loc);
1062
1127
1063
  /* Free the expanded arguments.  */
1128
  /* Free the expanded arguments.  */
1064
  for (i = 0; i < macro->paramc; i++)
1129
  for (i = 0; i < macro->paramc; i++)
1065
    if (args[i].expanded)
1130
    if (args[i].expanded)
1066
      free (args[i].expanded);
1131
      free (args[i].expanded);
1067
1132
1068
  push_ptoken_context (pfile, node, buff, first, dest - first);
1133
  /* FIXME: doesn't handle BUFF */
1134
  _cpp_push_token_context (pfile, node, first, dest - first);
1069
}
1135
}
1070
1136
1071
/* Return a special padding token, with padding inherited from SOURCE.  */
1137
/* Return a special padding token, with padding inherited from SOURCE.  */
Lines 1225-1232 const cpp_token * Link Here
1225
cpp_get_token (cpp_reader *pfile)
1291
cpp_get_token (cpp_reader *pfile)
1226
{
1292
{
1227
  const cpp_token *result;
1293
  const cpp_token *result;
1228
  bool can_set = pfile->set_invocation_location;
1229
  pfile->set_invocation_location = false;
1230
1294
1231
  for (;;)
1295
  for (;;)
1232
    {
1296
    {
Lines 1273-1282 cpp_get_token (cpp_reader *pfile) Link Here
1273
      if (!(node->flags & NODE_DISABLED))
1337
      if (!(node->flags & NODE_DISABLED))
1274
	{
1338
	{
1275
	  int ret = 0;
1339
	  int ret = 0;
1276
	  /* If not in a macro context, and we're going to start an
1277
	     expansion, record the location.  */
1278
	  if (can_set && !context->macro)
1279
	    pfile->invocation_location = result->src_loc;
1280
	  if (pfile->state.prevent_expansion)
1340
	  if (pfile->state.prevent_expansion)
1281
	    break;
1341
	    break;
1282
1342
Lines 1335-1361 cpp_get_token (cpp_reader *pfile) Link Here
1335
  return result;
1395
  return result;
1336
}
1396
}
1337
1397
1338
/* Like cpp_get_token, but also returns a location separate from the
1339
   one provided by the returned token.  LOC is an out parameter; *LOC
1340
   is set to the location "as expected by the user".  This matters
1341
   when a token results from macro expansion -- the token's location
1342
   will indicate where the macro is defined, but *LOC will be the
1343
   location of the start of the expansion.  */
1344
const cpp_token *
1345
cpp_get_token_with_location (cpp_reader *pfile, source_location *loc)
1346
{
1347
  const cpp_token *result;
1348
1349
  pfile->set_invocation_location = true;
1350
  result = cpp_get_token (pfile);
1351
  if (pfile->context->macro)
1352
    *loc = pfile->invocation_location;
1353
  else
1354
    *loc = result->src_loc;
1355
1356
  return result;
1357
}
1358
1359
/* Returns true if we're expanding an object-like macro that was
1398
/* Returns true if we're expanding an object-like macro that was
1360
   defined in a system header.  Just checks the macro at the top of
1399
   defined in a system header.  Just checks the macro at the top of
1361
   the stack.  Used for diagnostic suppression.  */
1400
   the stack.  Used for diagnostic suppression.  */
Lines 1851-1856 _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node) Link Here
1851
      (sizeof (cpp_macro));
1890
      (sizeof (cpp_macro));
1852
  else
1891
  else
1853
    macro = (cpp_macro *) _cpp_aligned_alloc (pfile, sizeof (cpp_macro));
1892
    macro = (cpp_macro *) _cpp_aligned_alloc (pfile, sizeof (cpp_macro));
1893
  macro->name = node;
1854
  macro->line = pfile->directive_line;
1894
  macro->line = pfile->directive_line;
1855
  macro->params = 0;
1895
  macro->params = 0;
1856
  macro->paramc = 0;
1896
  macro->paramc = 0;

Return to bug 7263