public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] gas: recognize #APP at start-of-physical-line only
@ 2024-08-05 14:30 Jan Beulich
  0 siblings, 0 replies; only message in thread
From: Jan Beulich @ 2024-08-05 14:30 UTC (permalink / raw)
  To: binutils-cvs

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

commit 1068b74548858fe9c8ed17f0bba8b136111fbec9
Author: Jan Beulich <jbeulich@suse.com>
Date:   Mon Aug 5 16:28:43 2024 +0200

    gas: recognize #APP at start-of-physical-line only
    
    It's not valid to recognize it after mere line separators (often
    semicolon) or after labels, let alone after tc_unrecognized_line()
    perhaps having parsed off parts of a line. It shouldn't even be
    preceded by whitespace, aiui.
    
    However, keep ignoring line comments as before, for backwards
    compatibility.

Diff:
---
 gas/read.c | 106 ++++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 60 insertions(+), 46 deletions(-)

diff --git a/gas/read.c b/gas/read.c
index adb4759a96b..c6fb3dc5a1d 100644
--- a/gas/read.c
+++ b/gas/read.c
@@ -900,7 +900,7 @@ read_a_source_file (const char *name)
 #endif
       while (input_line_pointer < buffer_limit)
 	{
-	  bool was_new_line;
+	  char was_new_line;
 	  /* We have more of this buffer to parse.  */
 
 	  /* We now have input_line_pointer->1st char of next line.
@@ -953,6 +953,59 @@ read_a_source_file (const char *name)
 		listing_newline (NULL);
 	    }
 #endif
+
+	  next_char = *input_line_pointer;
+	  if (was_new_line == 1 && next_char
+	      && strchr (line_comment_chars, next_char))
+	    {
+	      /* Its a comment.  Check for APP followed by NO_APP.  */
+	      sb sbuf;
+	      char *ends;
+	      size_t len;
+
+	      s = input_line_pointer + 1;
+	      if (!startswith (s, "APP\n"))
+		{
+		  /* We ignore it.  Note: Not ignore_rest_of_line ()!  */
+		  while (s <= buffer_limit)
+		    if (is_end_of_line (*s++))
+		      break;
+		  input_line_pointer = s;
+		  continue;
+		}
+	      bump_line_counters ();
+	      s += 4;
+
+	      ends = strstr (s, "#NO_APP\n");
+	      len = ends ? ends - s : buffer_limit - s;
+
+	      sb_build (&sbuf, len + 100);
+	      sb_add_buffer (&sbuf, s, len);
+	      if (!ends)
+		{
+		  /* The end of the #APP wasn't in this buffer.  We
+		     keep reading in buffers until we find the #NO_APP
+		     that goes with this #APP  There is one.  The specs
+		     guarantee it...  */
+		  do
+		    {
+		      buffer_limit = input_scrub_next_buffer (&buffer);
+		      if (!buffer_limit)
+			break;
+		      ends = strstr (buffer, "#NO_APP\n");
+		      len = ends ? ends - buffer : buffer_limit - buffer;
+		      sb_add_buffer (&sbuf, buffer, len);
+		    }
+		  while (!ends);
+		}
+
+	      input_line_pointer = ends ? ends + 8 : NULL;
+	      input_scrub_include_sb (&sbuf, input_line_pointer, expanding_none);
+	      sb_kill (&sbuf);
+	      buffer_limit = input_scrub_next_buffer (&input_line_pointer);
+	      continue;
+	    }
+
 	  if (was_new_line)
 	    {
 	      line_label = NULL;
@@ -1316,51 +1369,12 @@ read_a_source_file (const char *name)
 	    }
 
 	  if (next_char && strchr (line_comment_chars, next_char))
-	    {			/* Its a comment.  Better say APP or NO_APP.  */
-	      sb sbuf;
-	      char *ends;
-	      size_t len;
-
-	      s = input_line_pointer;
-	      if (!startswith (s, "APP\n"))
-		{
-		  /* We ignore it.  Note: Not ignore_rest_of_line ()!  */
-		  while (s <= buffer_limit)
-		    if (is_end_of_line (*s++))
-		      break;
-		  input_line_pointer = s;
-		  continue;
-		}
-	      bump_line_counters ();
-	      s += 4;
-
-	      ends = strstr (s, "#NO_APP\n");
-	      len = ends ? ends - s : buffer_limit - s;
-
-	      sb_build (&sbuf, len + 100);
-	      sb_add_buffer (&sbuf, s, len);
-	      if (!ends)
-		{
-		  /* The end of the #APP wasn't in this buffer.  We
-		     keep reading in buffers until we find the #NO_APP
-		     that goes with this #APP  There is one.  The specs
-		     guarantee it...  */
-		  do
-		    {
-		      buffer_limit = input_scrub_next_buffer (&buffer);
-		      if (!buffer_limit)
-			break;
-		      ends = strstr (buffer, "#NO_APP\n");
-		      len = ends ? ends - buffer : buffer_limit - buffer;
-		      sb_add_buffer (&sbuf, buffer, len);
-		    }
-		  while (!ends);
-		}
-
-	      input_line_pointer = ends ? ends + 8 : NULL;
-	      input_scrub_include_sb (&sbuf, input_line_pointer, expanding_none);
-	      sb_kill (&sbuf);
-	      buffer_limit = input_scrub_next_buffer (&input_line_pointer);
+	    {
+	      /* Its a comment, ignore it.  Note: Not ignore_rest_of_line ()!  */
+	      while (s <= buffer_limit)
+		if (is_end_of_line (*s++))
+		  break;
+	      input_line_pointer = s;
 	      continue;
 	    }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-08-05 14:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-05 14:30 [binutils-gdb] gas: recognize #APP at start-of-physical-line only Jan Beulich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).