[binutils-gdb] gas: maintain line numbers correctly after #APP / #NO_APP

Jan Beulich jbeulich@sourceware.org
Mon Aug 5 14:30:16 GMT 2024


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b43f37b77fd5d47466c7f35ec9acde68908d7aeb

commit b43f37b77fd5d47466c7f35ec9acde68908d7aeb
Author: Jan Beulich <jbeulich@suse.com>
Date:   Mon Aug 5 16:29:54 2024 +0200

    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.

Diff:
---
 gas/input-scrub.c                   | 31 ++++++++++++++++++++++++-------
 gas/read.c                          |  4 ++--
 gas/sb.h                            |  1 +
 gas/testsuite/gas/macros/app6.l     |  7 +++++++
 gas/testsuite/gas/macros/app6.s     | 11 +++++++++++
 gas/testsuite/gas/macros/macros.exp |  3 +++
 6 files changed, 48 insertions(+), 9 deletions(-)

diff --git a/gas/input-scrub.c b/gas/input-scrub.c
index 776d15ea087..878edc8fd36 100644
--- a/gas/input-scrub.c
+++ b/gas/input-scrub.c
@@ -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)
diff --git a/gas/read.c b/gas/read.c
index 78551937ccd..ba31f8de53e 100644
--- 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;
diff --git a/gas/sb.h b/gas/sb.h
index 2507d35e1e2..9c60f71dee5 100644
--- 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);
 
diff --git a/gas/testsuite/gas/macros/app6.l b/gas/testsuite/gas/macros/app6.l
new file mode 100644
index 00000000000..6541fda1ec4
--- /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
diff --git a/gas/testsuite/gas/macros/app6.s b/gas/testsuite/gas/macros/app6.s
new file mode 100644
index 00000000000..a88ba43172f
--- /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"
diff --git a/gas/testsuite/gas/macros/macros.exp b/gas/testsuite/gas/macros/macros.exp
index 69914f72e42..bb5d4abf25b 100644
--- 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-cvs mailing list