From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 61AFF3858418; Wed, 13 Jul 2022 07:46:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61AFF3858418 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] backend: properly handles foreign ABIs X-Act-Checkin: gcc X-Git-Author: liushuyu X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: a273dbd971d337000155fe56a1d7cd78868caa9a X-Git-Newrev: a991c30262663f989839e833f0b0c7fc2dbd07da Message-Id: <20220713074645.61AFF3858418@sourceware.org> Date: Wed, 13 Jul 2022 07:46:45 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jul 2022 07:46:45 -0000 https://gcc.gnu.org/g:a991c30262663f989839e833f0b0c7fc2dbd07da commit a991c30262663f989839e833f0b0c7fc2dbd07da Author: liushuyu Date: Fri Jul 8 17:01:40 2022 -0600 backend: properly handles foreign ABIs Diff: --- gcc/rust/backend/rust-compile-base.cc | 29 +++++++++++++++++++++++------ gcc/rust/util/rust-abi.cc | 8 ++++++++ gcc/rust/util/rust-abi.h | 2 ++ gcc/testsuite/rust/debug/win64-abi.rs | 11 +++++++++++ 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index 3e6e370abe5..5bf64cc4ef4 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -17,17 +17,20 @@ // . #include "rust-compile-base.h" +#include "rust-abi.h" #include "rust-compile-item.h" #include "rust-compile-stmt.h" #include "rust-compile-fnparam.h" #include "rust-compile-var-decl.h" +#include "rust-diagnostics.h" #include "rust-expr.h" // for AST::AttrInputLiteral #include "rust-macro.h" // for AST::MetaNameValueStr #include "fold-const.h" #include "stringpool.h" #include "attribs.h" +#include "tree.h" namespace Rust { namespace Compile { @@ -293,6 +296,8 @@ HIRCompileBase::handle_must_use_attribute_on_fndecl (tree fndecl, void HIRCompileBase::setup_abi_options (tree fndecl, ABI abi) { + tree abi_tree = NULL_TREE; + switch (abi) { case Rust::ABI::RUST: @@ -301,22 +306,34 @@ HIRCompileBase::setup_abi_options (tree fndecl, ABI abi) case Rust::ABI::CDECL: DECL_ATTRIBUTES (fndecl) = tree_cons (get_identifier ("cdecl"), NULL, DECL_ATTRIBUTES (fndecl)); - break; + + return; case Rust::ABI::STDCALL: - DECL_ATTRIBUTES (fndecl) = tree_cons (get_identifier ("stdcall"), NULL, - DECL_ATTRIBUTES (fndecl)); + abi_tree = get_identifier ("stdcall"); + break; case Rust::ABI::FASTCALL: - DECL_ATTRIBUTES (fndecl) = tree_cons (get_identifier ("fastcall"), NULL, - DECL_ATTRIBUTES (fndecl)); + abi_tree = get_identifier ("fastcall"); + + break; + + case Rust::ABI::SYSV64: + abi_tree = get_identifier ("sysv_abi"); + + break; + + case Rust::ABI::WIN64: + abi_tree = get_identifier ("ms_abi"); break; default: break; } + + decl_attributes (&fndecl, build_tree_list (abi_tree, NULL_TREE), 0); } // ported from gcc/c/c-typecheck.c @@ -497,7 +514,7 @@ HIRCompileBase::compile_function ( setup_fndecl (fndecl, is_main_fn, fntype->has_subsititions_defined (), visibility, qualifiers, outer_attrs); - setup_abi_options (fndecl, fntype->get_abi ()); + setup_abi_options (fndecl, qualifiers.get_abi ()); // conditionally mangle the function name bool should_mangle = should_mangle_item (fndecl); diff --git a/gcc/rust/util/rust-abi.cc b/gcc/rust/util/rust-abi.cc index 473988799d1..6477c3790af 100644 --- a/gcc/rust/util/rust-abi.cc +++ b/gcc/rust/util/rust-abi.cc @@ -33,6 +33,10 @@ get_abi_from_string (const std::string &abi) return Rust::ABI::STDCALL; else if (abi.compare ("fastcall") == 0) return Rust::ABI::FASTCALL; + else if (abi.compare ("sysv64") == 0) + return Rust::ABI::SYSV64; + else if (abi.compare ("win64") == 0) + return Rust::ABI::WIN64; return Rust::ABI::UNKNOWN; } @@ -54,6 +58,10 @@ get_string_from_abi (Rust::ABI abi) return "stdcall"; case Rust::ABI::FASTCALL: return "fastcall"; + case Rust::ABI::SYSV64: + return "sysv64"; + case Rust::ABI::WIN64: + return "win64"; case Rust::ABI::UNKNOWN: return "unknown"; diff --git a/gcc/rust/util/rust-abi.h b/gcc/rust/util/rust-abi.h index 2bd5ff081c9..d794cc35fb3 100644 --- a/gcc/rust/util/rust-abi.h +++ b/gcc/rust/util/rust-abi.h @@ -30,6 +30,8 @@ enum ABI CDECL, STDCALL, FASTCALL, + WIN64, + SYSV64 }; extern Rust::ABI diff --git a/gcc/testsuite/rust/debug/win64-abi.rs b/gcc/testsuite/rust/debug/win64-abi.rs new file mode 100644 index 00000000000..9d8de406b0b --- /dev/null +++ b/gcc/testsuite/rust/debug/win64-abi.rs @@ -0,0 +1,11 @@ +pub extern "win64" fn square(num: i32) -> i32 { + num * num +} + +fn main() { + // { dg-do compile { target { x86_64-*-* } } } + // { dg-options "-gdwarf-5 -dA -w -O1" } + // MS ABI dictates that the first argument is ecx instead of edi from the sysv world + // { dg-final { scan-assembler "%ecx, %ecx" } } + square(1); +}