diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index e535371f2b..289edf8903 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -558,10 +558,15 @@ impl CodeGenerator for Var { } } else { let mut attrs = vec![]; - if let Some(mangled) = self.mangled_name() { - attrs.push(attributes::link_name(mangled)); - } else if canonical_name != self.name() { - attrs.push(attributes::link_name(self.name())); + + // If necessary, apply a `#[link_name]` attribute + let link_name = self.mangled_name().unwrap_or(self.name()); + if !utils::names_will_be_identical_after_mangling( + &canonical_name, + link_name, + None, + ) { + attrs.push(attributes::link_name(link_name)); } let maybe_mut = if self.is_const() { @@ -3390,14 +3395,6 @@ impl CodeGenerator for Function { write!(&mut canonical_name, "{}", times_seen).unwrap(); } - if let Some(mangled) = mangled_name { - if canonical_name != mangled { - attributes.push(attributes::link_name(mangled)); - } - } else if name != canonical_name { - attributes.push(attributes::link_name(name)); - } - let abi = match signature.abi() { Abi::ThisCall if !ctx.options().rust_features().thiscall_abi => { warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target"); @@ -3418,6 +3415,15 @@ impl CodeGenerator for Function { abi => abi, }; + let link_name = mangled_name.unwrap_or(name); + if !utils::names_will_be_identical_after_mangling( + &canonical_name, + link_name, + Some(abi), + ) { + attributes.push(attributes::link_name(link_name)); + } + let ident = ctx.rust_ident(canonical_name); let tokens = quote!( extern #abi { #(#attributes)* @@ -3581,7 +3587,7 @@ pub(crate) fn codegen(context: BindgenContext) -> (Vec mod utils { use super::{ToRustTyOrOpaque, error}; use ir::context::BindgenContext; - use ir::function::FunctionSig; + use ir::function::{Abi, FunctionSig}; use ir::item::{Item, ItemCanonicalPath}; use ir::ty::TypeKind; use proc_macro2; @@ -3965,4 +3971,79 @@ mod utils { *const ::block::Block<(#(#args,)*), #ret_ty> } } + + // Returns true if `canonical_name` will end up as `mangled_name` at the + // machine code level, i.e. after LLVM has applied any target specific + // mangling. + pub fn names_will_be_identical_after_mangling( + canonical_name: &str, + mangled_name: &str, + call_conv: Option, + ) -> bool { + // If the mangled name and the canonical name are the same then no + // mangling can have happened between the two versions. + if canonical_name == mangled_name { + return true; + } + + // Working with &[u8] makes indexing simpler than with &str + let canonical_name = canonical_name.as_bytes(); + let mangled_name = mangled_name.as_bytes(); + + let (mangling_prefix, expect_suffix) = match call_conv { + Some(Abi::C) | + // None is the case for global variables + None => { + (b'_', false) + } + Some(Abi::Stdcall) => (b'_', true), + Some(Abi::Fastcall) => (b'@', true), + + // This is something we don't recognize, stay on the safe side + // by emitting the `#[link_name]` attribute + Some(_) => return false, + }; + + // Check that the mangled name is long enough to at least contain the + // canonical name plus the expected prefix. + if mangled_name.len() < canonical_name.len() + 1 { + return false; + } + + // Return if the mangled name does not start with the prefix expected + // for the given calling convention. + if mangled_name[0] != mangling_prefix { + return false; + } + + // Check that the mangled name contains the canonical name after the + // prefix + if &mangled_name[1..canonical_name.len() + 1] != canonical_name { + return false; + } + + // If the given calling convention also prescribes a suffix, check that + // it exists too + if expect_suffix { + let suffix = &mangled_name[canonical_name.len() + 1..]; + + // The shortest suffix is "@0" + if suffix.len() < 2 { + return false; + } + + // Check that the suffix starts with '@' and is all ASCII decimals + // after that. + if suffix[0] != b'@' || !suffix[1..].iter().all(u8::is_ascii_digit) + { + return false; + } + } else if mangled_name.len() != canonical_name.len() + 1 { + // If we don't expect a prefix but there is one, we need the + // #[link_name] attribute + return false; + } + + true + } } diff --git a/tests/expectations/tests/bitfield_large_overflow.rs b/tests/expectations/tests/bitfield_large_overflow.rs index 7df5b937f8..ea9b97abef 100644 --- a/tests/expectations/tests/bitfield_large_overflow.rs +++ b/tests/expectations/tests/bitfield_large_overflow.rs @@ -27,6 +27,5 @@ fn bindgen_test_layout__bindgen_ty_1() { ); } extern "C" { - #[link_name = "\u{1}a"] pub static mut a: _bindgen_ty_1; } diff --git a/tests/expectations/tests/class_nested.rs b/tests/expectations/tests/class_nested.rs index 7fee662a92..efd7dac256 100644 --- a/tests/expectations/tests/class_nested.rs +++ b/tests/expectations/tests/class_nested.rs @@ -95,7 +95,6 @@ fn bindgen_test_layout_A_C() { ); } extern "C" { - #[link_name = "\u{1}var"] pub static mut var: A_B; } #[test] @@ -118,7 +117,6 @@ fn __bindgen_test_layout_A_D_open0_int_close0_instantiation() { ); } extern "C" { - #[link_name = "\u{1}baz"] pub static mut baz: A_D<::std::os::raw::c_int>; } #[repr(C)] diff --git a/tests/expectations/tests/complex_global.rs b/tests/expectations/tests/complex_global.rs index defdbe68ca..417ccd4a01 100644 --- a/tests/expectations/tests/complex_global.rs +++ b/tests/expectations/tests/complex_global.rs @@ -11,14 +11,11 @@ pub struct __BindgenComplex { pub im: T, } extern "C" { - #[link_name = "\u{1}globalValueFloat"] pub static mut globalValueFloat: __BindgenComplex; } extern "C" { - #[link_name = "\u{1}globalValueDouble"] pub static mut globalValueDouble: __BindgenComplex; } extern "C" { - #[link_name = "\u{1}globalValueLongDouble"] pub static mut globalValueLongDouble: __BindgenComplex; } diff --git a/tests/expectations/tests/decl_extern_int_twice.rs b/tests/expectations/tests/decl_extern_int_twice.rs index 995457587e..04a53e51e5 100644 --- a/tests/expectations/tests/decl_extern_int_twice.rs +++ b/tests/expectations/tests/decl_extern_int_twice.rs @@ -5,6 +5,5 @@ extern "C" { - #[link_name = "\u{1}foo"] pub static mut foo: ::std::os::raw::c_int; } diff --git a/tests/expectations/tests/decl_ptr_to_array.rs b/tests/expectations/tests/decl_ptr_to_array.rs index 6d6eeb4b88..0750bbbbcf 100644 --- a/tests/expectations/tests/decl_ptr_to_array.rs +++ b/tests/expectations/tests/decl_ptr_to_array.rs @@ -5,6 +5,5 @@ extern "C" { - #[link_name = "\u{1}foo"] pub static mut foo: *mut [::std::os::raw::c_int; 1usize]; } diff --git a/tests/expectations/tests/extern-const-struct.rs b/tests/expectations/tests/extern-const-struct.rs index 2f9ade8b03..df81311b7b 100644 --- a/tests/expectations/tests/extern-const-struct.rs +++ b/tests/expectations/tests/extern-const-struct.rs @@ -41,6 +41,5 @@ impl Default for nsFoo { } } extern "C" { - #[link_name = "\u{1}gDetails"] pub static gDetails: nsFoo; } diff --git a/tests/expectations/tests/func_ptr.rs b/tests/expectations/tests/func_ptr.rs index 730849c059..0f39a07579 100644 --- a/tests/expectations/tests/func_ptr.rs +++ b/tests/expectations/tests/func_ptr.rs @@ -5,7 +5,6 @@ extern "C" { - #[link_name = "\u{1}foo"] pub static mut foo: ::std::option::Option< unsafe extern "C" fn(x: ::std::os::raw::c_int, y: ::std::os::raw::c_int) diff --git a/tests/expectations/tests/issue-511.rs b/tests/expectations/tests/issue-511.rs index 453fed0917..5d7982e054 100644 --- a/tests/expectations/tests/issue-511.rs +++ b/tests/expectations/tests/issue-511.rs @@ -8,18 +8,14 @@ )] extern "C" { - #[link_name = "\u{1}a"] pub static mut a: *mut ::std::os::raw::c_char; } extern "C" { - #[link_name = "\u{1}b"] pub static mut b: *const ::std::os::raw::c_char; } extern "C" { - #[link_name = "\u{1}c"] pub static c: *mut ::std::os::raw::c_char; } extern "C" { - #[link_name = "\u{1}d"] pub static d: *const ::std::os::raw::c_char; } diff --git a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs index db573a7ec9..21d381a721 100644 --- a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs +++ b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs @@ -38,7 +38,6 @@ fn bindgen_test_layout__bindgen_ty_1() { ); } extern "C" { - #[link_name = "\u{1}AutoIdVector"] pub static mut AutoIdVector: _bindgen_ty_1; } #[test] diff --git a/tests/expectations/tests/keywords.rs b/tests/expectations/tests/keywords.rs index b354f431f9..35f518f812 100644 --- a/tests/expectations/tests/keywords.rs +++ b/tests/expectations/tests/keywords.rs @@ -5,51 +5,39 @@ extern "C" { - #[link_name = "\u{1}u8"] pub static mut u8: ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}u16"] pub static mut u16: ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}u32"] pub static mut u32: ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}u64"] pub static mut u64: ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}i8"] pub static mut i8: ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}i16"] pub static mut i16: ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}i32"] pub static mut i32: ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}i64"] pub static mut i64: ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}f32"] pub static mut f32: ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}f64"] pub static mut f64: ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}usize"] pub static mut usize: ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}isize"] pub static mut isize: ::std::os::raw::c_int; } extern "C" { diff --git a/tests/expectations/tests/libclang-3.8/constant-evaluate.rs b/tests/expectations/tests/libclang-3.8/constant-evaluate.rs index fa54df27a6..73455f3a6a 100644 --- a/tests/expectations/tests/libclang-3.8/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-3.8/constant-evaluate.rs @@ -12,34 +12,26 @@ pub enum _bindgen_ty_1 { foo = 4, bar = 8, } pub type EasyToOverflow = ::std::os::raw::c_ulonglong; pub const k: EasyToOverflow = 2147483648; extern "C" { - #[link_name = "\u{1}k_expr"] pub static k_expr: EasyToOverflow; } extern "C" { - #[link_name = "\u{1}wow"] pub static wow: EasyToOverflow; } extern "C" { - #[link_name = "\u{1}BAZ"] pub static BAZ: ::std::os::raw::c_longlong; } extern "C" { - #[link_name = "\u{1}fuzz"] pub static fuzz: f64; } extern "C" { - #[link_name = "\u{1}BAZZ"] pub static BAZZ: ::std::os::raw::c_char; } extern "C" { - #[link_name = "\u{1}WAT"] pub static WAT: ::std::os::raw::c_char; } extern "C" { - #[link_name = "\u{1}bytestring"] pub static mut bytestring: *const ::std::os::raw::c_char; } extern "C" { - #[link_name = "\u{1}NOT_UTF8"] pub static mut NOT_UTF8: *const ::std::os::raw::c_char; } diff --git a/tests/expectations/tests/libclang-3.8/mangling-win32.rs b/tests/expectations/tests/libclang-3.8/mangling-win32.rs new file mode 100644 index 0000000000..e920634ed3 --- /dev/null +++ b/tests/expectations/tests/libclang-3.8/mangling-win32.rs @@ -0,0 +1,55 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +extern "C" { + pub fn foo(); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { + pub _address: u8, +} +extern "C" { + #[link_name = "\u{1}?sBar@Foo@@2_NA"] + pub static mut Foo_sBar: bool; +} +#[test] +fn bindgen_test_layout_Foo() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); +} +extern "C" { + #[link_name = "\u{1}@fast_call_func_no_args@0"] + pub fn fast_call_func_no_args() -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "\u{1}@fast_call_func_many_args@12"] + pub fn fast_call_func_many_args( + arg1: ::std::os::raw::c_int, + arg2: ::std::os::raw::c_int, + arg3: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "\u{1}_std_call_func_no_args@0"] + pub fn std_call_func_no_args() -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "\u{1}_std_call_func_many_args@12"] + pub fn std_call_func_many_args( + arg1: ::std::os::raw::c_int, + arg2: ::std::os::raw::c_int, + arg3: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} diff --git a/tests/expectations/tests/libclang-3.9/call-conv-field.rs b/tests/expectations/tests/libclang-3.9/call-conv-field.rs index 6cf8ec5b8e..7007d2217a 100644 --- a/tests/expectations/tests/libclang-3.9/call-conv-field.rs +++ b/tests/expectations/tests/libclang-3.9/call-conv-field.rs @@ -48,6 +48,5 @@ fn bindgen_test_layout_JNINativeInterface_() { ); } extern "stdcall" { - #[link_name = "\u{1}_bar@0"] pub fn bar(); } diff --git a/tests/expectations/tests/libclang-3.9/constant-evaluate.rs b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs index 6a3c8a362b..7e6fcd60de 100644 --- a/tests/expectations/tests/libclang-3.9/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs @@ -16,7 +16,6 @@ pub type EasyToOverflow = ::std::os::raw::c_ulonglong; pub const k: EasyToOverflow = 2147483648; pub const k_expr: EasyToOverflow = 0; extern "C" { - #[link_name = "\u{1}wow"] pub static wow: EasyToOverflow; } pub const BAZ: ::std::os::raw::c_longlong = 24; diff --git a/tests/expectations/tests/mangling-win32.rs b/tests/expectations/tests/libclang-3.9/mangling-win32.rs similarity index 53% rename from tests/expectations/tests/mangling-win32.rs rename to tests/expectations/tests/libclang-3.9/mangling-win32.rs index 2d2d7fcdbd..ad4ac42a15 100644 --- a/tests/expectations/tests/mangling-win32.rs +++ b/tests/expectations/tests/libclang-3.9/mangling-win32.rs @@ -5,7 +5,6 @@ extern "C" { - #[link_name = "\u{1}_foo"] pub fn foo(); } #[repr(C)] @@ -30,3 +29,23 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); } +extern "fastcall" { + pub fn fast_call_func_no_args() -> ::std::os::raw::c_int; +} +extern "fastcall" { + pub fn fast_call_func_many_args( + arg1: ::std::os::raw::c_int, + arg2: ::std::os::raw::c_int, + arg3: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "stdcall" { + pub fn std_call_func_no_args() -> ::std::os::raw::c_int; +} +extern "stdcall" { + pub fn std_call_func_many_args( + arg1: ::std::os::raw::c_int, + arg2: ::std::os::raw::c_int, + arg3: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} diff --git a/tests/expectations/tests/libclang-4/call-conv-field.rs b/tests/expectations/tests/libclang-4/call-conv-field.rs index 6cf8ec5b8e..7007d2217a 100644 --- a/tests/expectations/tests/libclang-4/call-conv-field.rs +++ b/tests/expectations/tests/libclang-4/call-conv-field.rs @@ -48,6 +48,5 @@ fn bindgen_test_layout_JNINativeInterface_() { ); } extern "stdcall" { - #[link_name = "\u{1}_bar@0"] pub fn bar(); } diff --git a/tests/expectations/tests/libclang-4/mangling-win32.rs b/tests/expectations/tests/libclang-4/mangling-win32.rs new file mode 100644 index 0000000000..ad4ac42a15 --- /dev/null +++ b/tests/expectations/tests/libclang-4/mangling-win32.rs @@ -0,0 +1,51 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +extern "C" { + pub fn foo(); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { + pub _address: u8, +} +extern "C" { + #[link_name = "\u{1}?sBar@Foo@@2_NA"] + pub static mut Foo_sBar: bool; +} +#[test] +fn bindgen_test_layout_Foo() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); +} +extern "fastcall" { + pub fn fast_call_func_no_args() -> ::std::os::raw::c_int; +} +extern "fastcall" { + pub fn fast_call_func_many_args( + arg1: ::std::os::raw::c_int, + arg2: ::std::os::raw::c_int, + arg3: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "stdcall" { + pub fn std_call_func_no_args() -> ::std::os::raw::c_int; +} +extern "stdcall" { + pub fn std_call_func_many_args( + arg1: ::std::os::raw::c_int, + arg2: ::std::os::raw::c_int, + arg3: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} diff --git a/tests/expectations/tests/libclang-5/call-conv-field.rs b/tests/expectations/tests/libclang-5/call-conv-field.rs index 76712fe790..3286ac4668 100644 --- a/tests/expectations/tests/libclang-5/call-conv-field.rs +++ b/tests/expectations/tests/libclang-5/call-conv-field.rs @@ -51,6 +51,5 @@ fn bindgen_test_layout_JNINativeInterface_() { ); } extern "stdcall" { - #[link_name = "\u{1}_bar@0"] pub fn bar(); } diff --git a/tests/expectations/tests/libclang-5/mangling-win32.rs b/tests/expectations/tests/libclang-5/mangling-win32.rs new file mode 100644 index 0000000000..ad4ac42a15 --- /dev/null +++ b/tests/expectations/tests/libclang-5/mangling-win32.rs @@ -0,0 +1,51 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +extern "C" { + pub fn foo(); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { + pub _address: u8, +} +extern "C" { + #[link_name = "\u{1}?sBar@Foo@@2_NA"] + pub static mut Foo_sBar: bool; +} +#[test] +fn bindgen_test_layout_Foo() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); +} +extern "fastcall" { + pub fn fast_call_func_no_args() -> ::std::os::raw::c_int; +} +extern "fastcall" { + pub fn fast_call_func_many_args( + arg1: ::std::os::raw::c_int, + arg2: ::std::os::raw::c_int, + arg3: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "stdcall" { + pub fn std_call_func_no_args() -> ::std::os::raw::c_int; +} +extern "stdcall" { + pub fn std_call_func_many_args( + arg1: ::std::os::raw::c_int, + arg2: ::std::os::raw::c_int, + arg3: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} diff --git a/tests/expectations/tests/mangling-ios.rs b/tests/expectations/tests/mangling-ios.rs index 0fddb5d707..87df5e4ad7 100644 --- a/tests/expectations/tests/mangling-ios.rs +++ b/tests/expectations/tests/mangling-ios.rs @@ -5,6 +5,5 @@ extern "C" { - #[link_name = "\u{1}_foo"] pub fn foo(); } diff --git a/tests/expectations/tests/mangling-macos.rs b/tests/expectations/tests/mangling-macos.rs index 7835dd928c..7101b321d6 100644 --- a/tests/expectations/tests/mangling-macos.rs +++ b/tests/expectations/tests/mangling-macos.rs @@ -5,7 +5,6 @@ extern "C" { - #[link_name = "\u{1}_foo"] pub fn foo(); } #[repr(C)] diff --git a/tests/expectations/tests/objc_class.rs b/tests/expectations/tests/objc_class.rs index b5c15a0e2a..062cab3f20 100644 --- a/tests/expectations/tests/objc_class.rs +++ b/tests/expectations/tests/objc_class.rs @@ -9,7 +9,6 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; extern "C" { - #[link_name = "\u{1}fooVar"] pub static mut fooVar: *mut id; } pub trait Foo { diff --git a/tests/expectations/tests/objc_interface_type.rs b/tests/expectations/tests/objc_interface_type.rs index 9931f5a94c..0b77b5bec0 100644 --- a/tests/expectations/tests/objc_interface_type.rs +++ b/tests/expectations/tests/objc_interface_type.rs @@ -47,6 +47,5 @@ extern "C" { pub fn fooFunc(foo: id); } extern "C" { - #[link_name = "\u{1}kFoo"] pub static mut kFoo: *const id; } diff --git a/tests/expectations/tests/objc_sel_and_id.rs b/tests/expectations/tests/objc_sel_and_id.rs index 8802c206ea..da69c7a897 100644 --- a/tests/expectations/tests/objc_sel_and_id.rs +++ b/tests/expectations/tests/objc_sel_and_id.rs @@ -9,11 +9,9 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; extern "C" { - #[link_name = "\u{1}object"] pub static mut object: id; } extern "C" { - #[link_name = "\u{1}selector"] pub static mut selector: objc::runtime::Sel; } extern "C" { diff --git a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs index 94504951d7..528a7a2fc2 100644 --- a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs +++ b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs @@ -1,7 +1,6 @@ /* automatically generated by rust-bindgen */ extern "C" { - #[link_name = "\u{1}foo"] pub static mut foo: ::std::option::Option< unsafe extern "C" fn(x: ::std::os::raw::c_int, y: ::std::os::raw::c_int) diff --git a/tests/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs index 563258a0b1..8f6c4cd56e 100644 --- a/tests/expectations/tests/use-core.rs +++ b/tests/expectations/tests/use-core.rs @@ -95,7 +95,6 @@ impl Default for _bindgen_ty_1 { } } extern "C" { - #[link_name = "\u{1}bazz"] pub static mut bazz: _bindgen_ty_1; } pub type fooFunction = ::core::option::Option; diff --git a/tests/expectations/tests/use-core_1_0.rs b/tests/expectations/tests/use-core_1_0.rs index 3ce8fe5cca..ce17d3bca7 100644 --- a/tests/expectations/tests/use-core_1_0.rs +++ b/tests/expectations/tests/use-core_1_0.rs @@ -139,7 +139,6 @@ impl Clone for _bindgen_ty_1 { } } extern "C" { - #[link_name = "\u{1}bazz"] pub static mut bazz: _bindgen_ty_1; } pub type fooFunction = ::core::option::Option; diff --git a/tests/headers/mangling-win32.hpp b/tests/headers/mangling-win32.hpp index 50beea5aec..386df4aba3 100644 --- a/tests/headers/mangling-win32.hpp +++ b/tests/headers/mangling-win32.hpp @@ -5,3 +5,14 @@ extern "C" void foo(); struct Foo { static bool sBar; }; + +// Also test some x86 Windows specific calling conventions that have their own +// special mangling +extern "C" { + int _fastcall fast_call_func_no_args(); + // This will result in a suffix with more than one character (i.e. `@12`) + int _fastcall fast_call_func_many_args(int,int,int); + int _stdcall std_call_func_no_args(); + // This will result in a suffix with more than one character (i.e. `@12`) + int _stdcall std_call_func_many_args(int,int,int); +} diff --git a/tests/tests.rs b/tests/tests.rs index 092824f154..ee4783ebd9 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -339,11 +339,9 @@ fn test_clang_env_args() { let (expected, _) = rustfmt("/* automatically generated by rust-bindgen */ extern \"C\" { - #[link_name = \"\\u{1}x\"] pub static mut x: [::std::os::raw::c_int; 1usize]; } extern \"C\" { - #[link_name = \"\\u{1}y\"] pub static mut y: [::std::os::raw::c_int; 1usize]; } ".to_string());