]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas: maintain line numbers correctly after #APP / #NO_APP
authorJan Beulich <jbeulich@suse.com>
Mon, 5 Aug 2024 14:29:54 +0000 (16:29 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 5 Aug 2024 14:29:54 +0000 (16:29 +0200)
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.

gas/input-scrub.c
gas/read.c
gas/sb.h
gas/testsuite/gas/macros/app6.l [new file with mode: 0644]
gas/testsuite/gas/macros/app6.s [new file with mode: 0644]
gas/testsuite/gas/macros/macros.exp

index 776d15ea0873816771b3b5f22d89b9a400e85e87..878edc8fd3672ab62ece60d58e869913de7ce71f 100644 (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)
index 78551937ccd173678fa2b3d667ffcc4223968dc8..ba31f8de53e4af58a6912e8b0928fde66d3ef9c0 100644 (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;
index 2507d35e1e26b8cfdef55e231fadd2ec0afb0e80..9c60f71dee5365e969c3af966295136077a61835 100644 (file)
--- 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 (file)
index 0000000..6541fda
--- /dev/null
@@ -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 (file)
index 0000000..a88ba43
--- /dev/null
@@ -0,0 +1,11 @@
+#NO_APP
+       .data
+       .warning "first"
+#APP
+       .warning "second"
+       ;#NO_APP
+       .warning "third"
+       ;#APP
+       .warning "fourth"
+#NO_APP
+       .warning "fifth"
index 69914f72e42f3e3e992b005691d9f349c8c7a3f9..bb5d4abf25b8e3977dba52b27dd54ed8bc2df5b7 100644 (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 ""