public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Arthur Cohen <cohenarthur@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-8093] gccrs: Change ABI setup and add gccrs_proc_macro attr
Date: Tue, 16 Jan 2024 18:18:03 +0000 (GMT)	[thread overview]
Message-ID: <20240116181803.5B529386102D@sourceware.org> (raw)

https://gcc.gnu.org/g:193b0780d55c6ee93cb4a677e6bacf8c1da87021

commit r14-8093-g193b0780d55c6ee93cb4a677e6bacf8c1da87021
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Mon Sep 4 14:23:10 2023 +0200

    gccrs: 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>

Diff:
---
 gcc/rust/backend/rust-compile-base.cc | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc
index 46313048c7a..5255e57543b 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);

                 reply	other threads:[~2024-01-16 18:18 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=20240116181803.5B529386102D@sourceware.org \
    --to=cohenarthur@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: link
Be 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).