https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79061
--- Comment #11 from Maxim Ostapenko <m.ostapenko at samsung dot com> --- (In reply to Maxim Ostapenko from comment #10) > Yeah, but it seems that lto doesn't propagate source location either: > > /* Output info about new location into bitpack BP. > After outputting bitpack, lto_output_location_data has > to be done to output actual data. */ > > void > lto_output_location (struct output_block *ob, struct bitpack_d *bp, > location_t loc) > { > expanded_location xloc; > > loc = LOCATION_LOCUS (loc); > bp_pack_int_in_range (bp, 0, RESERVED_LOCATION_COUNT, > loc < RESERVED_LOCATION_COUNT > ? loc : RESERVED_LOCATION_COUNT); > if (loc < RESERVED_LOCATION_COUNT) > return; > > [...] > } > > where RESERVED_LOCATION_COUNT == 2. Or maybe I missed something? > We can probably teach it to propagate source location but is it OK for > current stage? Hm, attached patch seems to propagate source location normally: diff --git a/gcc/tree-streamer-in.c b/gcc/tree-streamer-in.c index 3496df5..714a5b1 100644 --- a/gcc/tree-streamer-in.c +++ b/gcc/tree-streamer-in.c @@ -405,6 +405,7 @@ unpack_ts_translation_unit_decl_value_fields (struct data_in *data_in, struct bitpack_d *bp, tree expr) { TRANSLATION_UNIT_LANGUAGE (expr) = xstrdup (bp_unpack_string (data_in, bp)); + DECL_SOURCE_LOCATION (expr) = stream_input_location_now (bp, data_in); vec_safe_push (all_translation_units, expr); } diff --git a/gcc/tree-streamer-out.c b/gcc/tree-streamer-out.c index 0ee2abe..3c11d61 100644 --- a/gcc/tree-streamer-out.c +++ b/gcc/tree-streamer-out.c @@ -359,6 +359,7 @@ pack_ts_translation_unit_decl_value_fields (struct output_block *ob, struct bitpack_d *bp, tree expr) { bp_pack_string (ob, bp, TRANSLATION_UNIT_LANGUAGE (expr), true); + stream_output_location (ob, bp, DECL_SOURCE_LOCATION (expr)); } diff --git a/gcc/tree.c b/gcc/tree.c index cffa36d..ee611e2 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -4758,7 +4758,9 @@ vec<tree, va_gc> *all_translation_units; tree build_translation_unit_decl (tree name) { - tree tu = build_decl (UNKNOWN_LOCATION, TRANSLATION_UNIT_DECL, + linemap_add (line_table, LC_ENTER, false, main_input_filename, 1); + location_t loc = linemap_line_start (line_table, 1, 0); + tree tu = build_decl (loc, TRANSLATION_UNIT_DECL, name, NULL_TREE); TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name; vec_safe_push (all_translation_units, tu); The only issue is failing diagnostic test now: /home/max/workspace/downloads/gcc/gcc/diagnostic.c:1557: test_print_parseable_fixits_insert: FAIL: ASSERT_STREQ ("fix-it:\"test.c\":{5:10-5:10}:\"added content\"\n", pp_formatted_text (&pp)) expected="fix-it:"test.c":{5:10-5:10}:"added content" " actual="fix-it:"/dev/null":{33:10-33:10}:"added content" "