[PATCH 3/3] gas: maintain line numbers correctly after #APP / #NO_APP
Jan Beulich
jbeulich@suse.com
Fri Jul 26 07:34:22 GMT 2024
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.
---
The two from_sb_expansion expansion checks around the updating of
macro_nest likely could do with also covering expanding_none.
--- a/gas/input-scrub.c
+++ b/gas/input-scrub.c
@@ -194,10 +194,23 @@ input_scrub_pop (struct input_save *save
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 *
{
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)
--- a/gas/read.c
+++ b/gas/read.c
@@ -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;
--- a/gas/sb.h
+++ b/gas/sb.h
@@ -69,6 +69,7 @@ enum expansion {
expanding_none,
expanding_repeat,
expanding_macro,
+ expanding_app,
};
extern void input_scrub_include_sb (sb *, char *, enum expansion);
--- /dev/null
+++ b/gas/testsuite/gas/macros/app6.l
@@ -0,0 +1,7 @@
+.*: Assembler messages:
+.*:3: Warning: .*first.*
+.*:5: Warning: .*second.*
+.*:7: Warning: .*third.*
+.*:9: Warning: .*fourth.*
+.*:11: Warning: .*fifth.*
+#pass
--- /dev/null
+++ b/gas/testsuite/gas/macros/app6.s
@@ -0,0 +1,11 @@
+#NO_APP
+ .data
+ .warning "first"
+#APP
+ .warning "second"
+ ;#NO_APP
+ .warning "third"
+ ;#APP
+ .warning "fourth"
+#NO_APP
+ .warning "fifth"
--- a/gas/testsuite/gas/macros/macros.exp
+++ b/gas/testsuite/gas/macros/macros.exp
@@ -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 ""
More information about the Binutils
mailing list