summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Cole <david.cole1340@gmail.com>2022-03-13 12:30:06 +1300
committerEmilio Cobos Álvarez <emilio@crisal.io>2022-03-15 03:39:58 +0100
commit1b66dcf87692e455dc5e1603ca05d3f41b3f771b (patch)
treebedb23fcd1ea0b9263995a0a84e3d5506cdf3973
parent6a169f21344d541ab4790dee894d2cc9e51a0345 (diff)
Added support for `vectorcall` ABI
-rw-r--r--src/codegen/mod.rs33
-rw-r--r--src/features.rs11
-rw-r--r--src/ir/function.rs4
-rw-r--r--tests/expectations/tests/win32-vectorcall-1_0.rs6
-rw-r--r--tests/expectations/tests/win32-vectorcall-nightly.rs16
-rw-r--r--tests/headers/win32-vectorcall-1_0.h3
-rw-r--r--tests/headers/win32-vectorcall-nightly.h3
7 files changed, 69 insertions, 7 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index a0a0670c..1b54597f 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -17,6 +17,7 @@ use self::struct_layout::StructLayoutTracker;
use super::BindgenOptions;
+use crate::features::RustFeatures;
use crate::ir::analysis::{HasVtable, Sizedness};
use crate::ir::annotations::FieldAccessorKind;
use crate::ir::comment;
@@ -2414,10 +2415,22 @@ impl MethodCodegen for Method {
_ => panic!("How in the world?"),
};
- if let (Abi::ThisCall, false) =
- (signature.abi(), ctx.options().rust_features().thiscall_abi)
- {
- return;
+ match (signature.abi(), ctx.options().rust_features()) {
+ (
+ Abi::ThisCall,
+ RustFeatures {
+ thiscall_abi: false,
+ ..
+ },
+ ) |
+ (
+ Abi::Vectorcall,
+ RustFeatures {
+ vectorcall_abi: false,
+ ..
+ },
+ ) => return,
+ _ => {}
}
// Do not generate variadic methods, since rust does not allow
@@ -3867,6 +3880,12 @@ impl TryToRustTy for FunctionSig {
warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target");
Ok(proc_macro2::TokenStream::new())
}
+ Abi::Vectorcall
+ if !ctx.options().rust_features().vectorcall_abi =>
+ {
+ warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target");
+ Ok(proc_macro2::TokenStream::new())
+ }
_ => Ok(quote! {
unsafe extern #abi fn ( #( #arguments ),* ) #ret
}),
@@ -3958,6 +3977,12 @@ impl CodeGenerator for Function {
warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target");
return None;
}
+ Abi::Vectorcall
+ if !ctx.options().rust_features().vectorcall_abi =>
+ {
+ warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target");
+ return None;
+ }
Abi::Win64 if signature.is_variadic() => {
warn!("Skipping variadic function with Win64 ABI that isn't supported");
return None;
diff --git a/src/features.rs b/src/features.rs
index a786f07f..59467703 100644
--- a/src/features.rs
+++ b/src/features.rs
@@ -129,6 +129,7 @@ macro_rules! rust_target_base {
=> Stable_1_47 => 1.47;
/// Nightly rust
/// * `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202))
+ /// * `vectorcall` calling convention (no tracking issue)
=> Nightly => nightly;
);
}
@@ -234,6 +235,7 @@ rust_feature_def!(
}
Nightly {
=> thiscall_abi;
+ => vectorcall_abi;
}
);
@@ -259,7 +261,8 @@ mod test {
!f_1_0.associated_const &&
!f_1_0.builtin_clone_impls &&
!f_1_0.repr_align &&
- !f_1_0.thiscall_abi
+ !f_1_0.thiscall_abi &&
+ !f_1_0.vectorcall_abi
);
let f_1_21 = RustFeatures::from(RustTarget::Stable_1_21);
assert!(
@@ -269,7 +272,8 @@ mod test {
f_1_21.associated_const &&
f_1_21.builtin_clone_impls &&
!f_1_21.repr_align &&
- !f_1_21.thiscall_abi
+ !f_1_21.thiscall_abi &&
+ !f_1_21.vectorcall_abi
);
let f_nightly = RustFeatures::from(RustTarget::Nightly);
assert!(
@@ -280,7 +284,8 @@ mod test {
f_nightly.builtin_clone_impls &&
f_nightly.maybe_uninit &&
f_nightly.repr_align &&
- f_nightly.thiscall_abi
+ f_nightly.thiscall_abi &&
+ f_nightly.vectorcall_abi
);
}
diff --git a/src/ir/function.rs b/src/ir/function.rs
index 0ba2d1ee..e8e2c2df 100644
--- a/src/ir/function.rs
+++ b/src/ir/function.rs
@@ -181,6 +181,8 @@ pub enum Abi {
Fastcall,
/// The "thiscall" ABI.
ThisCall,
+ /// The "vectorcall" ABI.
+ Vectorcall,
/// The "aapcs" ABI.
Aapcs,
/// The "win64" ABI.
@@ -203,6 +205,7 @@ impl quote::ToTokens for Abi {
Abi::Stdcall => quote! { "stdcall" },
Abi::Fastcall => quote! { "fastcall" },
Abi::ThisCall => quote! { "thiscall" },
+ Abi::Vectorcall => quote! { "vectorcall" },
Abi::Aapcs => quote! { "aapcs" },
Abi::Win64 => quote! { "win64" },
Abi::Unknown(cc) => panic!(
@@ -241,6 +244,7 @@ fn get_abi(cc: CXCallingConv) -> Abi {
CXCallingConv_X86StdCall => Abi::Stdcall,
CXCallingConv_X86FastCall => Abi::Fastcall,
CXCallingConv_X86ThisCall => Abi::ThisCall,
+ CXCallingConv_X86VectorCall => Abi::Vectorcall,
CXCallingConv_AAPCS => Abi::Aapcs,
CXCallingConv_X86_64Win64 => Abi::Win64,
other => Abi::Unknown(other),
diff --git a/tests/expectations/tests/win32-vectorcall-1_0.rs b/tests/expectations/tests/win32-vectorcall-1_0.rs
new file mode 100644
index 00000000..131dbdf3
--- /dev/null
+++ b/tests/expectations/tests/win32-vectorcall-1_0.rs
@@ -0,0 +1,6 @@
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
diff --git a/tests/expectations/tests/win32-vectorcall-nightly.rs b/tests/expectations/tests/win32-vectorcall-nightly.rs
new file mode 100644
index 00000000..163741df
--- /dev/null
+++ b/tests/expectations/tests/win32-vectorcall-nightly.rs
@@ -0,0 +1,16 @@
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
+#![cfg(feature = "nightly")]
+#![feature(abi_vectorcall)]
+
+extern "vectorcall" {
+ #[link_name = "\u{1}test_vectorcall@@16"]
+ pub fn test_vectorcall(
+ a: ::std::os::raw::c_int,
+ b: ::std::os::raw::c_int,
+ ) -> ::std::os::raw::c_int;
+}
diff --git a/tests/headers/win32-vectorcall-1_0.h b/tests/headers/win32-vectorcall-1_0.h
new file mode 100644
index 00000000..a1f852b5
--- /dev/null
+++ b/tests/headers/win32-vectorcall-1_0.h
@@ -0,0 +1,3 @@
+// bindgen-flags: --rust-target 1.0 -- --target=x86_64-pc-windows-msvc
+
+int __vectorcall test_vectorcall(int a, int b);
diff --git a/tests/headers/win32-vectorcall-nightly.h b/tests/headers/win32-vectorcall-nightly.h
new file mode 100644
index 00000000..c099bb59
--- /dev/null
+++ b/tests/headers/win32-vectorcall-nightly.h
@@ -0,0 +1,3 @@
+// bindgen-flags: --rust-target nightly --raw-line '#![cfg(feature = "nightly")]' --raw-line '#![feature(abi_vectorcall)]' -- --target=x86_64-pc-windows-msvc
+
+int __vectorcall test_vectorcall(int a, int b);