]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Make proc macro definition cdecl
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Mon, 4 Sep 2023 11:22:21 +0000 (13:22 +0200)
committerPhilip Herron <philip.herron@embecosm.com>
Tue, 31 Oct 2023 11:39:08 +0000 (11:39 +0000)
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>
gcc/rust/backend/rust-compile-base.cc
gcc/rust/backend/rust-compile-base.h

index 7aab59baefec950581b8da5e2ed71a795b15a2f7..1d1edfb20052705dfc8e96a0960109c06a2a5905 100644 (file)
@@ -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)
index 4a763a27862e1c1e23b1fb73ab2d9c2a9c3d455b..84775c8701123abe60729f9a6e773f40995a397b 100644 (file)
@@ -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);