From patchwork Mon Aug 3 06:22:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1340144 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (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=R0HPlByd; 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 4BKnql3Wwrz9sRN for ; Mon, 3 Aug 2020 16:22:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0DE323851C39; Mon, 3 Aug 2020 06:22:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DE323851C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596435759; bh=ttiDBxJVxhK/oik4BIFE1lYSddr/RN1tdzj+HZ2FnRI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=R0HPlByd5i6NJ9IxfU1UlE7x7Y/axUyU+Gqln812wLOUxuvauWFb4NhZc9ciOs0nJ rjw4Nkl57SKp+V3ttXGqhRcQx+HKAn0GUgqg8p1JpXtjYBVBhrcz8EL1fQ9tcKrs+L 4N/sXgwPbBNwxXOngKY1PhahHruQQ8kx2rzxG4v4= 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 [80.241.56.172]) by sourceware.org (Postfix) with ESMTPS id ACD293857C66 for ; Mon, 3 Aug 2020 06:22:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org ACD293857C66 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4BKnqZ12nQzQlJ1; Mon, 3 Aug 2020 08:22:34 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by gerste.heinlein-support.de (gerste.heinlein-support.de [91.198.250.173]) (amavisd-new, port 10030) with ESMTP id cBpDr0rtkL4H; Mon, 3 Aug 2020 08:22:29 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Merge upstream dmd c2274e56a (PR96250). Date: Mon, 3 Aug 2020 08:22:25 +0200 Message-Id: <20200803062225.481264-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-MBO-SPAM-Probability: 1 X-Rspamd-Score: 0.16 / 15.00 / 15.00 X-Rspamd-Queue-Id: ACF7C1807 X-Rspamd-UID: a22654 X-Spam-Status: No, score=-16.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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.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 c2274e56a, fixing a couple ICE bugs found in the front-end. 1. Fixes an ICE in the front-end if a struct symbol were to appear twice in the compilation unit. 2. Fixes a rejects-valid bug in the front-end where `(symbol)' was being resolved as a `var' expression, instead of `this.var'. Bootstrapped and regression tested on x86_64-linux-gnu, and committed to mainline. Regards Iain. --- gcc/d/ChangeLog: PR d/96250 * dmd/MERGE: Merge upstream dmd c2274e56a. --- gcc/d/dmd/MERGE | 2 +- gcc/d/dmd/dstruct.c | 9 ++++- gcc/d/dmd/expressionsem.c | 10 +++++ gcc/d/dmd/parse.c | 1 + gcc/testsuite/gdc.test/compilable/b9490.d | 39 +++++++++++++++++++ gcc/testsuite/gdc.test/compilable/ice14739.d | 19 +++++++++ .../gdc.test/fail_compilation/fail17492.d | 20 +++++++++- .../gdc.test/fail_compilation/ice21060.d | 15 +++++++ .../imports/ice21060a/package.d | 1 + .../imports/ice21060b/package.d | 5 +++ .../imports/ice21060c/package.d | 1 + .../imports/ice21060d/package.d | 5 +++ gcc/testsuite/gdc.test/runnable/b16278.d | 6 +++ 13 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gdc.test/compilable/b9490.d create mode 100644 gcc/testsuite/gdc.test/compilable/ice14739.d create mode 100644 gcc/testsuite/gdc.test/fail_compilation/ice21060.d create mode 100644 gcc/testsuite/gdc.test/fail_compilation/imports/ice21060a/package.d create mode 100644 gcc/testsuite/gdc.test/fail_compilation/imports/ice21060b/package.d create mode 100644 gcc/testsuite/gdc.test/fail_compilation/imports/ice21060c/package.d create mode 100644 gcc/testsuite/gdc.test/fail_compilation/imports/ice21060d/package.d create mode 100644 gcc/testsuite/gdc.test/runnable/b16278.d diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index b99e9f3353d..daa3e565ff7 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -1,4 +1,4 @@ -8508c4e683f065eb3deab76b610f7fecb3258a8e +c2274e56a3220ea636c6199fd06cd54fcdf6bad9 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/dstruct.c b/gcc/d/dmd/dstruct.c index 86bb6c8aa76..2b87154142c 100644 --- a/gcc/d/dmd/dstruct.c +++ b/gcc/d/dmd/dstruct.c @@ -1206,6 +1206,13 @@ void StructDeclaration::semantic(Scope *sc) } } + if (type->ty == Tstruct && ((TypeStruct *)type)->sym != this) + { + // https://issues.dlang.org/show_bug.cgi?id=19024 + StructDeclaration *sd = ((TypeStruct *)type)->sym; + error("already exists at %s. Perhaps in another function with the same name?", sd->loc.toChars()); + } + if (global.errors != errors) { // The type is no good. @@ -1220,8 +1227,6 @@ void StructDeclaration::semantic(Scope *sc) deferred->semantic2(sc); deferred->semantic3(sc); } - - assert(type->ty != Tstruct || ((TypeStruct *)type)->sym == this); } Dsymbol *StructDeclaration::search(const Loc &loc, Identifier *ident, int flags) diff --git a/gcc/d/dmd/expressionsem.c b/gcc/d/dmd/expressionsem.c index ac6b5bc81f3..9f21dabb7e4 100644 --- a/gcc/d/dmd/expressionsem.c +++ b/gcc/d/dmd/expressionsem.c @@ -812,6 +812,16 @@ public: exp->type->resolve(exp->loc, sc, &e, &t, &s, true); if (e) { + // `(Type)` is actually `(var)` so if `(var)` is a member requiring `this` + // then rewrite as `(this.var)` in case it would be followed by a DotVar + // to fix https://issues.dlang.org/show_bug.cgi?id=9490 + VarExp *ve = e->isVarExp(); + if (ve && ve->var && exp->parens && !ve->var->isStatic() && !(sc->stc & STCstatic) && + sc->func && sc->func->needThis() && ve->var->toParent2()->isAggregateDeclaration()) + { + // printf("apply fix for issue 9490: add `this.` to `%s`...\n", e->toChars()); + e = new DotVarExp(exp->loc, new ThisExp(exp->loc), ve->var, false); + } //printf("e = %s %s\n", Token::toChars(e->op), e->toChars()); e = semantic(e, sc); } diff --git a/gcc/d/dmd/parse.c b/gcc/d/dmd/parse.c index f4cd28ed2fb..d1017ac462c 100644 --- a/gcc/d/dmd/parse.c +++ b/gcc/d/dmd/parse.c @@ -7531,6 +7531,7 @@ Expression *Parser::parseUnaryExp() return NULL; } e = new TypeExp(loc, t); + e->parens = 1; e = parsePostExp(e); } else diff --git a/gcc/testsuite/gdc.test/compilable/b9490.d b/gcc/testsuite/gdc.test/compilable/b9490.d new file mode 100644 index 00000000000..d0148b1a738 --- /dev/null +++ b/gcc/testsuite/gdc.test/compilable/b9490.d @@ -0,0 +1,39 @@ +// https://issues.dlang.org/show_bug.cgi?id=9490 +class A +{ + int[1] arr; + + this() + { + assert(arr.length); + assert((arr).length); + } +} + +class C +{ + struct Foo { int a; void funcToo(){} } + Foo foo; + + auto get(){return foo;} + + void test() + { + // Error: need 'this' to access member a + (foo).a = 1; + (foo).funcToo(); + (get()).a = 2; + } +} + +struct S { int i; } +struct S1 { S s; } +void f(int) { } + +void main() +{ + S1 s1; + f(s1.s.tupleof); // OK + f((s1.s).tupleof); // Error: need 'this' to access member s +} + diff --git a/gcc/testsuite/gdc.test/compilable/ice14739.d b/gcc/testsuite/gdc.test/compilable/ice14739.d new file mode 100644 index 00000000000..cc90da6342e --- /dev/null +++ b/gcc/testsuite/gdc.test/compilable/ice14739.d @@ -0,0 +1,19 @@ +// REQUIRED_ARGS: -o- + +void main(string[] args) +{ + immutable int a; + immutable int b; + S!a sa; + S!b sb; + C!a ca; + C!b cb; +} + +struct S(alias a) +{ +} + +class C(alias a) +{ +} diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail17492.d b/gcc/testsuite/gdc.test/fail_compilation/fail17492.d index e45c2e59359..80e9e2a2c4a 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/fail17492.d +++ b/gcc/testsuite/gdc.test/fail_compilation/fail17492.d @@ -1,6 +1,7 @@ /* TEST_OUTPUT: --- -fail_compilation/fail17492.d(19): Error: class fail17492.C.testE.I already exists at fail_compilation/fail17492.d(12). Perhaps in another function with the same name? +fail_compilation/fail17492.d(20): Error: class `fail17492.C.testE.I` already exists at fail17492.d(13). Perhaps in another function with the same name? +fail_compilation/fail17492.d(37): Error: struct `fail17492.S.testE.I` already exists at fail17492.d(30). Perhaps in another function with the same name? --- https://issues.dlang.org/show_bug.cgi?id=17492 */ @@ -21,3 +22,20 @@ class C } } } + +class S +{ + void testE() + { + struct I + { + } + } + + void testE() + { + struct I + { + } + } +} diff --git a/gcc/testsuite/gdc.test/fail_compilation/ice21060.d b/gcc/testsuite/gdc.test/fail_compilation/ice21060.d new file mode 100644 index 00000000000..d33889cee3d --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/ice21060.d @@ -0,0 +1,15 @@ +/* +EXTRA_FILES: imports/ice21060a/package.d imports/ice21060b/package.d imports/ice21060c/package.d imports/ice21060d/package.d +TEST_OUTPUT: +--- +fail_compilation/imports/ice21060b/package.d(3): Error: struct `imports.ice21060d.P21060` already exists at fail_compilation/imports/ice21060d/package.d(3). Perhaps in another function with the same name? +--- +*/ +struct S21060 +{ + void print() + { + import imports.ice21060a; + import imports.ice21060b; + } +} diff --git a/gcc/testsuite/gdc.test/fail_compilation/imports/ice21060a/package.d b/gcc/testsuite/gdc.test/fail_compilation/imports/ice21060a/package.d new file mode 100644 index 00000000000..b046aebe1d8 --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/imports/ice21060a/package.d @@ -0,0 +1 @@ +import imports.ice21060c; diff --git a/gcc/testsuite/gdc.test/fail_compilation/imports/ice21060b/package.d b/gcc/testsuite/gdc.test/fail_compilation/imports/ice21060b/package.d new file mode 100644 index 00000000000..a806fd08a6a --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/imports/ice21060b/package.d @@ -0,0 +1,5 @@ +module imports.ice21060d; + +struct P21060 +{ +} diff --git a/gcc/testsuite/gdc.test/fail_compilation/imports/ice21060c/package.d b/gcc/testsuite/gdc.test/fail_compilation/imports/ice21060c/package.d new file mode 100644 index 00000000000..cc6f74ec6bb --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/imports/ice21060c/package.d @@ -0,0 +1 @@ +import imports.ice21060d; diff --git a/gcc/testsuite/gdc.test/fail_compilation/imports/ice21060d/package.d b/gcc/testsuite/gdc.test/fail_compilation/imports/ice21060d/package.d new file mode 100644 index 00000000000..a806fd08a6a --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/imports/ice21060d/package.d @@ -0,0 +1,5 @@ +module imports.ice21060d; + +struct P21060 +{ +} diff --git a/gcc/testsuite/gdc.test/runnable/b16278.d b/gcc/testsuite/gdc.test/runnable/b16278.d new file mode 100644 index 00000000000..a0a422daf6b --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/b16278.d @@ -0,0 +1,6 @@ +// REQUIRED_ARGS: -main +class A() +{ + static struct S { A a; } +} +enum e = is(A!());