diff options
-rw-r--r-- | src/codegen/mod.rs | 14 | ||||
-rw-r--r-- | src/ir/function.rs | 6 | ||||
-rw-r--r-- | tests/expectations/tests/issue-1350-attribute-overloadable.rs | 17 | ||||
-rw-r--r-- | tests/headers/issue-1350-attribute-overloadable.h | 2 |
4 files changed, 28 insertions, 11 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index d8524a3d..983ee4dd 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3377,12 +3377,6 @@ impl CodeGenerator for Function { attributes.push(attributes::doc(comment)); } - if let Some(mangled) = mangled_name { - attributes.push(attributes::link_name(mangled)); - } else if name != canonical_name { - attributes.push(attributes::link_name(name)); - } - // Handle overloaded functions by giving each overload its own unique // suffix. let times_seen = result.overload_number(&canonical_name); @@ -3390,6 +3384,14 @@ 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"); diff --git a/src/ir/function.rs b/src/ir/function.rs index 3f2c8254..883203e9 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -562,11 +562,7 @@ impl ClangSubItemParser for Function { name.push_str("_destructor"); } - let mut mangled_name = cursor_mangling(context, &cursor); - if mangled_name.as_ref() == Some(&name) { - mangled_name = None; - } - + let mangled_name = cursor_mangling(context, &cursor); let comment = cursor.raw_comment(); let function = Self::new(name, mangled_name, sig, comment, kind, linkage); diff --git a/tests/expectations/tests/issue-1350-attribute-overloadable.rs b/tests/expectations/tests/issue-1350-attribute-overloadable.rs new file mode 100644 index 00000000..39b03406 --- /dev/null +++ b/tests/expectations/tests/issue-1350-attribute-overloadable.rs @@ -0,0 +1,17 @@ +/* automatically generated by rust-bindgen */ + +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern "C" { + #[link_name = "\u{1}_Z11my_functioni"] + pub fn my_function(a: ::std::os::raw::c_int); +} +extern "C" { + #[link_name = "\u{1}_Z11my_functionPKc"] + pub fn my_function1(a: *const ::std::os::raw::c_char); +} diff --git a/tests/headers/issue-1350-attribute-overloadable.h b/tests/headers/issue-1350-attribute-overloadable.h new file mode 100644 index 00000000..4b0ec2a6 --- /dev/null +++ b/tests/headers/issue-1350-attribute-overloadable.h @@ -0,0 +1,2 @@ +void my_function(int a) __attribute__((overloadable)); +void my_function(const char *a) __attribute__((overloadable)); |