From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1386) id 111FC3858D1E; Tue, 14 Feb 2023 07:35:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 111FC3858D1E Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jan Beulich To: bfd-cvs@sourceware.org Subject: [binutils-gdb] gas: improve interaction between read_a_source_file() and s_linefile() X-Act-Checkin: binutils-gdb X-Git-Author: Jan Beulich X-Git-Refname: refs/heads/master X-Git-Oldrev: f54cd6441de5c057b43ea1501c1b075984067e7c X-Git-Newrev: 7545aa2dd2eb85a852f978dc0d93b3deb6f52536 Message-Id: <20230214073513.111FC3858D1E@sourceware.org> Date: Tue, 14 Feb 2023 07:35:13 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Feb 2023 07:35:13 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D7545aa2dd2eb= 85a852f978dc0d93b3deb6f52536 commit 7545aa2dd2eb85a852f978dc0d93b3deb6f52536 Author: Jan Beulich Date: Tue Feb 14 08:34:03 2023 +0100 gas: improve interaction between read_a_source_file() and s_linefile() =20 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. =20 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. Diff: --- gas/macro.c | 2 +- gas/read.c | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/gas/macro.c b/gas/macro.c index 763bafbdc3d..f9f2d63e9f7 100644 --- a/gas/macro.c +++ b/gas/macro.c @@ -265,7 +265,7 @@ buffer_and_nest (const char *from, const char *to, sb *= ptr, { char saved_eol_char =3D ptr->ptr[ptr->len]; =20 - ptr->ptr[ptr->len] =3D '\0'; + ptr->ptr[ptr->len] =3D '\n'; temp_ilp (ptr->ptr + i + 8); s_linefile (0); restore_ilp (); diff --git a/gas/read.c b/gas/read.c index 9f6a7007ebf..f1099cba1a3 100644 --- a/gas/read.c +++ b/gas/read.c @@ -2049,18 +2049,22 @@ s_linefile (int ignore ATTRIBUTE_UNUSED) =20 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] =3D=3D '\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 (); } =20 /* Handle the .end pseudo-op. Actually, the real work is done in