[gcc(refs/users/marxin/heads/vect_cond_expr-rework-v3)] d: Fix multiple definition error when using mixins and interfaces.

Martin Liska marxin@gcc.gnu.org
Thu Mar 19 09:30:16 GMT 2020


https://gcc.gnu.org/g:447d196e75d97a9ac7c6a548dc9d0fe367adf6be

commit 447d196e75d97a9ac7c6a548dc9d0fe367adf6be
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Mon Mar 16 23:04:49 2020 +0100

    d: Fix multiple definition error when using mixins and interfaces.
    
    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.

Diff:
---
 gcc/d/ChangeLog                        |  6 ++++++
 gcc/d/decl.cc                          |  7 +++++--
 gcc/testsuite/ChangeLog                |  6 ++++++
 gcc/testsuite/gdc.dg/imports/pr92216.d | 22 ++++++++++++++++++++++
 gcc/testsuite/gdc.dg/pr92216.d         | 13 +++++++++++++
 5 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/gcc/d/ChangeLog b/gcc/d/ChangeLog
index fbd56b70f66..d9c7657eaac 100644
--- a/gcc/d/ChangeLog
+++ b/gcc/d/ChangeLog
@@ -1,3 +1,9 @@
+2020-03-16  Iain Buclaw  <ibuclaw@gdcproject.org>
+
+	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-01-01  Jakub Jelinek  <jakub@redhat.com>
 
 	Update copyright years.
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/ChangeLog b/gcc/testsuite/ChangeLog
index f0d703369a8..a3820726772 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2020-03-16  Iain Buclaw  <ibuclaw@gdcproject.org>
+
+	PR d/92216
+	* gdc.dg/imports/pr92216.d: New.
+	* gdc.dg/pr92216.d: New test.
+
 2020-03-16  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c/94179
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() {}
+}


More information about the Gcc-cvs mailing list