From patchwork Mon May 18 13:20:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1292528 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=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=vE04LmYB; 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 49QflK3Xvlz9sTj for ; Mon, 18 May 2020 23:20:27 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DC202388F072; Mon, 18 May 2020 13:20:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC202388F072 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1589808024; bh=xue7XBLSQmAzcDJa2OW4O6+WFZ2nziX8kVnY4qnkOnk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=vE04LmYB5hjjC3i6m2YrrB7Ha8uS0jF2fpim0ySoUhyA8HyKFoBCt27YAnfQAkY/r zUoR97Tu8wP2o1SxeS6eVZDSDqnRRVK/XxybRjxNtc7VAvW8XQ9WIqZSVcmbD8sXsy tVqu/c2Xw+RiLkCboponwDJokiGIaf3bTt37AtjA= 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 5DA34388F06B for ; Mon, 18 May 2020 13:20:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5DA34388F06B 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-p-102.mailbox.org (Postfix) with ESMTPS id 49Qfl91DBhzKmPs for ; Mon, 18 May 2020 15:20:21 +0200 (CEST) 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 aH2JCNIy6NwD for ; Mon, 18 May 2020 15:20:13 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed][GCC9] d: Fix multiple definition error when using mixins and interfaces (PR92216, PR95184) Date: Mon, 18 May 2020 15:20:13 +0200 Message-Id: <20200518132013.557-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 92802176E X-Rspamd-Score: -1.77 / 15.00 / 15.00 X-Spam-Status: No, score=-18.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 for PR d/92216 was already applied to mainline before the GCC-10 release, however due to a second bug report (PR d/95184) against the GCC-9 release, I've decided it's best to apply it there too. Backport is a merge of r10-7199 and r10-7504. Bootstrapped and regression tested on x86_64-linux-gnu, committed to gcc-9 branch. 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/ChangeLog | 9 +++++++++ gcc/d/decl.cc | 7 +++++-- gcc/testsuite/ChangeLog | 9 +++++++++ gcc/testsuite/gdc.dg/imports/pr92216.d | 22 ++++++++++++++++++++++ gcc/testsuite/gdc.dg/pr92216.d | 13 +++++++++++++ 5 files changed, 58 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/ChangeLog b/gcc/d/ChangeLog index 5048d2ab400..9ef34dd7927 100644 --- a/gcc/d/ChangeLog +++ b/gcc/d/ChangeLog @@ -1,3 +1,12 @@ +2020-05-18 Iain Buclaw + + Backport from mainline + 2020-03-16 Iain Buclaw + + PR d/92216 + * decl.cc (make_thunk): Don't set TREE_PUBLIC on thunks if the target + function is external to the current compilation. + 2020-05-17 Iain Buclaw Backport from mainline diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc index 49723649230..d1dfce25c68 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/ChangeLog b/gcc/testsuite/ChangeLog index 984db29ccac..87e6df437c1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2020-05-18 Iain Buclaw + + Backport from mainline + 2020-03-16 Iain Buclaw + + PR d/92216 + * gdc.dg/imports/pr92216.d: New. + * gdc.dg/pr92216.d: New test. + 2020-05-17 Iain Buclaw Backport from mainline 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..89a99e599be --- /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 "_DT(4|8|16)_D7imports7pr922161B8__mixin24getSMFZPv\[: \t\n\]" } } +// { dg-final { scan-assembler-not "(.globl|.global)\[ \]+_DT(4|8|16)_D7imports7pr922161B8__mixin24getSMFZPv" } } +module pr92216; + +private import imports.pr92216; + +class C : B +{ + protected override void getStruct() {} +}