From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [IPv6:2001:67c:2050:0:465::202]) by sourceware.org (Postfix) with ESMTPS id D4748395B408 for ; Tue, 31 May 2022 16:35:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D4748395B408 Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4LCHvC5wnnz9t1S; Tue, 31 May 2022 18:35:19 +0200 (CEST) From: Iain Buclaw 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 Message-Id: <20220531163518.804065-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 May 2022 16:35:25 -0000 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