public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Iain Buclaw <ibuclaw@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-8171] d: Add TARGET_D_HAS_STDCALL_CONVENTION Date: Wed, 14 Apr 2021 12:44:02 +0000 (GMT) [thread overview] Message-ID: <20210414124402.55DC13951866@sourceware.org> (raw) https://gcc.gnu.org/g:d253a6f7bb1748405bd9d12967f40dc19c8f77c4 commit r11-8171-gd253a6f7bb1748405bd9d12967f40dc19c8f77c4 Author: Iain Buclaw <ibuclaw@gdcproject.org> Date: Mon Apr 5 18:46:18 2021 +0200 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. Diff: --- gcc/config/i386/i386-d.c | 20 ++++++++++++++++++++ gcc/config/i386/i386-protos.h | 1 + gcc/config/i386/i386.h | 3 ++- gcc/d/d-target.cc | 12 +++++++++++- gcc/d/d-target.def | 13 +++++++++++++ gcc/d/types.cc | 19 +++++++++++++------ gcc/doc/tm.texi | 8 ++++++++ gcc/doc/tm.texi.in | 2 ++ 8 files changed, 70 insertions(+), 8 deletions(-) diff --git a/gcc/config/i386/i386-d.c b/gcc/config/i386/i386-d.c index b79be85e661..58b4790fdad 100644 --- a/gcc/config/i386/i386-d.c +++ b/gcc/config/i386/i386-d.c @@ -44,3 +44,23 @@ ix86_d_target_versions (void) else d_add_builtin_version ("D_SoftFloat"); } + +/* Implement TARGET_D_HAS_STDCALL_CONVENTION for x86 targets. */ + +bool +ix86_d_has_stdcall_convention (unsigned int *link_system, + unsigned int *link_windows) +{ + if (ix86_abi == MS_ABI) + { + *link_system = 1; + *link_windows = (!TARGET_64BIT) ? 1 : 0; + } + else + { + *link_system = 0; + *link_windows = 0; + } + + return true; +} diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h index 9f8a69ea7dc..acfb9f5fe87 100644 --- a/gcc/config/i386/i386-protos.h +++ b/gcc/config/i386/i386-protos.h @@ -264,6 +264,7 @@ extern void ix86_register_pragmas (void); /* In i386-d.c */ extern void ix86_d_target_versions (void); +extern bool ix86_d_has_stdcall_convention (unsigned int *, unsigned int *); /* In winnt.c */ extern void i386_pe_unique_section (tree, int); diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h index fab1b3c43d6..4b525d203a3 100644 --- a/gcc/config/i386/i386.h +++ b/gcc/config/i386/i386.h @@ -802,8 +802,9 @@ extern const char *host_detect_local_cpu (int argc, const char **argv); /* Target Pragmas. */ #define REGISTER_TARGET_PRAGMAS() ix86_register_pragmas () -/* Target CPU versions for D. */ +/* Target hooks for D language. */ #define TARGET_D_CPU_VERSIONS ix86_d_target_versions +#define TARGET_D_HAS_STDCALL_CONVENTION ix86_d_has_stdcall_convention #ifndef CC1_SPEC #define CC1_SPEC "%(cc1_cpu) " diff --git a/gcc/d/d-target.cc b/gcc/d/d-target.cc index a1dc2ee286f..f1814df110d 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 d1426a17e99..f79ffb9cd7d 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 ec617407b3d..3b121f5b042 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: diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index b272fa4806d..71607c4dc4e 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -10828,6 +10828,14 @@ as the name of the symbol indicating the end address of the module info section @end deftypevr +@deftypefn {D Target Hook} bool TARGET_D_HAS_STDCALL_CONVENTION (unsigned int *@var{link_system}, unsigned int *@var{link_windows}) +Returns @code{true} if the target supports the stdcall calling convention. +The hook should also set @var{link_system} to @code{1} if the @code{stdcall} +attribute should be applied to functions with @code{extern(System)} linkage, +and @var{link_windows} to @code{1} to apply @code{stdcall} to functions with +@code{extern(Windows)} linkage. +@end deftypefn + @node Named Address Spaces @section Adding support for named address spaces @cindex named address spaces diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index bf724dc093c..c8880dafcd4 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -7363,6 +7363,8 @@ floating-point support; they are not included in this mechanism. @hook TARGET_D_MINFO_END_NAME +@hook TARGET_D_HAS_STDCALL_CONVENTION + @node Named Address Spaces @section Adding support for named address spaces @cindex named address spaces
reply other threads:[~2021-04-14 12:44 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210414124402.55DC13951866@sourceware.org \ --to=ibuclaw@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).