aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-base.cc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-07-12 11:22:47 +0000
committerGitHub <noreply@github.com>2022-07-12 11:22:47 +0000
commit26114120fd6e1feb1b3cbbadfa569981df372a9f (patch)
treefffaa2e45b0d7f7a939a9233524131260b2dd53c /gcc/rust/backend/rust-compile-base.cc
parenta273dbd971d337000155fe56a1d7cd78868caa9a (diff)
parenta991c30262663f989839e833f0b0c7fc2dbd07da (diff)
downloadgcc-26114120fd6e1feb1b3cbbadfa569981df372a9f.zip
gcc-26114120fd6e1feb1b3cbbadfa569981df372a9f.tar.gz
gcc-26114120fd6e1feb1b3cbbadfa569981df372a9f.tar.bz2
Merge #1375
1375: backend: properly handles foreign ABIs r=philberty a=liushuyu - Properly handles foreign (`extern` functions) ABIs Co-authored-by: liushuyu <liushuyu011@gmail.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-base.cc')
-rw-r--r--gcc/rust/backend/rust-compile-base.cc29
1 files changed, 23 insertions, 6 deletions
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc
index 3e6e370..5bf64cc 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -17,17 +17,20 @@
// <http://www.gnu.org/licenses/>.
#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);