gas: maintain line numbers correctly after #APP / #NO_APP

Maintaining line numbers correctly both inside the region and past it
requires special care. The SB produced there is somewhat different from
that produced for e.g. macro expansions, and hence also needs treating
differently: In particular we aren't doing anything resembling macro
expansion here.

The new testcase may be a little misplaced in macros/, but that's where
all the other #APP / #NO_APP ones are.
This commit is contained in:
Jan Beulich 2024-08-05 16:29:54 +02:00
parent 526363dbe4
commit b43f37b77f
6 changed files with 48 additions and 9 deletions

View File

@ -194,10 +194,23 @@ input_scrub_pop (struct input_save *saved)
saved_position = saved->saved_position;
buffer_start = saved->buffer_start;
buffer_length = saved->buffer_length;
physical_input_file = saved->physical_input_file;
/* When expanding an #APP / #NO_APP block, original lines are re-
processed, so whatever they did to physical file/line needs
retaining. If logical file/line weren't changed, the logical
line number will want bumping by a corresponding value. */
if (from_sb_expansion != expanding_app)
{
if (logical_input_file == 0 && logical_input_line == -1u
&& saved->logical_input_line != -1u)
saved->logical_input_line
+= physical_input_line - saved->physical_input_line;
physical_input_file = saved->physical_input_file;
physical_input_line = saved->physical_input_line;
}
logical_input_file = saved->logical_input_file;
physical_input_line = saved->physical_input_line;
logical_input_line = saved->logical_input_line;
is_linefile = saved->is_linefile;
sb_index = saved->sb_index;
from_sb = saved->from_sb;
@ -270,9 +283,12 @@ input_scrub_include_sb (sb *from, char *position, enum expansion expansion)
{
int newline;
if (macro_nest > max_macro_nest)
as_fatal (_("macros nested too deeply"));
++macro_nest;
if (expansion != expanding_app)
{
if (macro_nest > max_macro_nest)
as_fatal (_("macros nested too deeply"));
++macro_nest;
}
#ifdef md_macro_start
if (expansion == expanding_macro)
@ -335,7 +351,8 @@ input_scrub_next_buffer (char **bufp)
md_macro_end ();
#endif
}
--macro_nest;
if (from_sb_expansion != expanding_app)
--macro_nest;
partial_where = NULL;
partial_size = 0;
if (next_saved_file != NULL)
@ -432,7 +449,7 @@ seen_at_least_1_file (void)
void
bump_line_counters (void)
{
if (sb_index == (size_t) -1)
if (sb_index == (size_t) -1 || from_sb_expansion == expanding_app)
++physical_input_line;
if (logical_input_line != -1u)

View File

@ -998,7 +998,6 @@ read_a_source_file (const char *name)
input_line_pointer = s;
continue;
}
bump_line_counters ();
s += 4;
ends = find_no_app (s, next_char);
@ -1023,9 +1022,10 @@ read_a_source_file (const char *name)
}
while (!ends);
}
sb_add_char (&sbuf, '\n');
input_line_pointer = ends ? ends + 8 : NULL;
input_scrub_include_sb (&sbuf, input_line_pointer, expanding_none);
input_scrub_include_sb (&sbuf, input_line_pointer, expanding_app);
sb_kill (&sbuf);
buffer_limit = input_scrub_next_buffer (&input_line_pointer);
continue;

View File

@ -69,6 +69,7 @@ enum expansion {
expanding_none,
expanding_repeat,
expanding_macro,
expanding_app,
};
extern void input_scrub_include_sb (sb *, char *, enum expansion);

View File

@ -0,0 +1,7 @@
.*: Assembler messages:
.*:3: Warning: .*first.*
.*:5: Warning: .*second.*
.*:7: Warning: .*third.*
.*:9: Warning: .*fourth.*
.*:11: Warning: .*fifth.*
#pass

View File

@ -0,0 +1,11 @@
#NO_APP
.data
.warning "first"
#APP
.warning "second"
;#NO_APP
.warning "third"
;#APP
.warning "fourth"
#NO_APP
.warning "fifth"

View File

@ -71,6 +71,9 @@ run_dump_test app3
remote_download host "$srcdir/$subdir/app4b.s"
run_dump_test app4
run_dump_test app5
if { ![istarget tic30-*-*] } {
run_list_test app6 ""
}
run_list_test badarg ""