public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Iain Buclaw <ibuclaw@gdcproject.org>
To: gcc-patches@gcc.gnu.org
Subject: [GCC-12][committed] d: Fix D lexer sometimes fails to compile code read from stdin
Date: Tue, 31 May 2022 18:35:18 +0200	[thread overview]
Message-ID: <20220531163518.804065-1-ibuclaw@gdcproject.org> (raw)

Hi,

As of gdc-12, the lexer expects there 4 bytes of zero padding at the end
of the source buffer to mark the end of input.  Sometimes when reading
from stdin, the data at the end of input is garbage rather than zeroes.
Fix that by explicitly calling memset past the end of the buffer.

Bootstrapped and regression tested on x86_64-linux-gnu, committed to
mainline and backported to the releases/gcc-12 branch.

Regards,
Iain.
---
	PR d/105544

gcc/d/ChangeLog:

	* d-lang.cc (d_parse_file): Zero padding past the end of the stdin
	buffer so the D lexer has a sentinel to stop parsing at.
---
 gcc/d/d-lang.cc | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index ef0fe0b8adb..b7c8685f779 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -1077,6 +1077,10 @@ d_parse_file (void)
 				      global.params.dihdr.doOutput);
 	  modules.push (m);
 
+	  /* Zero the padding past the end of the buffer so the D lexer has a
+	     sentinel.  The lexer only reads up to 4 bytes at a time.  */
+	  memset (buffer + len, '\0', 16);
+
 	  /* Overwrite the source file for the module, the one created by
 	     Module::create would have a forced a `.d' suffix.  */
 	  m->src.length = len;
-- 
2.34.1


                 reply	other threads:[~2022-05-31 16:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220531163518.804065-1-ibuclaw@gdcproject.org \
    --to=ibuclaw@gdcproject.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).