From patchwork Wed Nov 18 09:25:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1402138 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org 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=X8q3bw6/; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4Cbcqd4640z9sT6 for ; Wed, 18 Nov 2020 20:25:49 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 01E71383F85C; Wed, 18 Nov 2020 09:25:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01E71383F85C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1605691547; bh=2ce1QZuM899L2Dje5YvXR4RpgMKGBTdKmKCvdQCk3OU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=X8q3bw6/ktjhBjbPqy9HDTU4xnXIczZ/LvejkrV9eEVLH0myhKa8LHfpXTm1kGgRP AsEu9OwJqAE4UtsLsPpGqkXapV0tyXioxjqmKnMgX/k+CynoQwZ0uq1uuAPorlJA/x Iy5KyATynvloi2i+Z3WoqNchPqSzQ7ez0Y7LFc+0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [IPv6:2001:67c:2050::465:102]) by sourceware.org (Postfix) with ESMTPS id 5EF29385800A for ; Wed, 18 Nov 2020 09:25:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5EF29385800A Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (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-102.mailbox.org (Postfix) with ESMTPS id 4CbcqV20jCzQkm3; Wed, 18 Nov 2020 10:25:42 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by gerste.heinlein-support.de (gerste.heinlein-support.de [91.198.250.173]) (amavisd-new, port 10030) with ESMTP id tsS0oBPxzBrI; Wed, 18 Nov 2020 10:25:37 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] d: Fix a couple of ICEs found in the dmd front-end (PR97842) Date: Wed, 18 Nov 2020 10:25:35 +0100 Message-Id: <20201118092535.3907639-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-MBO-SPAM-Probability: X-Rspamd-Score: -0.75 / 15.00 / 15.00 X-Rspamd-Queue-Id: DADED171F X-Rspamd-UID: 075709 X-Spam-Status: No, score=-15.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch merges the D front-end implementation with upstream dmd b6a779e49, fixing two segmentation faults. One when encountering an incomplete static if, and another when resolving typeof() expressions whilst gagging is on. Bootstrapped and regression tested on x86_64-linux-gnu, committed to mainline, and backported to the release/gcc-10 branch. Regards Iain. --- gcc/d/ChangeLog: PR d/97842 * dmd/MERGE: Merge upstream dmd b6a779e49 --- gcc/d/dmd/MERGE | 2 +- gcc/d/dmd/cond.c | 4 ++ gcc/d/dmd/mtype.c | 6 +++ .../gdc.test/fail_compilation/fail18970.d | 37 +++++++++++++++++++ .../fail_compilation/imports/test21164a.d | 9 +++++ .../fail_compilation/imports/test21164b.d | 4 ++ .../fail_compilation/imports/test21164c.d | 10 +++++ .../fail_compilation/imports/test21164d.d | 9 +++++ .../gdc.test/fail_compilation/test21164.d | 13 +++++++ 9 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gdc.test/fail_compilation/fail18970.d create mode 100644 gcc/testsuite/gdc.test/fail_compilation/imports/test21164a.d create mode 100644 gcc/testsuite/gdc.test/fail_compilation/imports/test21164b.d create mode 100644 gcc/testsuite/gdc.test/fail_compilation/imports/test21164c.d create mode 100644 gcc/testsuite/gdc.test/fail_compilation/imports/test21164d.d create mode 100644 gcc/testsuite/gdc.test/fail_compilation/test21164.d diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index e2a0bab2e4a..b00cb8262a7 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -1,4 +1,4 @@ -95044d8e45a4320f07d9c75b4eb30e55688a8195 +b6a779e49a3bba8be6272e6730e14cbb6293ef77 The first line of this file holds the git revision number of the last merge done from the dlang/dmd repository. diff --git a/gcc/d/dmd/cond.c b/gcc/d/dmd/cond.c index beda133ffdb..9f76e83238e 100644 --- a/gcc/d/dmd/cond.c +++ b/gcc/d/dmd/cond.c @@ -705,6 +705,10 @@ int StaticIfCondition::include(Scope *sc) sc = sc->push(sc->scopesym); bool errors = false; + + if (!exp) + goto Lerror; + bool result = evalStaticCondition(sc, exp, exp, errors); sc->pop(); diff --git a/gcc/d/dmd/mtype.c b/gcc/d/dmd/mtype.c index bc66be028c1..6f0195af305 100644 --- a/gcc/d/dmd/mtype.c +++ b/gcc/d/dmd/mtype.c @@ -7418,6 +7418,12 @@ void TypeTypeof::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol //printf("TypeTypeof::resolve(sc = %p, idents = '%s')\n", sc, toChars()); //static int nest; if (++nest == 50) *(char*)0=0; + if (sc == NULL) + { + *pt = Type::terror; + error(loc, "Invalid scope."); + return; + } if (inuse) { inuse = 2; diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail18970.d b/gcc/testsuite/gdc.test/fail_compilation/fail18970.d new file mode 100644 index 00000000000..846a5782d7d --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/fail18970.d @@ -0,0 +1,37 @@ +/* +TEST_OUTPUT: +--- +fail_compilation/fail18970.d(22): Error: no property `y` for type `fail18970.S` +fail_compilation/fail18970.d(29): Error: no property `yyy` for type `fail18970.S2` +--- +*/ + +// https://issues.dlang.org/show_bug.cgi?id=18970 + +struct S +{ + auto opDispatch(string name)(int) + { + alias T = typeof(x); + static assert(!is(T.U)); + return 0; + } +} +void f() +{ + S().y(1); +} + +struct S2 +{ + this(int) + { + this.yyy; + } + + auto opDispatch(string name)() + { + alias T = typeof(x); + static if(is(T.U)) {} + } +} diff --git a/gcc/testsuite/gdc.test/fail_compilation/imports/test21164a.d b/gcc/testsuite/gdc.test/fail_compilation/imports/test21164a.d new file mode 100644 index 00000000000..e5fcd43595e --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/imports/test21164a.d @@ -0,0 +1,9 @@ +struct D(E) +{ + void G() { + import imports.test21164d; + I; + } + +} + diff --git a/gcc/testsuite/gdc.test/fail_compilation/imports/test21164b.d b/gcc/testsuite/gdc.test/fail_compilation/imports/test21164b.d new file mode 100644 index 00000000000..ece5476654e --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/imports/test21164b.d @@ -0,0 +1,4 @@ +import imports.test21164c; +enum N = O(); +alias Q = R!(N, S); + diff --git a/gcc/testsuite/gdc.test/fail_compilation/imports/test21164c.d b/gcc/testsuite/gdc.test/fail_compilation/imports/test21164c.d new file mode 100644 index 00000000000..21a252f5036 --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/imports/test21164c.d @@ -0,0 +1,10 @@ +enum S = 1; + +struct O +{ +} + +struct R(O U, int W) +{ +} + diff --git a/gcc/testsuite/gdc.test/fail_compilation/imports/test21164d.d b/gcc/testsuite/gdc.test/fail_compilation/imports/test21164d.d new file mode 100644 index 00000000000..08f83ea91f7 --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/imports/test21164d.d @@ -0,0 +1,9 @@ +auto AB() +{ +static if} + +auto I() +{ +AB; +} + diff --git a/gcc/testsuite/gdc.test/fail_compilation/test21164.d b/gcc/testsuite/gdc.test/fail_compilation/test21164.d new file mode 100644 index 00000000000..f42c4bc9d15 --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/test21164.d @@ -0,0 +1,13 @@ +/* +TEST_OUTPUT: +--- +fail_compilation/imports/test21164d.d(3): Error: (expression) expected following `static if` +fail_compilation/imports/test21164d.d(3): Error: found `}` instead of statement +fail_compilation/test21164.d(11): Error: template instance `test21164a.D!(R!(O(), 1))` error instantiating +--- +*/ +import imports.test21164a; +import imports.test21164b; +auto GB(D!Q) +{ +}