From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-u-204.mailbox.org (mout-u-204.mailbox.org [IPv6:2001:67c:2050:1::465:204]) by sourceware.org (Postfix) with ESMTPS id 1C2DF3877024 for ; Mon, 16 Mar 2020 22:08:15 +0000 (GMT) Received: from mout-u-107.mailbox.org (mout-u-107.mailbox.org [91.198.250.252]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 48h9RK5RLWzQlFr; Mon, 16 Mar 2020 23:08:13 +0100 (CET) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-u-107.mailbox.org (Postfix) with ESMTPS id 48h9RK51XtzKmjM; Mon, 16 Mar 2020 23:08:13 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id BXOfrjxXX8wo; Mon, 16 Mar 2020 23:08:12 +0100 (CET) From: Iain Buclaw To: gcc-patches@gcc.gnu.org Subject: [PATCH] d: Committed fix multiple definition error when using mixins and interfaces. Date: Mon, 16 Mar 2020 23:08:09 +0100 Message-Id: <20200316220809.31868-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-25.2 required=5.0 tests=DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_NONE, SPF_PASS 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-List-Received-Date: Mon, 16 Mar 2020 22:08:17 -0000 Hi, When generating thunks in the D front-end, they need not necesarily be in the same compilation unit as the module where the target function is declared. When this happens, don't make the thunk public. Later on expand_thunk will be called with force_gimple_thunk=true, so the thunk can never be made weak due to differing implementations between modules. Bootstrapped and tested on x86_64-linux-gnu, and committed to trunk. Regards Iain. --- gcc/d/ChangeLog: PR d/92216 * decl.cc (make_thunk): Don't set TREE_PUBLIC on thunks if the target function is external to the current compilation. gcc/testsuite/ChangeLog: PR d/92216 * gdc.dg/imports/pr92216.d: New. * gdc.dg/pr92216.d: New test. --- gcc/d/decl.cc | 7 +++++-- gcc/testsuite/gdc.dg/imports/pr92216.d | 22 ++++++++++++++++++++++ gcc/testsuite/gdc.dg/pr92216.d | 13 +++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gdc.dg/imports/pr92216.d create mode 100644 gcc/testsuite/gdc.dg/pr92216.d diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc index 3824060feb9..7afb1aa0292 100644 --- a/gcc/d/decl.cc +++ b/gcc/d/decl.cc @@ -1803,8 +1803,11 @@ make_thunk (FuncDeclaration *decl, int offset) DECL_CONTEXT (thunk) = d_decl_context (decl); - /* Thunks inherit the public access of the function they are targetting. */ - TREE_PUBLIC (thunk) = TREE_PUBLIC (function); + /* Thunks inherit the public access of the function they are targetting. + When the function is outside the current compilation unit however, then the + thunk must be kept private to not conflict. */ + TREE_PUBLIC (thunk) = TREE_PUBLIC (function) && !DECL_EXTERNAL (function); + DECL_EXTERNAL (thunk) = 0; /* Thunks are always addressable. */ diff --git a/gcc/testsuite/gdc.dg/imports/pr92216.d b/gcc/testsuite/gdc.dg/imports/pr92216.d new file mode 100644 index 00000000000..b8c71c03420 --- /dev/null +++ b/gcc/testsuite/gdc.dg/imports/pr92216.d @@ -0,0 +1,22 @@ +module imports.pr92216; + +class B : I +{ + protected override void getStruct(){} + mixin A!(); + +} + +mixin template A() +{ + public void* getS() + { + return null; + } +} + +public interface I +{ + public void* getS(); + protected void getStruct(); +} diff --git a/gcc/testsuite/gdc.dg/pr92216.d b/gcc/testsuite/gdc.dg/pr92216.d new file mode 100644 index 00000000000..330604c9c89 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr92216.d @@ -0,0 +1,13 @@ +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92216 +// { dg-options "-I $srcdir/gdc.dg" } +// { dg-do compile } +// { dg-final { scan-assembler "_DT16_D7imports7pr922161B8__mixin24getSMFZPv\[: \t\n\]" } } +// { dg-final { scan-assembler-not "(.globl|.global)\[ \]+_DT16_D7imports7pr922161B8__mixin24getSMFZPv" } } +module pr92216; + +private import imports.pr92216; + +class C : B +{ + protected override void getStruct() {} +} -- 2.20.1