aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-09-04 14:23:10 +0200
committerPhilip Herron <philip.herron@embecosm.com>2023-10-31 11:39:08 +0000
commit327a285500ac640f1d8257d11ea56bf4ab65ee47 (patch)
tree28b355ecfac16f0ff9ce505a18b7a987f3568cf6 /gcc
parentff32f8fdcef87ef569fd072ee12c47237e8da2e7 (diff)
downloadgcc-327a285500ac640f1d8257d11ea56bf4ab65ee47.zip
gcc-327a285500ac640f1d8257d11ea56bf4ab65ee47.tar.gz
gcc-327a285500ac640f1d8257d11ea56bf4ab65ee47.tar.bz2
Change ABI setup and add gccrs_proc_macro attr
Change the way the ABI is setup on a function to avoid duplicates. ABI is setup by the setup function only now. Add a new attribute to the function "gccrs_proc_macro" in order to differentiate it from another type of function. gcc/rust/ChangeLog: * backend/rust-compile-base.cc (handle_proc_macro_common): Add new attribute "gccrs_proc_macro" to all procedural macro functions. (get_abi): Add a function to retrieve the correct ABI depending on wether the function is a proc macro or not. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-base.cc21
1 files changed, 18 insertions, 3 deletions
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc
index 1d1edfb..78093a2 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -133,8 +133,8 @@ HIRCompileBase::setup_fndecl (tree fndecl, bool is_main_entry_point,
static void
handle_proc_macro_common (tree fndecl, const AST::Attribute &attr)
{
- DECL_ATTRIBUTES (fndecl)
- = tree_cons (get_identifier ("cdecl"), NULL, DECL_ATTRIBUTES (fndecl));
+ DECL_ATTRIBUTES (fndecl) = tree_cons (get_identifier ("gccrs_proc_macro"),
+ NULL, DECL_ATTRIBUTES (fndecl));
}
void
@@ -591,6 +591,21 @@ HIRCompileBase::compile_function_body (tree fndecl,
}
}
+static ABI
+get_abi (const AST::AttrVec &outer_attrs,
+ const HIR::FunctionQualifiers &qualifiers)
+{
+ bool is_proc_macro = std::any_of (outer_attrs.cbegin (), outer_attrs.cend (),
+ [] (const AST::Attribute &attr) {
+ auto path = attr.get_path ().as_string ();
+ return path == "proc_macro"
+ || path == "proc_macro_derive"
+ || path == "proc_macro_attribute";
+ });
+
+ return is_proc_macro ? ABI::CDECL : qualifiers.get_abi ();
+}
+
tree
HIRCompileBase::compile_function (
const std::string &fn_name, HIR::SelfParam &self_param,
@@ -613,7 +628,7 @@ HIRCompileBase::compile_function (
setup_fndecl (fndecl, is_main_fn, fntype->has_substitutions_defined (),
visibility, qualifiers, outer_attrs);
- setup_abi_options (fndecl, qualifiers.get_abi ());
+ setup_abi_options (fndecl, get_abi (outer_attrs, qualifiers));
// conditionally mangle the function name
bool should_mangle = should_mangle_item (fndecl);