From patchwork Mon Oct 12 10:17:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1380798 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=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=cVv9dUew; 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 4C8vkm664Sz9sT6 for ; Mon, 12 Oct 2020 21:17:52 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 58D62386F000; Mon, 12 Oct 2020 10:17:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 58D62386F000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1602497870; bh=wPY+cgmmkDDWyIPMAwM8Fxm6xC9i/TepNABhO5M1Vlo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=cVv9dUewIcWVCrQ8Y34zhpvs5iyeBnMhxk54Zt1S2UHE0FVBF+tcWzn69rK9Qsyak WFAMZhvWaTNZWEJXqO1zRQF9nNearB4w+bKQsc70OHxaUWYjN+GeJJWjkBIaX0MiU2 2FRmo4Ufmb4YVGhk6leT1gkutJ2UPXvTGKvAt3vM= 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 2DCF9386F000 for ; Mon, 12 Oct 2020 10:17:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2DCF9386F000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2: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 4C8vkf0RBLzKmZj; Mon, 12 Oct 2020 12:17:46 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id WB6lscVP7vvl; Mon, 12 Oct 2020 12:17:39 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Fix alias protection being ignored if used before declaration. Date: Mon, 12 Oct 2020 12:17:38 +0200 Message-Id: <20201012101738.3306493-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-MBO-SPAM-Probability: X-Rspamd-Score: -0.33 / 15.00 / 15.00 X-Rspamd-Queue-Id: CB40E1700 X-Rspamd-UID: 9b1df8 X-Spam-Status: No, score=-15.4 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 3a9790525. Fixes a symbol resolver bug where a private alias becomes public if used before its declaration. Bootstrapped and regression tested on x86_64-linux-gnu, and committed to mainline, and backported to the gcc-10 and gcc-9 release branches. Regards, Iain. --- gcc/d/ChangeLog: * dmd/MERGE: Merge upstream dmd 70aabfb51 --- gcc/d/dmd/MERGE | 2 +- gcc/d/dmd/declaration.c | 7 +++++++ gcc/testsuite/gdc.test/fail_compilation/fail21001.d | 12 ++++++++++++ .../gdc.test/fail_compilation/imports/fail21001b.d | 5 +++++ .../fail_compilation/imports/issue21295ast_node.d | 5 +++++ .../fail_compilation/imports/issue21295astcodegen.d | 4 ++++ .../fail_compilation/imports/issue21295dtemplate.d | 3 +++ .../fail_compilation/imports/issue21295visitor.d | 3 +++ gcc/testsuite/gdc.test/fail_compilation/issue21295.d | 9 +++++++++ 9 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gdc.test/fail_compilation/fail21001.d create mode 100644 gcc/testsuite/gdc.test/fail_compilation/imports/fail21001b.d create mode 100644 gcc/testsuite/gdc.test/fail_compilation/imports/issue21295ast_node.d create mode 100644 gcc/testsuite/gdc.test/fail_compilation/imports/issue21295astcodegen.d create mode 100644 gcc/testsuite/gdc.test/fail_compilation/imports/issue21295dtemplate.d create mode 100644 gcc/testsuite/gdc.test/fail_compilation/imports/issue21295visitor.d create mode 100644 gcc/testsuite/gdc.test/fail_compilation/issue21295.d diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index 8a59cbde78e..5f6193f76b7 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -1,4 +1,4 @@ -3a979052509fff8170ba80e48817377a60e78eb3 +70aabfb511d55f2bfbdccbac7868519d9d4b63da 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/declaration.c b/gcc/d/dmd/declaration.c index 08b295070b2..f490cc5a413 100644 --- a/gcc/d/dmd/declaration.c +++ b/gcc/d/dmd/declaration.c @@ -340,6 +340,13 @@ void AliasDeclaration::semantic(Scope *sc) void AliasDeclaration::aliasSemantic(Scope *sc) { //printf("AliasDeclaration::semantic() %s\n", toChars()); + + // as AliasDeclaration::semantic, in case we're called first. + // see https://issues.dlang.org/show_bug.cgi?id=21001 + storage_class |= sc->stc & STCdeprecated; + protection = sc->protection; + userAttribDecl = sc->userAttribDecl; + // TypeTraits needs to know if it's located in an AliasDeclaration sc->flags |= SCOPEalias; diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail21001.d b/gcc/testsuite/gdc.test/fail_compilation/fail21001.d new file mode 100644 index 00000000000..0faeb4038ef --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/fail21001.d @@ -0,0 +1,12 @@ +/* +TEST_OUTPUT: +--- +fail_compilation/fail21001.d(12): Error: undefined identifier `Alias` +--- +*/ + +module fail21001; + +import imports.fail21001b; + +void main() { Alias var; } diff --git a/gcc/testsuite/gdc.test/fail_compilation/imports/fail21001b.d b/gcc/testsuite/gdc.test/fail_compilation/imports/fail21001b.d new file mode 100644 index 00000000000..69c1c20a356 --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/imports/fail21001b.d @@ -0,0 +1,5 @@ +module imports.fail21001b; + +private struct S { Alias member; } + +private alias Alias = int; diff --git a/gcc/testsuite/gdc.test/fail_compilation/imports/issue21295ast_node.d b/gcc/testsuite/gdc.test/fail_compilation/imports/issue21295ast_node.d new file mode 100644 index 00000000000..d9298bf972d --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/imports/issue21295ast_node.d @@ -0,0 +1,5 @@ +module imports.issue21295ast_node; +import imports.issue21295visitor : Visitor; +class ASTNode { + void accept(Visitor); +} diff --git a/gcc/testsuite/gdc.test/fail_compilation/imports/issue21295astcodegen.d b/gcc/testsuite/gdc.test/fail_compilation/imports/issue21295astcodegen.d new file mode 100644 index 00000000000..5eccf6ac028 --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/imports/issue21295astcodegen.d @@ -0,0 +1,4 @@ +module imports.issue21295astcodegen; +struct ASTCodegen { + import imports.issue21295dtemplate; +} diff --git a/gcc/testsuite/gdc.test/fail_compilation/imports/issue21295dtemplate.d b/gcc/testsuite/gdc.test/fail_compilation/imports/issue21295dtemplate.d new file mode 100644 index 00000000000..8864f9ea27e --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/imports/issue21295dtemplate.d @@ -0,0 +1,3 @@ +module imports.issue21295dtemplate; +import imports.issue21295ast_node; +class TemplateParameter : ASTNode { } diff --git a/gcc/testsuite/gdc.test/fail_compilation/imports/issue21295visitor.d b/gcc/testsuite/gdc.test/fail_compilation/imports/issue21295visitor.d new file mode 100644 index 00000000000..3665a7fe8c2 --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/imports/issue21295visitor.d @@ -0,0 +1,3 @@ +module imports.issue21295visitor; +import imports.issue21295astcodegen; +class Visitor { } diff --git a/gcc/testsuite/gdc.test/fail_compilation/issue21295.d b/gcc/testsuite/gdc.test/fail_compilation/issue21295.d new file mode 100644 index 00000000000..9916e9ba2a7 --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/issue21295.d @@ -0,0 +1,9 @@ +/* +REQUIRED_ARGS: -de +TEST_OUTPUT: +--- +fail_compilation/issue21295.d(9): Deprecation: imports.issue21295ast_node.Visitor is not visible from module issue21295 +--- +*/ +import imports.issue21295ast_node; +Visitor should_fail;