diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-03-16 23:04:49 +0100 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-05-18 15:10:24 +0200 |
commit | 3e84ee0fab9cedfa57fe86ea3c00608f6a873ab9 (patch) | |
tree | fd8d7bf9ed215e5aab09081b776c33d0daefb7e3 | |
parent | e8dcd6c79335997a80f75db389263b63dfa45ca1 (diff) |
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.
-rw-r--r-- | gcc/d/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/d/decl.cc | 7 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/testsuite/gdc.dg/imports/pr92216.d | 22 | ||||
-rw-r--r-- | gcc/testsuite/gdc.dg/pr92216.d | 13 |
5 files changed, 58 insertions, 2 deletions
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 <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 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 <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 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() {} +} |