public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-8439] d: Fix D lexer sometimes fails to compile code read from stdin
@ 2022-05-31 16:33 Iain Buclaw
  0 siblings, 0 replies; only message in thread
From: Iain Buclaw @ 2022-05-31 16:33 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f106ef53024cc464ae446189fbad373caaff058e

commit r12-8439-gf106ef53024cc464ae446189fbad373caaff058e
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Tue May 31 14:45:02 2022 +0200

    d: Fix D lexer sometimes fails to compile code read from stdin
    
    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.
    
            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.
    
    (cherry picked from commit a0bc7fd42136f124726985b1ab4dcde739cd260e)

Diff:
---
 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 dc8560f799a..f078f24fc5e 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -1082,6 +1082,10 @@ d_parse_file (void)
 				      global.params.doHdrGeneration);
 	  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;


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

only message in thread, other threads:[~2022-05-31 16:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-31 16:33 [gcc r12-8439] d: Fix D lexer sometimes fails to compile code read from stdin Iain Buclaw

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