public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gas: improve interaction between read_a_source_file() and s_linefile()
@ 2023-02-13  8:15 Jan Beulich
  2023-02-13 10:31 ` Alan Modra
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Beulich @ 2023-02-13  8:15 UTC (permalink / raw)
  To: Binutils; +Cc: Alan Modra

read_a_source_file() would bump line numbers only when seeing a newline,
whereas is_end_of_line[] indicates further end-of-line characters, in
particular the nul character. s_linefile() attempts to compensate for
the bump, but was too aggressive with this so far: It should only adjust
when a newline ends the line. To facilitate such a check, the check for
nothing else on the line needs to move ahead, which luckily is easily
possible: The relevant two conditions match, and the function can
simply return from the body of that earlier instance of the conditional.

The more strict treatment in s_linefile() then requires an adjustment
to buffer_and_nest()'s invocation of the function: The line terminator
now needs to be a newline, not nul.

--- a/gas/macro.c
+++ b/gas/macro.c
@@ -265,7 +265,7 @@ buffer_and_nest (const char *from, const
 	    {
 	      char saved_eol_char = ptr->ptr[ptr->len];
 
-	      ptr->ptr[ptr->len] = '\0';
+	      ptr->ptr[ptr->len] = '\n';
 	      temp_ilp (ptr->ptr + i + 8);
 	      s_linefile (0);
 	      restore_ilp ();
--- a/gas/read.c
+++ b/gas/read.c
@@ -2047,18 +2047,22 @@ s_linefile (int ignore ATTRIBUTE_UNUSED)
 
       if (file || flags)
 	{
-	  linenum--;
+	  demand_empty_rest_of_line ();
+
+	  /* read_a_source_file() will bump the line number only if the line
+	     is terminated by '\n'.  */
+	  if (input_line_pointer[-1] == '\n')
+	    linenum--;
+
 	  new_logical_line_flags (file, linenum, flags);
 #ifdef LISTING
 	  if (listing)
 	    listing_source_line (linenum);
 #endif
+	  return;
 	}
     }
-  if (file || flags)
-    demand_empty_rest_of_line ();
-  else
-    ignore_rest_of_line ();
+  ignore_rest_of_line ();
 }
 
 /* Handle the .end pseudo-op.  Actually, the real work is done in

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] gas: improve interaction between read_a_source_file() and s_linefile()
  2023-02-13  8:15 [PATCH] gas: improve interaction between read_a_source_file() and s_linefile() Jan Beulich
@ 2023-02-13 10:31 ` Alan Modra
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2023-02-13 10:31 UTC (permalink / raw)
  To: Jan Beulich; +Cc: Binutils

On Mon, Feb 13, 2023 at 09:15:36AM +0100, Jan Beulich wrote:
> read_a_source_file() would bump line numbers only when seeing a newline,
> whereas is_end_of_line[] indicates further end-of-line characters, in
> particular the nul character. s_linefile() attempts to compensate for
> the bump, but was too aggressive with this so far: It should only adjust
> when a newline ends the line. To facilitate such a check, the check for
> nothing else on the line needs to move ahead, which luckily is easily
> possible: The relevant two conditions match, and the function can
> simply return from the body of that earlier instance of the conditional.
> 
> The more strict treatment in s_linefile() then requires an adjustment
> to buffer_and_nest()'s invocation of the function: The line terminator
> now needs to be a newline, not nul.

Looks good to me, thanks for sorting this out.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-13 10:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-13  8:15 [PATCH] gas: improve interaction between read_a_source_file() and s_linefile() Jan Beulich
2023-02-13 10:31 ` Alan Modra

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).