From patchwork Tue May 31 16:35:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1637496 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=XmPb9e/Y; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LCHxP3PxZz9s1l for ; Wed, 1 Jun 2022 02:37:13 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95C06395B450 for ; Tue, 31 May 2022 16:37:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95C06395B450 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1654015031; bh=/7MvJ7QVrB92KhQP9FOZHZNOHqYSlYoCMen4ywwAEvg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=XmPb9e/Yr6RtgJpXEmHlehZEU0xiqBXt1y+7THAUPeyJxZ0FUSoiXH7oWmuFvUuzU xYrB/wGm5TVXjB8rhL0Jx8tVJdFKguMfewU1tCRQYTrHBkhNl5jdxS4XMNeQNZmcNH zhFvEUnXeoRGX2Nh5xOt0vkKHUYpRuteQ74+arjw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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) 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 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-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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;