aboutsummaryrefslogtreecommitdiff
path: root/gcc/d
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2021-04-05 18:46:18 +0200
committerIain Buclaw <ibuclaw@gdcproject.org>2021-04-14 14:43:37 +0200
commitd253a6f7bb1748405bd9d12967f40dc19c8f77c4 (patch)
tree5521bbeda5815da04d1f8cd76efb8095ffe99aa2 /gcc/d
parent3330e673959d44e5c7663956803e1e7a703dd626 (diff)
downloadgcc-d253a6f7bb1748405bd9d12967f40dc19c8f77c4.zip
gcc-d253a6f7bb1748405bd9d12967f40dc19c8f77c4.tar.gz
gcc-d253a6f7bb1748405bd9d12967f40dc19c8f77c4.tar.bz2
d: Add TARGET_D_HAS_STDCALL_CONVENTION
This replaces the use of the D front-end `is64bit' parameter in determining whether to insert the "stdcall" function attribute. It is also used to determine whether `extern(System)' should be the same as `extern(Windows)' in the implementation of Target::systemLinkage. gcc/ChangeLog: * config/i386/i386-d.c (ix86_d_has_stdcall_convention): New function. * config/i386/i386-protos.h (ix86_d_has_stdcall_convention): Declare. * config/i386/i386.h (TARGET_D_HAS_STDCALL_CONVENTION): Define. * doc/tm.texi: Regenerate. * doc/tm.texi.in (D language and ABI): Add @hook for TARGET_D_HAS_STDCALL_CONVENTION. gcc/d/ChangeLog: * d-target.cc (Target::systemLinkage): Return LINKwindows if d_has_stdcall_convention applies to LINKsystem. * d-target.def (d_has_stdcall_convention): New hook. * types.cc (TypeVisitor::visit (TypeFunction *)): Insert "stdcall" function attribute if d_has_stdcall_convention applies to LINKwindows.
Diffstat (limited to 'gcc/d')
-rw-r--r--gcc/d/d-target.cc12
-rw-r--r--gcc/d/d-target.def13
-rw-r--r--gcc/d/types.cc19
3 files changed, 37 insertions, 7 deletions
diff --git a/gcc/d/d-target.cc b/gcc/d/d-target.cc
index a1dc2ee..f1814df 100644
--- a/gcc/d/d-target.cc
+++ b/gcc/d/d-target.cc
@@ -435,11 +435,21 @@ TargetCPP::derivedClassOffset(ClassDeclaration *base_class)
return base_class->structsize;
}
-/* Return the default system linkage for the target. */
+/* Return the default `extern (System)' linkage for the target. */
LINK
Target::systemLinkage (void)
{
+ unsigned link_system, link_windows;
+
+ if (targetdm.d_has_stdcall_convention (&link_system, &link_windows))
+ {
+ /* In [attribute/linkage], `System' is the same as `Windows' on Windows
+ platforms, and `C' on other platforms. */
+ if (link_system)
+ return LINKwindows;
+ }
+
return LINKc;
}
diff --git a/gcc/d/d-target.def b/gcc/d/d-target.def
index d1426a1..f79ffb9 100644
--- a/gcc/d/d-target.def
+++ b/gcc/d/d-target.def
@@ -71,5 +71,18 @@ as the name of the symbol indicating the end address of the module info\n\
section",
const char *, NULL)
+/* The "stdcall" convention is really supported on 32-bit x86/Windows only.
+ The following hook is a helper to determine whether to apply the attribute
+ on declarations with `extern(System)' and `extern(Windows)' linkage. */
+DEFHOOK
+(d_has_stdcall_convention,
+ "Returns @code{true} if the target supports the stdcall calling convention.\n\
+The hook should also set @var{link_system} to @code{1} if the @code{stdcall}\n\
+attribute should be applied to functions with @code{extern(System)} linkage,\n\
+and @var{link_windows} to @code{1} to apply @code{stdcall} to functions with\n\
+@code{extern(Windows)} linkage.",
+ bool, (unsigned int *link_system, unsigned int *link_windows),
+ hook_bool_uintp_uintp_false)
+
/* Close the 'struct gcc_targetdm' definition. */
HOOK_VECTOR_END (C90_EMPTY_HACK)
diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index ec61740..3b121f5 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -40,6 +40,7 @@ along with GCC; see the file COPYING3. If not see
#include "attribs.h"
#include "d-tree.h"
+#include "d-target.h"
/* Return the signed or unsigned version of TYPE, an integral type, the
@@ -800,13 +801,19 @@ public:
switch (t->linkage)
{
case LINKwindows:
- /* [attribute/linkage]
+ {
+ /* [attribute/linkage]
- The Windows convention is distinct from the C convention only
- on Win32, where it is equivalent to the stdcall convention. */
- if (!global.params.is64bit)
- t->ctype = insert_type_attribute (t->ctype, "stdcall");
- break;
+ The Windows convention is distinct from the C convention only
+ on Win32, where it is equivalent to the stdcall convention. */
+ unsigned link_system, link_windows;
+ if (targetdm.d_has_stdcall_convention (&link_system, &link_windows))
+ {
+ if (link_windows)
+ t->ctype = insert_type_attribute (t->ctype, "stdcall");
+ }
+ break;
+ }
case LINKc:
case LINKcpp: