This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch: make --enable-mapped-location work
- From: Tom Tromey <tromey at redhat dot com>
- To: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Cc: fortran at gcc dot gnu dot org
- Date: Fri, 31 Aug 2007 08:26:48 -0600
- Subject: Patch: make --enable-mapped-location work
- Reply-to: Tom Tromey <tromey at redhat dot com>
This patch supercedes my previous mapped location patch.
This updates the mapped location code for the C and C++ front ends.
Now --enable-mapped-location will bootstrap and pass regression tests
for those languages.
There's a fortran patch included as well, but there are still some
fortran regressions. I looked into these a bit but I think it may be
more efficient for someone more familiar with the fortran front end to
fix the problems.
The bulk of the change is because I changed line_table to be a
pointer, so that the PCH machinery could save its contents.
The only other tricky part for PCH is that we have to restore the
current location after reading the PCH file.
Note also that I added a new libcpp API. This is inelegant but was
the only way I could think of to avoid one major cause of regressions,
namely errors being reported at the wrong point. E.g., consider:
#define foo bar
int x (void) { return foo; }
With the old API in place the error would be reported for the token
'bar', whose location would be reported as line 1. However, this is
unhelpful to users, who (rightly, IMO) expect the error to be reported
at line 2.
The tree-cfg.c change appears to be what was intended, given the
comment in cp/decl.c and similar code in
remove_useless_stmts_warn_notreached. (This change was required to
fix a regression.)
Bootstrapped and regtested with and without --enable-mapped-location
on x86 FC6.
Ok?
I think it would be worthwhile to discuss when
--enable-mapped-location should be made the default. It is not quite
ready (in addition to fortran, Ada must be converted, and there is a
possible Java regression). However, it is reasonably close.
Tom
libcpp/ChangeLog:
2007-08-30 Tom Tromey <tromey@redhat.com>
* internal.h (struct cpp_reader) <invocation_location>: New
field.
(struct cpp_reader) <set_invocation_location>: Likewise.
* init.c (cpp_set_line_map): New function.
* line-map.c (linemap_add): Use linemap's allocator.
* include/line-map.h (GTY): Define.
(line_map_realloc): New typedef.
(struct line_map): Mark with GTY.
(struct line_maps): Likewise.
(struct line_maps) <maps>: Likewise.
(struct line_maps) <reallocator>: New field.
* include/symtab.h (GTY): Conditionally define.
* include/cpplib.h (cpp_set_line_map): Declare.
(cpp_get_token_with_location): Declare.
* macro.c (cpp_get_token): Set invocation_location on the reader.
(cpp_get_token_with_location): New function.
gcc/java/ChangeLog:
2007-08-28 Tom Tromey <tromey@redhat.com>
* lang.c (java_post_options): Update.
* jcf-parse.c (set_source_filename): Update.
(give_name_to_class): Update.
(jcf_parse): Update.
(duplicate_class_warning): Update.
(parse_class_file): Update.
(java_parse_file): Update.
* expr.c (expand_byte_code): Update.
gcc/ChangeLog:
2007-08-30 Tom Tromey <tromey@redhat.com>
* tree-cfg.c (remove_bb): Only warn if line is non-zero.
* c-pch.c (c_common_read_pch): Restore current location after
reading PCH file.
* tree.c (expand_location): Update.
(expr_filename): Separated USE_MAPPED_LOCATION variant.
Changed return type.
(expr_lineno): Likewise.
* toplev.c (line_table): Changed type.
(general_init): Update.
(realloc_for_line_map): New function.
(general_init): Allocate line_table using GC.
* fix-header.c (line_table): Changed type.
(read_scan_file): Update.
(read_scan_file): Update.
* c-ppoutput.c (maybe_print_line): Update.
(print_line): Update.
(cb_line_change): Update.
(cb_define): Update.
(pp_file_change): Update.
* c-opts.c (c_common_init_options): Update.
(finish_options): Update.
(push_command_line_include): Update.
* c-lex.c (cb_line_change): Update.
(cb_def_pragma): Update.
(cb_define): Update.
(cb_undef): Update.
(c_lex_with_flags): Use cpp_get_token_with_location.
* input.h (line_table): Changed type.
(location_from_locus): New macro.
* tree.h (EXPR_FILENAME): Separated USE_MAPPED_LOCATION variant.
(EXPR_LINENO): Likewise.
(expr_locus, set_expr_locus, expr_filename, expr_lineno): Declare
separately for USE_MAPPED_LOCATION.
* gimplify.c (tree_to_gimple_tuple): Use SET_EXPR_LOCUS.
* cfgexpand.c (expand_gimple_cond_expr): Use location_from_locus.
(expand_gimple_basic_block): Likewise.
* final.c (final_scan_insn): Use expanded_location.
gcc/testsuite/ChangeLog:
2007-08-30 Tom Tromey <tromey@redhat.com>
* lib/g++.exp (g++_target_compile): Use -fno-show-column.
gcc/cp/ChangeLog:
2007-08-30 Tom Tromey <tromey@redhat.com>
* decl.c (finish_function): Put return's location on line zero of
file.
gcc/fortran/ChangeLog:
2007-08-30 Tom Tromey <tromey@redhat.com>
* scanner.c (get_file): Update.
(load_file): Update.
(gfc_next_char_literal): Use gfc_linebuf_linenum.
* f95-lang.c (gfc_init): Update.
* gfortran.h (gfc_linebuf_linenum): New macro.
gcc/treelang/ChangeLog:
2007-08-30 Tom Tromey <tromey@redhat.com>
* tree1.c (treelang_init): Update.
(treelang_parse_file): Update.
(treelang_parse_file): Update.
(treelang_parse_file): Update.
* lex.l: Update.
(update_lineno_charno): Likewise.
Index: libcpp/macro.c
===================================================================
--- libcpp/macro.c (revision 127930)
+++ libcpp/macro.c (working copy)
@@ -1,7 +1,7 @@
/* Part of CPP library. (Macro and #define handling.)
Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998,
1999, 2000, 2001, 2002, 2003, 2004, 2005,
- 2006 Free Software Foundation, Inc.
+ 2006, 2007 Free Software Foundation, Inc.
Written by Per Bothner, 1994.
Based on CCCP program by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
@@ -1094,6 +1094,8 @@
cpp_get_token (cpp_reader *pfile)
{
const cpp_token *result;
+ bool can_set = pfile->set_invocation_location;
+ pfile->set_invocation_location = false;
for (;;)
{
@@ -1139,6 +1141,10 @@
if (!(node->flags & NODE_DISABLED))
{
+ /* If not in a macro context, and we're going to start an
+ expansion, record the location. */
+ if (can_set && !context->macro)
+ pfile->invocation_location = result->src_loc;
if (!pfile->state.prevent_expansion
&& enter_macro_context (pfile, node))
{
@@ -1164,6 +1170,21 @@
return result;
}
+const cpp_token *
+cpp_get_token_with_location (cpp_reader *pfile, source_location *loc)
+{
+ const cpp_token *result;
+
+ pfile->set_invocation_location = true;
+ result = cpp_get_token (pfile);
+ if (pfile->context->macro)
+ *loc = pfile->invocation_location;
+ else
+ *loc = result->src_loc;
+
+ return result;
+}
+
/* Returns true if we're expanding an object-like macro that was
defined in a system header. Just checks the macro at the top of
the stack. Used for diagnostic suppression. */
Index: libcpp/line-map.c
===================================================================
--- libcpp/line-map.c (revision 127930)
+++ libcpp/line-map.c (working copy)
@@ -1,5 +1,5 @@
/* Map logical line numbers to (source file, line number) pairs.
- Copyright (C) 2001, 2003, 2004
+ Copyright (C) 2001, 2003, 2004, 2007
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
@@ -96,8 +96,15 @@
if (set->used == set->allocated)
{
+ line_map_realloc reallocator
+ = set->reallocator ? set->reallocator : xrealloc;
set->allocated = 2 * set->allocated + 256;
- set->maps = XRESIZEVEC (struct line_map, set->maps, set->allocated);
+ set->maps
+ = (struct line_map *) (*reallocator) (set->maps,
+ set->allocated
+ * sizeof (struct line_map));
+ memset (&set->maps[set->used], 0, ((set->allocated - set->used)
+ * sizeof (struct line_map)));
}
map = &set->maps[set->used];
Index: libcpp/include/cpplib.h
===================================================================
--- libcpp/include/cpplib.h (revision 127930)
+++ libcpp/include/cpplib.h (working copy)
@@ -1,6 +1,6 @@
/* Definitions for CPP library.
Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
- 2004, 2005
+ 2004, 2005, 2007
Free Software Foundation, Inc.
Written by Per Bothner, 1994-95.
@@ -623,6 +623,10 @@
extern cpp_reader *cpp_create_reader (enum c_lang, struct ht *,
struct line_maps *);
+/* Reset the cpp_reader's line_map. This is only used after reading a
+ PCH file. */
+extern void cpp_set_line_map (cpp_reader *, struct line_maps *);
+
/* Call this to change the selected language standard (e.g. because of
command line options). */
extern void cpp_set_lang (cpp_reader *, enum c_lang);
@@ -687,6 +691,8 @@
extern int cpp_avoid_paste (cpp_reader *, const cpp_token *,
const cpp_token *);
extern const cpp_token *cpp_get_token (cpp_reader *);
+extern const cpp_token *cpp_get_token_with_location (cpp_reader *,
+ source_location *);
extern const unsigned char *cpp_macro_definition (cpp_reader *,
const cpp_hashnode *);
extern void _cpp_backup_tokens (cpp_reader *, unsigned int);
Index: libcpp/include/symtab.h
===================================================================
--- libcpp/include/symtab.h (revision 127930)
+++ libcpp/include/symtab.h (working copy)
@@ -1,5 +1,5 @@
/* Hash tables.
- Copyright (C) 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2003, 2004, 2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
@@ -19,7 +19,9 @@
#define LIBCPP_SYMTAB_H
#include "obstack.h"
+#ifndef GTY
#define GTY(x) /* nothing */
+#endif
/* This is what each hash table entry points to. It may be embedded
deeply within another object. */
Index: libcpp/include/line-map.h
===================================================================
--- libcpp/include/line-map.h (revision 127930)
+++ libcpp/include/line-map.h (working copy)
@@ -1,5 +1,5 @@
/* Map logical line numbers to (source file, line number) pairs.
- Copyright (C) 2001, 2003, 2004
+ Copyright (C) 2001, 2003, 2004, 2007
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
@@ -23,6 +23,10 @@
#ifndef LIBCPP_LINE_MAP_H
#define LIBCPP_LINE_MAP_H
+#ifndef GTY
+#define GTY(x) /* nothing */
+#endif
+
/* Reason for adding a line change with add_line_map (). LC_ENTER is
when including a new file, e.g. a #include directive in C.
LC_LEAVE is when reaching a file's end. LC_RENAME is when a file
@@ -35,6 +39,9 @@
and effectively typedef source_location location_t. */
typedef unsigned int source_location;
+/* Memory allocation function typedef. Works like xrealloc. */
+typedef void *(*line_map_realloc) (void *, size_t);
+
/* Physical source file TO_FILE at line TO_LINE at column 0 is represented
by the logical START_LOCATION. TO_LINE+L at column C is represented by
START_LOCATION+(L*(1<<column_bits))+C, as long as C<(1<<column_bits),
@@ -47,7 +54,7 @@
creation of this line map, SYSP is one for a system header, two for
a C system header file that therefore needs to be extern "C"
protected in C++, and zero otherwise. */
-struct line_map
+struct line_map GTY(())
{
const char *to_file;
unsigned int to_line;
@@ -61,9 +68,9 @@
};
/* A set of chronological line_map structures. */
-struct line_maps
+struct line_maps GTY(())
{
- struct line_map *maps;
+ struct line_map * GTY ((length ("%h.used"))) maps;
unsigned int allocated;
unsigned int used;
@@ -89,6 +96,10 @@
/* The maximum column number we can quickly allocate. Higher numbers
may require allocating a new line_map. */
unsigned int max_column_hint;
+
+ /* If non-null, the allocator to use when resizing 'maps'. If null,
+ xrealloc is used. */
+ line_map_realloc reallocator;
};
/* Initialize a line map set. */
Index: libcpp/init.c
===================================================================
--- libcpp/init.c (revision 127930)
+++ libcpp/init.c (working copy)
@@ -1,6 +1,6 @@
/* CPP Library.
Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
Contributed by Per Bothner, 1994-95.
Based on CCCP program by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
@@ -227,6 +227,12 @@
return pfile;
}
+void
+cpp_set_line_map (cpp_reader *pfile, struct line_maps *line_table)
+{
+ pfile->line_table = line_table;
+}
+
/* Free resources used by PFILE. Accessing PFILE after this function
returns leads to undefined behavior. Returns the error count. */
void
Index: libcpp/internal.h
===================================================================
--- libcpp/internal.h (revision 127930)
+++ libcpp/internal.h (working copy)
@@ -339,6 +339,14 @@
/* Token generated while handling a directive, if any. */
cpp_token directive_result;
+ /* When expanding a macro at top-level, this is the location of the
+ macro invocation. */
+ source_location invocation_location;
+
+ /* True if this call to cpp_get_token should consider setting
+ invocation_location. */
+ bool set_invocation_location;
+
/* Search paths for include files. */
struct cpp_dir *quote_include; /* "" */
struct cpp_dir *bracket_include; /* <> */
Index: gcc/java/jcf-parse.c
===================================================================
--- gcc/java/jcf-parse.c (revision 127930)
+++ gcc/java/jcf-parse.c (working copy)
@@ -365,7 +365,7 @@
sfname = find_sourcefile (sfname);
#ifdef USE_MAPPED_LOCATION
- line_table.maps[line_table.used-1].to_file = sfname;
+ line_table->maps[line_table->used-1].to_file = sfname;
#else
input_filename = sfname;
DECL_SOURCE_LOCATION (TYPE_NAME (current_class)) = input_location;
@@ -1209,8 +1209,8 @@
{
tree source_name = identifier_subst (class_name, "", '.', '/', ".java");
const char *sfname = IDENTIFIER_POINTER (source_name);
- linemap_add (&line_table, LC_ENTER, false, sfname, 0);
- input_location = linemap_line_start (&line_table, 0, 1);
+ linemap_add (line_table, LC_ENTER, false, sfname, 0);
+ input_location = linemap_line_start (line_table, 0, 1);
file_start_location = input_location;
DECL_SOURCE_LOCATION (TYPE_NAME (this_class)) = input_location;
if (main_input_filename == NULL && jcf == main_jcf)
@@ -1497,7 +1497,7 @@
annotation_write_byte (JV_DONE_ATTR);
#ifdef USE_MAPPED_LOCATION
- linemap_add (&line_table, LC_LEAVE, false, NULL, 0);
+ linemap_add (line_table, LC_LEAVE, false, NULL, 0);
#endif
/* The fields of class_type_node are already in correct order. */
@@ -1532,8 +1532,8 @@
{
location_t warn_loc;
#ifdef USE_MAPPED_LOCATION
- linemap_add (&line_table, LC_RENAME, 0, filename, 0);
- warn_loc = linemap_line_start (&line_table, 0, 1);
+ linemap_add (line_table, LC_RENAME, 0, filename, 0);
+ warn_loc = linemap_line_start (line_table, 0, 1);
#else
warn_loc.file = filename;
warn_loc.line = 0;
@@ -1650,7 +1650,7 @@
}
#ifdef USE_MAPPED_LOCATION
if (min_line != 0)
- input_location = linemap_line_start (&line_table, min_line, 1);
+ input_location = linemap_line_start (line_table, min_line, 1);
#else
if (min_line != 0)
input_line = min_line;
@@ -1926,8 +1926,8 @@
main_jcf->read_state = finput;
main_jcf->filbuf = jcf_filbuf_from_stdio;
#ifdef USE_MAPPED_LOCATION
- linemap_add (&line_table, LC_ENTER, false, filename, 0);
- input_location = linemap_line_start (&line_table, 0, 1);
+ linemap_add (line_table, LC_ENTER, false, filename, 0);
+ input_location = linemap_line_start (line_table, 0, 1);
#endif
if (open_in_zip (main_jcf, filename, NULL, 0) < 0)
fatal_error ("bad zip/jar file %s", filename);
@@ -1935,7 +1935,7 @@
/* Register all the classes defined there. */
process_zip_dir (main_jcf->read_state);
#ifdef USE_MAPPED_LOCATION
- linemap_add (&line_table, LC_LEAVE, false, NULL, 0);
+ linemap_add (line_table, LC_LEAVE, false, NULL, 0);
#endif
parse_zip_file_entries ();
}
@@ -1950,7 +1950,7 @@
java_parser_context_restore_global ();
java_pop_parser_context (1);
#ifdef USE_MAPPED_LOCATION
- linemap_add (&line_table, LC_LEAVE, false, NULL, 0);
+ linemap_add (line_table, LC_LEAVE, false, NULL, 0);
#endif
#endif
}
Index: gcc/java/expr.c
===================================================================
--- gcc/java/expr.c (revision 127930)
+++ gcc/java/expr.c (working copy)
@@ -3194,7 +3194,7 @@
{
int line = GET_u2 (linenumber_pointer - 2);
#ifdef USE_MAPPED_LOCATION
- input_location = linemap_line_start (&line_table, line, 1);
+ input_location = linemap_line_start (line_table, line, 1);
#else
input_location.line = line;
#endif
Index: gcc/java/lang.c
===================================================================
--- gcc/java/lang.c (revision 127930)
+++ gcc/java/lang.c (working copy)
@@ -653,8 +653,8 @@
}
}
#ifdef USE_MAPPED_LOCATION
- linemap_add (&line_table, LC_ENTER, false, filename, 0);
- linemap_add (&line_table, LC_RENAME, false, "<built-in>", 0);
+ linemap_add (line_table, LC_ENTER, false, filename, 0);
+ linemap_add (line_table, LC_RENAME, false, "<built-in>", 0);
#endif
/* Initialize the compiler back end. */
Index: gcc/c-lex.c
===================================================================
--- gcc/c-lex.c (revision 127930)
+++ gcc/c-lex.c (working copy)
@@ -204,7 +204,7 @@
#else
{
source_location loc = token->src_loc;
- const struct line_map *map = linemap_lookup (&line_table, loc);
+ const struct line_map *map = linemap_lookup (line_table, loc);
input_line = SOURCE_LINE (map, loc);
}
#endif
@@ -282,7 +282,7 @@
const cpp_token *s;
#ifndef USE_MAPPED_LOCATION
location_t fe_loc;
- const struct line_map *map = linemap_lookup (&line_table, loc);
+ const struct line_map *map = linemap_lookup (line_table, loc);
fe_loc.file = map->to_file;
fe_loc.line = SOURCE_LINE (map, loc);
#else
@@ -308,7 +308,7 @@
static void
cb_define (cpp_reader *pfile, source_location loc, cpp_hashnode *node)
{
- const struct line_map *map = linemap_lookup (&line_table, loc);
+ const struct line_map *map = linemap_lookup (line_table, loc);
(*debug_hooks->define) (SOURCE_LINE (map, loc),
(const char *) cpp_macro_definition (pfile, node));
}
@@ -318,7 +318,7 @@
cb_undef (cpp_reader * ARG_UNUSED (pfile), source_location loc,
cpp_hashnode *node)
{
- const struct line_map *map = linemap_lookup (&line_table, loc);
+ const struct line_map *map = linemap_lookup (line_table, loc);
(*debug_hooks->undef) (SOURCE_LINE (map, loc),
(const char *) NODE_NAME (node));
}
@@ -337,15 +337,15 @@
timevar_push (TV_CPP);
retry:
+#ifdef USE_MAPPED_LOCATION
+ tok = cpp_get_token_with_location (parse_in, loc);
+#else
tok = cpp_get_token (parse_in);
+ *loc = input_location;
+#endif
type = tok->type;
retry_after_at:
-#ifdef USE_MAPPED_LOCATION
- *loc = tok->src_loc;
-#else
- *loc = input_location;
-#endif
switch (type)
{
case CPP_PADDING:
@@ -389,10 +389,19 @@
/* An @ may give the next token special significance in Objective-C. */
if (c_dialect_objc ())
{
+#ifdef USE_MAPPED_LOCATION
+ location_t atloc = *loc;
+ location_t newloc;
+#else
location_t atloc = input_location;
+#endif
retry_at:
+#ifdef USE_MAPPED_LOCATION
+ tok = cpp_get_token_with_location (parse_in, &newloc);
+#else
tok = cpp_get_token (parse_in);
+#endif
type = tok->type;
switch (type)
{
@@ -416,6 +425,9 @@
default:
/* ... or not. */
error ("%Hstray %<@%> in program", &atloc);
+#ifdef USE_MAPPED_LOCATION
+ *loc = newloc;
+#endif
goto retry_after_at;
}
break;
Index: gcc/tree.c
===================================================================
--- gcc/tree.c (revision 127930)
+++ gcc/tree.c (working copy)
@@ -3403,7 +3403,7 @@
}
else
{
- const struct line_map *map = linemap_lookup (&line_table, loc);
+ const struct line_map *map = linemap_lookup (line_table, loc);
xloc.file = map->to_file;
xloc.line = SOURCE_LINE (map, loc);
xloc.column = SOURCE_COLUMN (map, loc);
@@ -3509,8 +3509,10 @@
{
#ifdef USE_MAPPED_LOCATION
if (GIMPLE_STMT_P (node))
- return &GIMPLE_STMT_LOCUS (node);
- return EXPR_P (node) ? &node->exp.locus : (location_t *) NULL;
+ return (source_location *) CONST_CAST (&GIMPLE_STMT_LOCUS (node));
+ return (source_location *) CONST_CAST (EXPR_P (node)
+ ? &node->exp.locus
+ : (location_t *) NULL);
#else
if (GIMPLE_STMT_P (node))
return GIMPLE_STMT_LOCUS (node);
@@ -3552,33 +3554,44 @@
#endif
}
-const char **
+#ifdef USE_MAPPED_LOCATION
+
+const char *
expr_filename (const_tree node)
{
-#ifdef USE_MAPPED_LOCATION
if (GIMPLE_STMT_P (node))
- return &LOCATION_FILE (GIMPLE_STMT_LOCUS (node));
- return &LOCATION_FILE (EXPR_CHECK (node)->exp.locus);
+ return LOCATION_FILE (GIMPLE_STMT_LOCUS (node));
+ return LOCATION_FILE (EXPR_CHECK (node)->exp.locus);
+}
+
+int
+expr_lineno (const_tree node)
+{
+ if (GIMPLE_STMT_P (node))
+ return LOCATION_LINE (GIMPLE_STMT_LOCUS (node));
+ return LOCATION_LINE (EXPR_CHECK (node)->exp.locus);
+}
+
#else
+
+const char **
+expr_filename (const_tree node)
+{
if (GIMPLE_STMT_P (node))
return &GIMPLE_STMT_LOCUS (node)->file;
return &(EXPR_CHECK (node)->exp.locus->file);
-#endif
}
int *
expr_lineno (const_tree node)
{
-#ifdef USE_MAPPED_LOCATION
if (GIMPLE_STMT_P (node))
- return &LOCATION_LINE (GIMPLE_STMT_LOCUS (node));
- return &LOCATION_LINE (EXPR_CHECK (node)->exp.locus);
-#else
- if (GIMPLE_STMT_P (node))
return &GIMPLE_STMT_LOCUS (node)->line;
return &EXPR_CHECK (node)->exp.locus->line;
+}
+
#endif
-}
+
/* Return a declaration like DDECL except that its DECL_ATTRIBUTES
is ATTRIBUTE. */
Index: gcc/tree.h
===================================================================
--- gcc/tree.h (revision 127930)
+++ gcc/tree.h (working copy)
@@ -1591,8 +1591,16 @@
#define EXPR_HAS_LOCATION(NODE) expr_has_location ((NODE))
#define EXPR_LOCUS(NODE) expr_locus ((NODE))
#define SET_EXPR_LOCUS(NODE, FROM) set_expr_locus ((NODE), (FROM))
+
+#ifdef USE_MAPPED_LOCATION
+#define EXPR_FILENAME(NODE) (expr_filename ((NODE)))
+#define EXPR_LINENO(NODE) (expr_lineno ((NODE)))
+#else
+/* Note that these can only be used as lvalues when
+ #!USE_MAPPED_LOCATION. */
#define EXPR_FILENAME(NODE) *(expr_filename ((NODE)))
#define EXPR_LINENO(NODE) *(expr_lineno ((NODE)))
+#endif
/* True if a tree is an expression or statement that can have a
location. */
@@ -4838,22 +4846,19 @@
extern location_t expr_location (const_tree);
extern void set_expr_location (tree, location_t);
extern bool expr_has_location (const_tree);
-extern
+
#ifdef USE_MAPPED_LOCATION
-source_location *
+extern source_locus *expr_locus (const_tree);
+extern void set_expr_locus (tree, source_location *);
+extern const char *expr_filename (const_tree);
+extern int expr_lineno (const_tree);
#else
-source_locus
-#endif
-expr_locus (const_tree);
-extern void set_expr_locus (tree,
-#ifdef USE_MAPPED_LOCATION
- source_location *loc
-#else
- source_locus loc
-#endif
- );
+extern source_locus expr_locus (const_tree);
+extern void set_expr_locus (tree, source_locus loc);
extern const char **expr_filename (const_tree);
extern int *expr_lineno (const_tree);
+#endif
+
extern tree *tree_block (tree);
extern tree *generic_tree_operand (tree, int);
extern tree *generic_tree_type (tree);
Index: gcc/final.c
===================================================================
--- gcc/final.c (revision 127930)
+++ gcc/final.c (working copy)
@@ -2092,7 +2092,7 @@
if (string[0])
{
- location_t loc;
+ expanded_location loc;
if (! app_on)
{
@@ -2100,7 +2100,7 @@
app_on = 1;
}
#ifdef USE_MAPPED_LOCATION
- loc = ASM_INPUT_SOURCE_LOCATION (body);
+ loc = expand_location (ASM_INPUT_SOURCE_LOCATION (body));
#else
loc.file = ASM_INPUT_SOURCE_FILE (body);
loc.line = ASM_INPUT_SOURCE_LINE (body);
@@ -2124,6 +2124,7 @@
rtx *ops = alloca (noperands * sizeof (rtx));
const char *string;
location_t loc;
+ expanded_location expanded;
/* There's no telling what that did to the condition codes. */
CC_STATUS_INIT;
@@ -2133,6 +2134,7 @@
/* Inhibit dieing on what would otherwise be compiler bugs. */
insn_noperands = noperands;
this_is_asm_operands = insn;
+ expanded = expand_location (loc);
#ifdef FINAL_PRESCAN_INSN
FINAL_PRESCAN_INSN (insn, ops, insn_noperands);
@@ -2146,12 +2148,12 @@
fputs (ASM_APP_ON, file);
app_on = 1;
}
- if (loc.file && loc.line)
+ if (expanded.file && expanded.line)
fprintf (asm_out_file, "%s %i \"%s\" 1\n",
- ASM_COMMENT_START, loc.line, loc.file);
+ ASM_COMMENT_START, expanded.line, expanded.file);
output_asm_insn (string, ops);
#if HAVE_AS_LINE_ZERO
- if (loc.file && loc.line)
+ if (expanded.file && expanded.line)
fprintf (asm_out_file, "%s 0 \"\" 2\n", ASM_COMMENT_START);
#endif
}
Index: gcc/input.h
===================================================================
--- gcc/input.h (revision 127930)
+++ gcc/input.h (working copy)
@@ -23,7 +23,7 @@
#define GCC_INPUT_H
#include "line-map.h"
-extern struct line_maps line_table;
+extern GTY(()) struct line_maps *line_table;
/* The location for declarations in "<built-in>" */
#define BUILTINS_LOCATION ((source_location) 2)
@@ -50,6 +50,8 @@
typedef source_location location_t; /* deprecated typedef */
typedef source_location source_locus; /* to be removed */
+#define location_from_locus(LOCUS) (LOCUS)
+
#else /* ! USE_MAPPED_LOCATION */
struct location_s GTY(())
@@ -69,6 +71,8 @@
extern location_t unknown_location;
#define UNKNOWN_LOCATION unknown_location
+#define location_from_locus(LOCUS) (* (LOCUS))
+
#endif /* ! USE_MAPPED_LOCATION */
struct file_stack
Index: gcc/toplev.c
===================================================================
--- gcc/toplev.c (revision 127930)
+++ gcc/toplev.c (working copy)
@@ -146,7 +146,7 @@
location_t input_location;
-struct line_maps line_table;
+struct line_maps *line_table;
/* Stack of currently pending input files. */
@@ -1601,6 +1601,12 @@
return true;
}
+static void *
+realloc_for_line_map (void *ptr, size_t len)
+{
+ return ggc_realloc (ptr, len);
+}
+
/* Initialization of the front end environment, before command line
options are parsed. Signal handlers, internationalization etc.
ARGV0 is main's argv[0]. */
@@ -1657,7 +1663,9 @@
table. */
init_ggc ();
init_stringpool ();
- linemap_init (&line_table);
+ line_table = GGC_NEW (struct line_maps);
+ linemap_init (line_table);
+ line_table->reallocator = realloc_for_line_map;
init_ttree ();
/* Initialize register usage now so switches may override. */
Index: gcc/testsuite/lib/g++.exp
===================================================================
--- gcc/testsuite/lib/g++.exp (revision 127930)
+++ gcc/testsuite/lib/g++.exp (working copy)
@@ -273,6 +273,7 @@
}
lappend options "additional_flags=[libio_include_flags]"
+ lappend options "additional_flags=-fno-show-column"
lappend options "compiler=$GXX_UNDER_TEST"
set options [concat $gpp_compile_options $options]
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c (revision 127930)
+++ gcc/cp/decl.c (working copy)
@@ -11611,7 +11611,10 @@
return is unreachable, so put the statement on the
special line 0. */
#ifdef USE_MAPPED_LOCATION
- SET_EXPR_LOCATION (stmt, UNKNOWN_LOCATION);
+ {
+ location_t linezero = linemap_line_start (line_table, 0, 1);
+ SET_EXPR_LOCATION (stmt, linezero);
+ }
#else
annotate_with_file_line (stmt, input_filename, 0);
#endif
Index: gcc/c-pch.c
===================================================================
--- gcc/c-pch.c (revision 127930)
+++ gcc/c-pch.c (working copy)
@@ -33,6 +33,7 @@
#include "langhooks.h"
#include "hosthooks.h"
#include "target.h"
+#include "opts.h"
/* This is a list of flag variables that must match exactly, and their
names for the error message. The possible values for *flag_var must
@@ -365,6 +366,7 @@
FILE *f;
struct c_pch_header h;
struct save_macro_data *smd;
+ expanded_location saved_loc;
f = fdopen (fd, "rb");
if (f == NULL)
@@ -406,6 +408,18 @@
cpp_errno (pfile, CPP_DL_ERROR, "seeking");
}
+ /* Save the location and then restore it after reading the PCH. */
+#ifdef USE_MAPPED_LOCATION
+ saved_loc = expand_location (line_table->highest_line);
+#else
+ {
+ const struct line_map *map = linemap_lookup (line_table,
+ line_table->highest_line);
+ saved_loc.file = map->to_file;
+ saved_loc.line = SOURCE_LINE (map, line_table->highest_line);
+ }
+#endif
+
cpp_prepare_state (pfile, &smd);
gt_pch_restore (f);
@@ -415,6 +429,9 @@
fclose (f);
+ cpp_set_line_map (pfile, line_table);
+ linemap_add (line_table, LC_RENAME, 0, saved_loc.file, saved_loc.line);
+
/* Give the front end a chance to take action after a PCH file has
been loaded. */
if (lang_post_pch_load)
Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h (revision 127930)
+++ gcc/fortran/gfortran.h (working copy)
@@ -750,6 +750,12 @@
#define gfc_linebuf_header_size (offsetof (gfc_linebuf, line))
+#ifdef USE_MAPPED_LOCATION
+#define gfc_linebuf_linenum(LBUF) (LOCATION_LINE ((LBUF)->location))
+#else
+#define gfc_linebuf_linenum(LBUF) ((LBUF)->linenum)
+#endif
+
typedef struct
{
char *nextc;
Index: gcc/fortran/scanner.c
===================================================================
--- gcc/fortran/scanner.c (revision 127930)
+++ gcc/fortran/scanner.c (working copy)
@@ -710,7 +710,7 @@
/* We've got a continuation line. If we are on the very next line after
the last continuation, increment the continuation line count and
check whether the limit has been exceeded. */
- if (gfc_current_locus.lb->linenum == continue_line + 1)
+ if (gfc_linebuf_linenum (gfc_current_locus.lb) == continue_line + 1)
{
if (++continue_count == gfc_option.max_continue_free)
{
@@ -719,7 +719,7 @@
"statement at %C", gfc_option.max_continue_free);
}
}
- continue_line = gfc_current_locus.lb->linenum;
+ continue_line = gfc_linebuf_linenum (gfc_current_locus.lb);
/* Now find where it continues. First eat any comment lines. */
openmp_cond_flag = skip_free_comments ();
@@ -831,7 +831,7 @@
/* We've got a continuation line. If we are on the very next line after
the last continuation, increment the continuation line count and
check whether the limit has been exceeded. */
- if (gfc_current_locus.lb->linenum == continue_line + 1)
+ if (gfc_linebuf_linenum (gfc_current_locus.lb) == continue_line + 1)
{
if (++continue_count == gfc_option.max_continue_fixed)
{
@@ -842,8 +842,8 @@
}
}
- if (continue_line < gfc_current_locus.lb->linenum)
- continue_line = gfc_current_locus.lb->linenum;
+ if (continue_line < gfc_linebuf_linenum (gfc_current_locus.lb))
+ continue_line = gfc_linebuf_linenum (gfc_current_locus.lb);
}
/* Ready to read first character of continuation line, which might
@@ -1170,7 +1170,7 @@
f->inclusion_line = current_file->line;
#ifdef USE_MAPPED_LOCATION
- linemap_add (&line_table, reason, false, f->filename, 1);
+ linemap_add (line_table, reason, false, f->filename, 1);
#endif
return f;
@@ -1514,7 +1514,7 @@
#ifdef USE_MAPPED_LOCATION
b->location
- = linemap_line_start (&line_table, current_file->line++, 120);
+ = linemap_line_start (line_table, current_file->line++, 120);
#else
b->linenum = current_file->line++;
#endif
@@ -1537,7 +1537,7 @@
current_file = current_file->up;
#ifdef USE_MAPPED_LOCATION
- linemap_add (&line_table, LC_LEAVE, 0, NULL, 0);
+ linemap_add (line_table, LC_LEAVE, 0, NULL, 0);
#endif
return SUCCESS;
}
Index: gcc/fortran/f95-lang.c
===================================================================
--- gcc/fortran/f95-lang.c (revision 127930)
+++ gcc/fortran/f95-lang.c (working copy)
@@ -316,8 +316,8 @@
gfc_init (void)
{
#ifdef USE_MAPPED_LOCATION
- linemap_add (&line_table, LC_ENTER, false, gfc_source_file, 1);
- linemap_add (&line_table, LC_RENAME, false, "<built-in>", 0);
+ linemap_add (line_table, LC_ENTER, false, gfc_source_file, 1);
+ linemap_add (line_table, LC_RENAME, false, "<built-in>", 0);
#endif
/* First initialize the backend. */
Index: gcc/treelang/lex.l
===================================================================
--- gcc/treelang/lex.l (revision 127930)
+++ gcc/treelang/lex.l (working copy)
@@ -76,7 +76,7 @@
{
/* ??? Should really allocate only what we need. */
yylval = my_malloc (sizeof (struct prod_token_parm_item));
- LINEMAP_POSITION_FOR_COLUMN (input_location, &line_table,
+ LINEMAP_POSITION_FOR_COLUMN (input_location, line_table,
next_tree_charno);
((struct prod_token_parm_item *)yylval)->tp.tok.location = input_location;
((struct prod_token_parm_item *)yylval)->tp.tok.charno = next_tree_charno;
@@ -233,7 +233,7 @@
/* Update the values we send to caller in case we sometimes don't
tell them about all the 'tokens' eg comments etc. */
int yyl;
- LINEMAP_POSITION_FOR_COLUMN (input_location, &line_table,
+ LINEMAP_POSITION_FOR_COLUMN (input_location, line_table,
next_tree_charno);
((struct prod_token_parm_item *)yylval)->tp.tok.location = input_location;
((struct prod_token_parm_item *)yylval)->tp.tok.charno = next_tree_charno;
@@ -243,7 +243,7 @@
if ( yytext[yyl] == '\n' )
{
#ifdef USE_MAPPED_LOCATION
- source_location s = linemap_line_start (&line_table, ++lineno,
+ source_location s = linemap_line_start (line_table, ++lineno,
80);
input_location = s;
#else
Index: gcc/treelang/tree1.c
===================================================================
--- gcc/treelang/tree1.c (revision 127930)
+++ gcc/treelang/tree1.c (working copy)
@@ -142,7 +142,7 @@
#ifndef USE_MAPPED_LOCATION
input_filename = main_input_filename;
#else
- linemap_add (&line_table, LC_ENTER, false, main_input_filename, 1);
+ linemap_add (line_table, LC_ENTER, false, main_input_filename, 1);
#endif
/* This error will not happen from GCC as it will always create a
@@ -166,8 +166,8 @@
}
#ifdef USE_MAPPED_LOCATION
- linemap_add (&line_table, LC_RENAME, false, "<built-in>", 1);
- linemap_line_start (&line_table, 0, 1);
+ linemap_add (line_table, LC_RENAME, false, "<built-in>", 1);
+ linemap_line_start (line_table, 0, 1);
#endif
/* Init decls, etc. */
@@ -191,8 +191,8 @@
{
#ifdef USE_MAPPED_LOCATION
source_location s;
- linemap_add (&line_table, LC_RENAME, false, main_input_filename, 1);
- s = linemap_line_start (&line_table, 1, 80);
+ linemap_add (line_table, LC_RENAME, false, main_input_filename, 1);
+ s = linemap_line_start (line_table, 1, 80);
input_location = s;
#else
input_line = 1;
@@ -202,7 +202,7 @@
yyparse ();
cgraph_finalize_compilation_unit ();
#ifdef USE_MAPPED_LOCATION
- linemap_add (&line_table, LC_LEAVE, false, NULL, 0);
+ linemap_add (line_table, LC_LEAVE, false, NULL, 0);
#endif
cgraph_optimize ();
}
Index: gcc/gimplify.c
===================================================================
--- gcc/gimplify.c (revision 127930)
+++ gcc/gimplify.c (working copy)
@@ -3569,7 +3569,7 @@
/* The set to base above overwrites the CODE. */
TREE_SET_CODE ((tree) gs, GIMPLE_MODIFY_STMT);
- gs->locus = EXPR_LOCUS (*tp);
+ SET_EXPR_LOCUS ((tree) gs, EXPR_LOCUS (*tp));
gs->operands[0] = TREE_OPERAND (*tp, 0);
gs->operands[1] = TREE_OPERAND (*tp, 1);
gs->block = TREE_BLOCK (*tp);
Index: gcc/cfgexpand.c
===================================================================
--- gcc/cfgexpand.c (revision 127930)
+++ gcc/cfgexpand.c (working copy)
@@ -1312,7 +1312,7 @@
add_reg_br_prob_note (last, true_edge->probability);
maybe_dump_rtl_for_tree_stmt (stmt, last);
if (true_edge->goto_locus)
- set_curr_insn_source_location (*true_edge->goto_locus);
+ set_curr_insn_source_location (location_from_locus (true_edge->goto_locus));
false_edge->flags |= EDGE_FALLTHRU;
return NULL;
}
@@ -1322,7 +1322,7 @@
add_reg_br_prob_note (last, false_edge->probability);
maybe_dump_rtl_for_tree_stmt (stmt, last);
if (false_edge->goto_locus)
- set_curr_insn_source_location (*false_edge->goto_locus);
+ set_curr_insn_source_location (location_from_locus (false_edge->goto_locus));
true_edge->flags |= EDGE_FALLTHRU;
return NULL;
}
@@ -1353,7 +1353,7 @@
maybe_dump_rtl_for_tree_stmt (stmt, last2);
if (false_edge->goto_locus)
- set_curr_insn_source_location (*false_edge->goto_locus);
+ set_curr_insn_source_location (location_from_locus (false_edge->goto_locus));
return new_bb;
}
@@ -1620,7 +1620,7 @@
{
emit_jump (label_rtx_for_bb (e->dest));
if (e->goto_locus)
- set_curr_insn_source_location (*e->goto_locus);
+ set_curr_insn_source_location (location_from_locus (e->goto_locus));
e->flags &= ~EDGE_FALLTHRU;
}
Index: gcc/c-opts.c
===================================================================
--- gcc/c-opts.c (revision 127930)
+++ gcc/c-opts.c (working copy)
@@ -217,7 +217,7 @@
}
parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89,
- ident_hash, &line_table);
+ ident_hash, line_table);
cpp_opts = cpp_get_options (parse_in);
cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
@@ -1484,7 +1484,7 @@
size_t i;
cb_file_change (parse_in,
- linemap_add (&line_table, LC_RENAME, 0,
+ linemap_add (line_table, LC_RENAME, 0,
_("<built-in>"), 0));
cpp_init_builtins (parse_in, flag_hosted);
@@ -1502,7 +1502,7 @@
cpp_opts->warn_dollars = (cpp_opts->pedantic && !cpp_opts->c99);
cb_file_change (parse_in,
- linemap_add (&line_table, LC_RENAME, 0,
+ linemap_add (line_table, LC_RENAME, 0,
_("<command-line>"), 0));
for (i = 0; i < deferred_count; i++)
@@ -1567,7 +1567,7 @@
/* Set this here so the client can change the option if it wishes,
and after stacking the main file so we don't trace the main file. */
- line_table.trace_includes = cpp_opts->print_include_names;
+ line_table->trace_includes = cpp_opts->print_include_names;
}
}
Index: gcc/c-ppoutput.c
===================================================================
--- gcc/c-ppoutput.c (revision 127930)
+++ gcc/c-ppoutput.c (working copy)
@@ -234,7 +234,7 @@
static void
maybe_print_line (source_location src_loc)
{
- const struct line_map *map = linemap_lookup (&line_table, src_loc);
+ const struct line_map *map = linemap_lookup (line_table, src_loc);
int src_line = SOURCE_LINE (map, src_loc);
/* End the previous line of text. */
if (print.printed)
@@ -268,7 +268,7 @@
if (!flag_no_line_commands)
{
- const struct line_map *map = linemap_lookup (&line_table, src_loc);
+ const struct line_map *map = linemap_lookup (line_table, src_loc);
size_t to_file_len = strlen (map->to_file);
unsigned char *to_file_quoted =
@@ -317,7 +317,7 @@
ought to care. Some things do care; the fault lies with them. */
if (!CPP_OPTION (pfile, traditional))
{
- const struct line_map *map = linemap_lookup (&line_table, src_loc);
+ const struct line_map *map = linemap_lookup (line_table, src_loc);
int spaces = SOURCE_COLUMN (map, src_loc) - 2;
print.printed = 1;
@@ -349,7 +349,7 @@
fputs ((const char *) NODE_NAME (node), print.outf);
putc ('\n', print.outf);
- if (linemap_lookup (&line_table, line)->to_line != 0)
+ if (linemap_lookup (line_table, line)->to_line != 0)
print.src_line++;
}
@@ -430,7 +430,7 @@
/* Bring current file to correct line when entering a new file. */
if (map->reason == LC_ENTER)
{
- const struct line_map *from = INCLUDED_FROM (&line_table, map);
+ const struct line_map *from = INCLUDED_FROM (line_table, map);
maybe_print_line (LAST_SOURCE_LINE_LOCATION (from));
}
if (map->reason == LC_ENTER)
Index: gcc/tree-cfg.c
===================================================================
--- gcc/tree-cfg.c (revision 127930)
+++ gcc/tree-cfg.c (working copy)
@@ -2055,7 +2055,7 @@
loop above, so the last statement we process is the first statement
in the block. */
#ifdef USE_MAPPED_LOCATION
- if (loc > BUILTINS_LOCATION)
+ if (loc > BUILTINS_LOCATION && LOCATION_LINE (loc) > 0)
warning (OPT_Wunreachable_code, "%Hwill never be executed", &loc);
#else
if (loc)