]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
d: Fix multiple definition error when using mixins and interfaces.
authorIain Buclaw <ibuclaw@gdcproject.org>
Mon, 16 Mar 2020 22:04:49 +0000 (23:04 +0100)
committerIain Buclaw <ibuclaw@gdcproject.org>
Mon, 18 May 2020 13:10:24 +0000 (15:10 +0200)
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
gcc/d/decl.cc
gcc/testsuite/ChangeLog
gcc/testsuite/gdc.dg/imports/pr92216.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/pr92216.d [new file with mode: 0644]

index 5048d2ab4003beac18d5df9b63e39154e79acc2a..9ef34dd7927c2f5d7c6381f67ed7b63532eae080 100644 (file)
@@ -1,3 +1,12 @@
+2020-05-18  Iain Buclaw  <ibuclaw@gdcproject.org>
+
+       Backport from mainline
+       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-05-17  Iain Buclaw  <ibuclaw@gdcproject.org>
 
        Backport from mainline
index 49723649230367ee7c9d9515ae2f3ea9d90f7fc9..d1dfce25c6833945f0306a9f650f599e484e15e3 100644 (file)
@@ -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.  */
index 984db29ccac12c901af55344dd3c8b268729a133..87e6df437c1128fbcd555cf966060838236ed691 100644 (file)
@@ -1,3 +1,12 @@
+2020-05-18  Iain Buclaw  <ibuclaw@gdcproject.org>
+
+       Backport from mainline
+       2020-03-16  Iain Buclaw  <ibuclaw@gdcproject.org>
+
+       PR d/92216
+       * gdc.dg/imports/pr92216.d: New.
+       * gdc.dg/pr92216.d: New test.
+
 2020-05-17  Iain Buclaw  <ibuclaw@gdcproject.org>
 
        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 (file)
index 0000000..b8c71c0
--- /dev/null
@@ -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 (file)
index 0000000..89a99e5
--- /dev/null
@@ -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() {}
+}