diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 35d46e16e4db..cc4b3194cc67 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,45 @@ +2007-09-06 Tom Tromey + + * 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): Changed return type. Unified the two cases. + (expr_lineno): Likewise. + (annotate_with_file_line): Don't use EXPR_LINENO and EXPR_FILENAME + as lvalues. + * 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): No longer an lvalue. + (EXPR_LINENO): Likewise. + (expr_locus, set_expr_locus): Declare separately for + USE_MAPPED_LOCATION. + (expr_filename, expr_lineno): Changed return type. + * 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. + 2007-09-06 Richard Guenther PR tree-optimization/32586 diff --git a/gcc/c-lex.c b/gcc/c-lex.c index bc0aeb2faa9e..23abaad6c108 100644 --- a/gcc/c-lex.c +++ b/gcc/c-lex.c @@ -205,7 +205,7 @@ cb_line_change (cpp_reader * ARG_UNUSED (pfile), const cpp_token *token, #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 @@ -283,7 +283,7 @@ cb_def_pragma (cpp_reader *pfile, source_location loc) 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 @@ -309,7 +309,7 @@ cb_def_pragma (cpp_reader *pfile, source_location loc) 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)); } @@ -319,7 +319,7 @@ static void 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)); } @@ -338,15 +338,15 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags) 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: @@ -390,10 +390,19 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags) /* 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) { @@ -417,6 +426,9 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags) default: /* ... or not. */ error ("%Hstray %<@%> in program", &atloc); +#ifdef USE_MAPPED_LOCATION + *loc = newloc; +#endif goto retry_after_at; } break; diff --git a/gcc/c-opts.c b/gcc/c-opts.c index 2a158c191e7d..80c01a01c1d8 100644 --- a/gcc/c-opts.c +++ b/gcc/c-opts.c @@ -218,7 +218,7 @@ c_common_init_options (unsigned int argc, const char **argv) } 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; @@ -1485,7 +1485,7 @@ finish_options (void) size_t i; cb_file_change (parse_in, - linemap_add (&line_table, LC_RENAME, 0, + linemap_add (line_table, LC_RENAME, 0, _(""), 0)); cpp_init_builtins (parse_in, flag_hosted); @@ -1503,7 +1503,7 @@ finish_options (void) 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, _(""), 0)); for (i = 0; i < deferred_count; i++) @@ -1568,7 +1568,7 @@ push_command_line_include (void) /* 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; } } diff --git a/gcc/c-pch.c b/gcc/c-pch.c index 255bcad20c83..d8751e83070f 100644 --- a/gcc/c-pch.c +++ b/gcc/c-pch.c @@ -33,6 +33,7 @@ along with GCC; see the file COPYING3. If not see #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 @@ c_common_read_pch (cpp_reader *pfile, const char *name, 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 @@ c_common_read_pch (cpp_reader *pfile, const char *name, 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 @@ c_common_read_pch (cpp_reader *pfile, const char *name, 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) diff --git a/gcc/c-ppoutput.c b/gcc/c-ppoutput.c index 22ee0f6a887b..f02d6cd2b766 100644 --- a/gcc/c-ppoutput.c +++ b/gcc/c-ppoutput.c @@ -234,7 +234,7 @@ scan_translation_unit_trad (cpp_reader *pfile) 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 @@ print_line (source_location src_loc, const char *special_flags) 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 @@ cb_line_change (cpp_reader *pfile, const cpp_token *token, 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 @@ cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node) 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 @@ pp_file_change (const struct line_map *map) /* 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) diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index 6031fda7c724..69c65bd5e498 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -1312,7 +1312,7 @@ expand_gimple_cond_expr (basic_block bb, tree stmt) 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 @@ expand_gimple_cond_expr (basic_block bb, tree stmt) 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 @@ expand_gimple_cond_expr (basic_block bb, tree stmt) 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 @@ expand_gimple_basic_block (basic_block bb) { 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; } diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6bcc3ef3cfed..db8b3eba13a9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2007-09-06 Tom Tromey + + * decl.c (finish_function): Put return's location on line zero of + file. + 2007-09-05 Jason Merrill PR c++/15745 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 9587de568480..86f2a4a1c161 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -11632,7 +11632,10 @@ finish_function (int flags) 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 diff --git a/gcc/final.c b/gcc/final.c index 7c2b4ea9f08d..e5e9b8d0f808 100644 --- a/gcc/final.c +++ b/gcc/final.c @@ -2092,7 +2092,7 @@ final_scan_insn (rtx insn, FILE *file, int optimize ATTRIBUTE_UNUSED, if (string[0]) { - location_t loc; + expanded_location loc; if (! app_on) { @@ -2100,7 +2100,7 @@ final_scan_insn (rtx insn, FILE *file, int optimize ATTRIBUTE_UNUSED, 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 @@ final_scan_insn (rtx insn, FILE *file, int optimize ATTRIBUTE_UNUSED, 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 @@ final_scan_insn (rtx insn, FILE *file, int optimize ATTRIBUTE_UNUSED, /* 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 @@ final_scan_insn (rtx insn, FILE *file, int optimize ATTRIBUTE_UNUSED, 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 } diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 45bbac9ec82a..8c9412461991 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,11 @@ +2007-09-06 Tom Tromey + + * 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. + 2007-09-05 Sandra Loosemore * trans-decl.c (build_entry_thunks): Use set_cfun. diff --git a/gcc/fortran/f95-lang.c b/gcc/fortran/f95-lang.c index 05f6750218db..b9eb1f852f05 100644 --- a/gcc/fortran/f95-lang.c +++ b/gcc/fortran/f95-lang.c @@ -316,8 +316,8 @@ static bool 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, "", 0); + linemap_add (line_table, LC_ENTER, false, gfc_source_file, 1); + linemap_add (line_table, LC_RENAME, false, "", 0); #endif /* First initialize the backend. */ diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index bfd1af88b90f..b2da38f4ebfa 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -696,6 +696,12 @@ typedef struct gfc_linebuf #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; diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c index 844cfbf7f154..b0c7979554ea 100644 --- a/gcc/fortran/scanner.c +++ b/gcc/fortran/scanner.c @@ -710,7 +710,7 @@ restart: /* 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 @@ restart: "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 @@ restart: /* 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 @@ restart: } } - 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 @@ get_file (const char *name, enum lc_reason reason ATTRIBUTE_UNUSED) 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 @@ load_file (const char *filename, bool initial) #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 @@ load_file (const char *filename, bool initial) 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; } diff --git a/gcc/gimplify.c b/gcc/gimplify.c index ee8ef09a1030..c4d4f6292550 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -3607,7 +3607,7 @@ tree_to_gimple_tuple (tree *tp) /* 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); diff --git a/gcc/input.h b/gcc/input.h index 45b0515361da..c360a1d5312c 100644 --- a/gcc/input.h +++ b/gcc/input.h @@ -23,7 +23,7 @@ along with GCC; see the file COPYING3. If not see #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 "" */ #define BUILTINS_LOCATION ((source_location) 2) @@ -50,6 +50,8 @@ extern expanded_location expand_location (source_location); 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 @@ typedef location_t *source_locus; extern location_t unknown_location; #define UNKNOWN_LOCATION unknown_location +#define location_from_locus(LOCUS) (* (LOCUS)) + #endif /* ! USE_MAPPED_LOCATION */ struct file_stack diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index 3e8a3a490ac5..94a5fe3852b2 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,14 @@ +2007-09-06 Tom Tromey + + * 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. + 2007-09-05 Sandra Loosemore * decl.c (finish_method): Use set_cfun. diff --git a/gcc/java/expr.c b/gcc/java/expr.c index af49adbe8d69..1eceaad8bc12 100644 --- a/gcc/java/expr.c +++ b/gcc/java/expr.c @@ -3194,7 +3194,7 @@ expand_byte_code (JCF *jcf, tree method) { 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 diff --git a/gcc/java/jcf-parse.c b/gcc/java/jcf-parse.c index 397b1874194a..ff2c9995e8c6 100644 --- a/gcc/java/jcf-parse.c +++ b/gcc/java/jcf-parse.c @@ -365,7 +365,7 @@ set_source_filename (JCF *jcf, int index) 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 @@ give_name_to_class (JCF *jcf, int i) { 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 @@ jcf_parse (JCF* jcf) 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 @@ duplicate_class_warning (const char *filename) { 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 @@ parse_class_file (void) } #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 @@ java_parse_file (int set_yydebug ATTRIBUTE_UNUSED) 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 @@ java_parse_file (int set_yydebug ATTRIBUTE_UNUSED) /* 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_parse_file (int set_yydebug ATTRIBUTE_UNUSED) 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 } diff --git a/gcc/java/lang.c b/gcc/java/lang.c index 3dd7017997d5..6a453fc9d846 100644 --- a/gcc/java/lang.c +++ b/gcc/java/lang.c @@ -653,8 +653,8 @@ java_post_options (const char **pfilename) } } #ifdef USE_MAPPED_LOCATION - linemap_add (&line_table, LC_ENTER, false, filename, 0); - linemap_add (&line_table, LC_RENAME, false, "", 0); + linemap_add (line_table, LC_ENTER, false, filename, 0); + linemap_add (line_table, LC_RENAME, false, "", 0); #endif /* Initialize the compiler back end. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3a463461b16d..64d00d36a819 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2007-09-06 Tom Tromey + + * lib/g++.exp (g++_target_compile): Use -fno-show-column. + 2007-09-06 Richard Guenther PR tree-optimization/32586 diff --git a/gcc/testsuite/lib/g++.exp b/gcc/testsuite/lib/g++.exp index 7ca5b7397818..c188824b8415 100644 --- a/gcc/testsuite/lib/g++.exp +++ b/gcc/testsuite/lib/g++.exp @@ -273,6 +273,7 @@ proc g++_target_compile { source dest type options } { } 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] diff --git a/gcc/toplev.c b/gcc/toplev.c index 31d8c5f1ab63..b8d1f9cbc5d2 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -146,7 +146,7 @@ location_t unknown_location = { NULL, 0 }; location_t input_location; -struct line_maps line_table; +struct line_maps *line_table; /* Stack of currently pending input files. */ @@ -1601,6 +1601,14 @@ default_tree_printer (pretty_printer * pp, text_info *text, const char *spec, return true; } +/* A helper function; used as the reallocator function for cpp's line + table. */ +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 +1665,9 @@ general_init (const char *argv0) 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. */ diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index 95f27141c0fb..461f3f2db25e 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -2057,7 +2057,7 @@ remove_bb (basic_block bb) 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) diff --git a/gcc/tree.c b/gcc/tree.c index 289b5c957525..9e5a7bd90681 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -3403,7 +3403,7 @@ expand_location (source_location loc) } 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); @@ -3419,6 +3419,8 @@ expand_location (source_location loc) void annotate_with_file_line (tree node, const char *file, int line) { + location_t *new_loc; + /* Roughly one percent of the calls to this function are to annotate a node with the same information already attached to that node! Just return instead of wasting memory. */ @@ -3443,10 +3445,11 @@ annotate_with_file_line (tree node, const char *file, int line) return; } - SET_EXPR_LOCUS (node, ggc_alloc (sizeof (location_t))); - EXPR_LINENO (node) = line; - EXPR_FILENAME (node) = file; - last_annotated_node = EXPR_LOCUS (node); + new_loc = GGC_NEW (location_t); + new_loc->file = file; + new_loc->line = line; + SET_EXPR_LOCUS (node, new_loc); + last_annotated_node = new_loc; } void @@ -3509,13 +3512,13 @@ expr_locus (const_tree node) { #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 CONST_CAST (source_location *, &GIMPLE_STMT_LOCUS (node)); + return (EXPR_P (node) + ? CONST_CAST (source_location *, &node->exp.locus) + : (source_location *) NULL); #else if (GIMPLE_STMT_P (node)) return GIMPLE_STMT_LOCUS (node); - /* ?? The cast below was originally "(location_t *)" in the macro, - but that makes no sense. ?? */ return EXPR_P (node) ? node->exp.locus : (source_locus) NULL; #endif } @@ -3552,33 +3555,24 @@ set_expr_locus (tree node, #endif } -const char ** +/* Return the file name of the location of NODE. */ +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); -#else - if (GIMPLE_STMT_P (node)) - return &GIMPLE_STMT_LOCUS (node)->file; - return &(EXPR_CHECK (node)->exp.locus->file); -#endif + return LOCATION_FILE (location_from_locus (GIMPLE_STMT_LOCUS (node))); + return LOCATION_FILE (location_from_locus (EXPR_CHECK (node)->exp.locus)); } -int * +/* Return the line number of the location of NODE. */ +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 LOCATION_LINE (location_from_locus (GIMPLE_STMT_LOCUS (node))); + return LOCATION_LINE (location_from_locus (EXPR_CHECK (node)->exp.locus)); } + /* Return a declaration like DDECL except that its DECL_ATTRIBUTES is ATTRIBUTE. */ diff --git a/gcc/tree.h b/gcc/tree.h index c274fb6ec245..5a74cccebba4 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -1598,8 +1598,8 @@ struct tree_constructor GTY(()) #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)) -#define EXPR_FILENAME(NODE) *(expr_filename ((NODE))) -#define EXPR_LINENO(NODE) *(expr_lineno ((NODE))) +#define EXPR_FILENAME(NODE) (expr_filename ((NODE))) +#define EXPR_LINENO(NODE) (expr_lineno ((NODE))) /* True if a tree is an expression or statement that can have a location. */ @@ -4840,22 +4840,17 @@ extern tree find_compatible_field (tree, tree); 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 *); #else -source_locus +extern source_locus expr_locus (const_tree); +extern void set_expr_locus (tree, source_locus loc); #endif -expr_locus (const_tree); -extern void set_expr_locus (tree, -#ifdef USE_MAPPED_LOCATION - source_location *loc -#else - source_locus loc -#endif - ); -extern const char **expr_filename (const_tree); -extern int *expr_lineno (const_tree); +extern const char *expr_filename (const_tree); +extern int expr_lineno (const_tree); + extern tree *tree_block (tree); extern tree *generic_tree_operand (tree, int); extern tree *generic_tree_type (tree); diff --git a/gcc/treelang/ChangeLog b/gcc/treelang/ChangeLog index 8c464d69940c..d98c1c4c85aa 100644 --- a/gcc/treelang/ChangeLog +++ b/gcc/treelang/ChangeLog @@ -1,3 +1,12 @@ +2007-09-06 Tom Tromey + + * tree1.c (treelang_init): Update. + (treelang_parse_file): Update. + (treelang_parse_file): Update. + (treelang_parse_file): Update. + * lex.l: Update. + (update_lineno_charno): Likewise. + 2007-09-05 Sandra Loosemore * treetree.c (tree_code_create_function_wrapup): Use set_cfun. diff --git a/gcc/treelang/lex.l b/gcc/treelang/lex.l index 429ee80fe60c..d0964c4af90e 100644 --- a/gcc/treelang/lex.l +++ b/gcc/treelang/lex.l @@ -76,7 +76,7 @@ static void dump_lex_value (int lexret); { /* ??? 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_lineno_charno (void) /* 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 @@ update_lineno_charno (void) 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 diff --git a/gcc/treelang/tree1.c b/gcc/treelang/tree1.c index bd1168c2fa5c..a2f990f862d1 100644 --- a/gcc/treelang/tree1.c +++ b/gcc/treelang/tree1.c @@ -142,7 +142,7 @@ treelang_init (void) #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 @@ treelang_init (void) } #ifdef USE_MAPPED_LOCATION - linemap_add (&line_table, LC_RENAME, false, "", 1); - linemap_line_start (&line_table, 0, 1); + linemap_add (line_table, LC_RENAME, false, "", 1); + linemap_line_start (line_table, 0, 1); #endif /* Init decls, etc. */ @@ -191,8 +191,8 @@ treelang_parse_file (int debug_flag ATTRIBUTE_UNUSED) { #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 @@ treelang_parse_file (int debug_flag ATTRIBUTE_UNUSED) 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 (); } diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index c24f47e1efff..08e5f86af1ed 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,22 @@ +2007-09-06 Tom Tromey + + * internal.h (struct cpp_reader) : New + field. + (struct cpp_reader) : 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) : Likewise. + (struct line_maps) : 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. + 2007-08-30 Chao-ying Fu * expr.c (interpret_float_suffix): Support hr, r, lr, llr, uhr, ur, diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 039dfbbf193e..ff13cd6b532e 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -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 @@ struct cpp_hashnode GTY(()) 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 void cpp_register_deferred_pragma (cpp_reader *, const char *, 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); diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index 7e9ede01a1a5..cddc74d432e6 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -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 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #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 @@ enum lc_reason {LC_ENTER = 0, LC_LEAVE, LC_RENAME}; 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<line_table = line_table; +} + /* Free resources used by PFILE. Accessing PFILE after this function returns leads to undefined behavior. Returns the error count. */ void diff --git a/libcpp/internal.h b/libcpp/internal.h index 8561088f9054..59332df4fe36 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -339,6 +339,14 @@ struct cpp_reader /* 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; /* <> */ diff --git a/libcpp/line-map.c b/libcpp/line-map.c index c95eacde7e3c..c13a82dcafc9 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -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 @@ linemap_add (struct line_maps *set, enum lc_reason reason, 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]; diff --git a/libcpp/macro.c b/libcpp/macro.c index f2427172ca0e..e80815b7bf2b 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -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 @@ const cpp_token * 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 @@ cpp_get_token (cpp_reader *pfile) 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,27 @@ cpp_get_token (cpp_reader *pfile) return result; } +/* Like cpp_get_token, but also returns a location separate from the + one provided by the returned token. LOC is an out parameter; *LOC + is set to the location "as expected by the user". This matters + when a token results from macro expansion -- the token's location + will indicate where the macro is defined, but *LOC will be the + location of the start of the expansion. */ +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. */