]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
d: Fix D lexer sometimes fails to compile code read from stdin
authorIain Buclaw <ibuclaw@gdcproject.org>
Tue, 31 May 2022 12:45:02 +0000 (14:45 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Tue, 31 May 2022 16:33:31 +0000 (18:33 +0200)
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)

gcc/d/d-lang.cc

index dc8560f799a36a2afa58db852b10005bc8626391..f078f24fc5e93d0761254f0f41f00a1b43d52ddd 100644 (file)
@@ -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;