diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-09-04 13:22:21 +0200 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2023-10-31 11:39:08 +0000 |
commit | ff32f8fdcef87ef569fd072ee12c47237e8da2e7 (patch) | |
tree | 0344d2319518d2677a8ba3db9301e213a953565c | |
parent | 2a1a37344f0db01900e73f05fca71cdcf7a559c2 (diff) | |
download | gcc-ff32f8fdcef87ef569fd072ee12c47237e8da2e7.zip gcc-ff32f8fdcef87ef569fd072ee12c47237e8da2e7.tar.gz gcc-ff32f8fdcef87ef569fd072ee12c47237e8da2e7.tar.bz2 |
Make proc macro definition cdecl
We need to make sure proc macros have the C abi in order to be called by
the compiler with dlopen.
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc (HIRCompileBase::setup_fndecl):
Add proc macro handlers dispatch.
(handle_proc_macro_common): Add a function for common behavior
between all kinds of proc macros.
* backend/rust-compile-base.h: Add function prototypes.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r-- | gcc/rust/backend/rust-compile-base.cc | 47 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-base.h | 12 |
2 files changed, 59 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index 7aab59b..1d1edfb 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -83,6 +83,13 @@ HIRCompileBase::setup_fndecl (tree fndecl, bool is_main_entry_point, = attr.get_path ().as_string () == Values::Attributes::NO_MANGLE; bool is_deprecated = attr.get_path ().as_string () == Values::Attributes::DEPRECATED; + bool is_proc_macro + = attr.get_path ().as_string () == Values::Attributes::PROC_MACRO; + bool is_proc_macro_attribute + = attr.get_path ().as_string () + == Values::Attributes::PROC_MACRO_ATTRIBUTE; + bool is_proc_macro_derive = attr.get_path ().as_string () + == Values::Attributes::PROC_MACRO_DERIVE; if (is_inline) { @@ -108,9 +115,49 @@ HIRCompileBase::setup_fndecl (tree fndecl, bool is_main_entry_point, { handle_no_mangle_attribute_on_fndecl (fndecl, attr); } + else if (is_proc_macro) + { + handle_proc_macro_attribute_on_fndecl (fndecl, attr); + } + else if (is_proc_macro_attribute) + { + handle_proc_macro_attribute_attribute_on_fndecl (fndecl, attr); + } + else if (is_proc_macro_derive) + { + handle_proc_macro_derive_attribute_on_fndecl (fndecl, attr); + } } } +static void +handle_proc_macro_common (tree fndecl, const AST::Attribute &attr) +{ + DECL_ATTRIBUTES (fndecl) + = tree_cons (get_identifier ("cdecl"), NULL, DECL_ATTRIBUTES (fndecl)); +} + +void +HIRCompileBase::handle_proc_macro_attribute_on_fndecl ( + tree fndecl, const AST::Attribute &attr) +{ + handle_proc_macro_common (fndecl, attr); +} + +void +HIRCompileBase::handle_proc_macro_attribute_attribute_on_fndecl ( + tree fndecl, const AST::Attribute &attr) +{ + handle_proc_macro_common (fndecl, attr); +} + +void +HIRCompileBase::handle_proc_macro_derive_attribute_on_fndecl ( + tree fndecl, const AST::Attribute &attr) +{ + handle_proc_macro_common (fndecl, attr); +} + void HIRCompileBase::handle_cold_attribute_on_fndecl (tree fndecl, const AST::Attribute &attr) diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h index 4a763a2..84775c8 100644 --- a/gcc/rust/backend/rust-compile-base.h +++ b/gcc/rust/backend/rust-compile-base.h @@ -110,6 +110,18 @@ protected: static void handle_inline_attribute_on_fndecl (tree fndecl, const AST::Attribute &attr); + static void + handle_proc_macro_attribute_on_fndecl (tree fndecl, + const AST::Attribute &attr); + + static void + handle_proc_macro_attribute_attribute_on_fndecl (tree fndecl, + const AST::Attribute &attr); + + static void + handle_proc_macro_derive_attribute_on_fndecl (tree fndecl, + const AST::Attribute &attr); + static void handle_cold_attribute_on_fndecl (tree fndecl, const AST::Attribute &attr); |