From patchwork Thu Jul 29 15:22:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1511325 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=) Authentication-Results: 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=rbbtYMAK; dkim-atps=neutral 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 (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GbDpZ6LM4z9sRf for ; Fri, 30 Jul 2021 01:24:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9743B39B5D1D for ; Thu, 29 Jul 2021 15:24:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9743B39B5D1D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1627572260; bh=VizM+MNgr8OPLE6a/BgshXK2ZkuQYo03ix8b0VqwYTg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=rbbtYMAKKLmfJmRT5IcN9zxoDAFaFZzzpHo0JmX9mo2Qp1a+BsbEane6pVB/CszoC UtfNWZF8LMg3BlP3EkiQxkOOV/8FIyPOFI9cLYpiVUx8Q538bzWPXhW4wFVdZx7mxL gKCv1G1sqj0NDzeya5Qw0Xp49P5HKIBF4mKEAbfw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by sourceware.org (Postfix) with ESMTPS id A11E039B5D16 for ; Thu, 29 Jul 2021 15:22:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A11E039B5D16 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (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-101.mailbox.org (Postfix) with ESMTPS id 4GbDmh3fVszQjgJ; Thu, 29 Jul 2021 17:22:44 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter06.heinlein-hosting.de (spamfilter06.heinlein-hosting.de [80.241.56.125]) (amavisd-new, port 10030) with ESMTP id fawQESE5OA1r; Thu, 29 Jul 2021 17:22:41 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Remove generated D header files on error (PR101657) Date: Thu, 29 Jul 2021 17:22:39 +0200 Message-Id: <20210729152239.273234-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6790518B3 X-Rspamd-UID: 26fa68 X-Spam-Status: No, score=-15.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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, This patch adds a clean-up for removing any generated DI header files created before semantic analysis was ran. If an error occurs later during compilation, remember that we generated the headers, so that they can be removed before exit. Bootstrapped and regression tested on x86_64-linux-gnu/-mx32/-m32, and committed to mainline. Regards, Iain --- gcc/d/ChangeLog: PR d/101657 * d-lang.cc (d_parse_file): Remove generated D header files on error. gcc/testsuite/ChangeLog: PR d/101657 * gdc.dg/pr101657.d: New test. --- gcc/d/d-lang.cc | 19 +++++++++++++++++++ gcc/testsuite/gdc.dg/pr101657.d | 14 ++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 gcc/testsuite/gdc.dg/pr101657.d diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc index 6ad3823d910..ac0945b1f34 100644 --- a/gcc/d/d-lang.cc +++ b/gcc/d/d-lang.cc @@ -1000,6 +1000,10 @@ d_parse_file (void) } } + /* If an error occurs later during compilation, remember that we generated + the headers, so that they can be removed before exit. */ + bool dump_headers = false; + if (global.errors) goto had_errors; @@ -1019,6 +1023,8 @@ d_parse_file (void) genhdrfile (m); } + + dump_headers = true; } if (global.errors) @@ -1243,6 +1249,19 @@ d_parse_file (void) exit with an error status. */ errorcount += (global.errors + global.warnings); + /* Remove generated .di files on error. */ + if (errorcount && dump_headers) + { + for (size_t i = 0; i < modules.length; i++) + { + Module *m = modules[i]; + if (d_option.fonly && m != Module::rootModule) + continue; + + remove (m->hdrfile->toChars ()); + } + } + /* Write out globals. */ d_finish_compilation (vec_safe_address (global_declarations), vec_safe_length (global_declarations)); diff --git a/gcc/testsuite/gdc.dg/pr101657.d b/gcc/testsuite/gdc.dg/pr101657.d new file mode 100644 index 00000000000..0d77c36f030 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr101657.d @@ -0,0 +1,14 @@ +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101657 +// { dg-do compile } +// { dg-additional-options "-H" } + +void fun101657() +{ + fail; // { dg-error "undefined identifier 'fail'" } +} + +// { dg-final { if ![file exists pr101657.di] \{ } } +// { dg-final { pass "gdc.dg/pr101657.d (file exists pr101657.di)" } } +// { dg-final { \} else \{ } } +// { dg-final { fail "gdc.dg/pr101657.d (file exists pr101657.di)" } } +// { dg-final { \} } }