From patchwork Thu Jan 21 13:55:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1429864 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; 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=GWVGxm8j; 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 4DM3nm0SbDz9sB4 for ; Fri, 22 Jan 2021 00:55:56 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4B4BB395185F; Thu, 21 Jan 2021 13:55:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B4BB395185F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1611237353; bh=nDFGZkiQKSZZboWIJb8sn3wJEAHgOtzn4NlvbHaXSaM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=GWVGxm8ji/xko23TcBlV9beioAd8QzZm2Z0LwejtTHcr3JIuHFIZBVpjy6StkK+jQ aigTuseyfVPg6f0X/yOp3l4JZk4xXYMqXNhdeUUo2t0GH3+5V8FQ1HcHg36GW3xabk yfyR+DZh/EYS94Vd7IHjbZ9Hk9zS0xmaO5Qha0jk= 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 B61843951840 for ; Thu, 21 Jan 2021 13:55:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B61843951840 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-102.mailbox.org (Postfix) with ESMTPS id 4DM3nd0FW1zQlZ2; Thu, 21 Jan 2021 14:55:49 +0100 (CET) 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 xQeY4YLm8T52; Thu, 21 Jan 2021 14:55:37 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Enable private member access for __traits Date: Thu, 21 Jan 2021 14:55:35 +0100 Message-Id: <20210121135535.659903-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-MBO-SPAM-Probability: * X-Rspamd-Score: 1.14 / 15.00 / 15.00 X-Rspamd-Queue-Id: F1F1C17C3 X-Rspamd-UID: 0c2176 X-Spam-Status: No, score=-15.8 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 with upstream dmd 3a7ebef73. The following traits can now access non-public members: - hasMember - getMember - getOverloads - getVirtualMethods - getVirtualFuntions This fixes a long-standing issue in D where the allMembers trait would correctly return non-public members but those non-public members would be inaccessible to other traits. Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32, and committed to mainline. Regards Iain. --- gcc/d/ChangeLog: * dmd/MERGE: Merge upstream dmd 3a7ebef73. --- gcc/d/dmd/MERGE | 2 +- gcc/d/dmd/traits.c | 10 ++++------ gcc/testsuite/gdc.test/compilable/imports/test15371.d | 9 +++++++++ gcc/testsuite/gdc.test/compilable/test15371.d | 10 ++++++++++ 4 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gdc.test/compilable/imports/test15371.d create mode 100644 gcc/testsuite/gdc.test/compilable/test15371.d diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index 4f7f7a8ff3b..1f907b8f19f 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -1,4 +1,4 @@ -2d3d137489f030395d06cb664087fd1a35bccabe +3a7ebef73cc01d4a877a95cf95cd3776c9e3ee66 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/traits.c b/gcc/d/dmd/traits.c index 5fd4b486a9b..70f7f2cb582 100644 --- a/gcc/d/dmd/traits.c +++ b/gcc/d/dmd/traits.c @@ -1103,12 +1103,14 @@ Expression *semanticTraits(TraitsExp *e, Scope *sc) return new ErrorExp(); } + // ignore symbol visibility and disable access checks for these traits + Scope *scx = sc->push(); + scx->flags |= SCOPEignoresymbolvisibility | SCOPEnoaccesscheck; + if (e->ident == Id::hasMember) { /* Take any errors as meaning it wasn't found */ - Scope *scx = sc->push(); - scx->flags |= SCOPEignoresymbolvisibility; ex = trySemantic(ex, scx); scx->pop(); return ex ? True(e) : False(e); @@ -1118,8 +1120,6 @@ Expression *semanticTraits(TraitsExp *e, Scope *sc) if (ex->op == TOKdotid) // Prevent semantic() from replacing Symbol with its initializer ((DotIdExp *)ex)->wantsym = true; - Scope *scx = sc->push(); - scx->flags |= SCOPEignoresymbolvisibility; ex = semantic(ex, scx); scx->pop(); return ex; @@ -1130,8 +1130,6 @@ Expression *semanticTraits(TraitsExp *e, Scope *sc) { unsigned errors = global.errors; Expression *eorig = ex; - Scope *scx = sc->push(); - scx->flags |= SCOPEignoresymbolvisibility; ex = semantic(ex, scx); if (errors < global.errors) e->error("%s cannot be resolved", eorig->toChars()); diff --git a/gcc/testsuite/gdc.test/compilable/imports/test15371.d b/gcc/testsuite/gdc.test/compilable/imports/test15371.d new file mode 100644 index 00000000000..49b446a329b --- /dev/null +++ b/gcc/testsuite/gdc.test/compilable/imports/test15371.d @@ -0,0 +1,9 @@ +module imports.test15371; + +struct A +{ + private int a; + private void fun() {} + private void fun(int, int) {} + public void fun(int) {} +} diff --git a/gcc/testsuite/gdc.test/compilable/test15371.d b/gcc/testsuite/gdc.test/compilable/test15371.d new file mode 100644 index 00000000000..6e762beeb1e --- /dev/null +++ b/gcc/testsuite/gdc.test/compilable/test15371.d @@ -0,0 +1,10 @@ +// EXTRA_FILES: imports/test15371.d +import imports.test15371; + +void main() +{ + A a; + static assert(__traits(hasMember, A, "a")); + static assert(__traits(getOverloads, A, "fun").length == 3); + static assert(__traits(compiles, __traits(getMember, a, "a") )); +}