Skip to content

Commit 1a2e2b3

Browse files
author
bors-servo
authored
Auto merge of #1434 - emilio:attr-overloadable, r=emilio
codegen: Make the mangling name check work in presence of attribute(overloadable). Fixes #1350
2 parents 5de943c + e065a32 commit 1a2e2b3

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

src/codegen/mod.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -3377,19 +3377,21 @@ impl CodeGenerator for Function {
33773377
attributes.push(attributes::doc(comment));
33783378
}
33793379

3380-
if let Some(mangled) = mangled_name {
3381-
attributes.push(attributes::link_name(mangled));
3382-
} else if name != canonical_name {
3383-
attributes.push(attributes::link_name(name));
3384-
}
3385-
33863380
// Handle overloaded functions by giving each overload its own unique
33873381
// suffix.
33883382
let times_seen = result.overload_number(&canonical_name);
33893383
if times_seen > 0 {
33903384
write!(&mut canonical_name, "{}", times_seen).unwrap();
33913385
}
33923386

3387+
if let Some(mangled) = mangled_name {
3388+
if canonical_name != mangled {
3389+
attributes.push(attributes::link_name(mangled));
3390+
}
3391+
} else if name != canonical_name {
3392+
attributes.push(attributes::link_name(name));
3393+
}
3394+
33933395
let abi = match signature.abi() {
33943396
Abi::ThisCall if !ctx.options().rust_features().thiscall_abi => {
33953397
warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target");

src/ir/function.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,7 @@ impl ClangSubItemParser for Function {
562562
name.push_str("_destructor");
563563
}
564564

565-
let mut mangled_name = cursor_mangling(context, &cursor);
566-
if mangled_name.as_ref() == Some(&name) {
567-
mangled_name = None;
568-
}
569-
565+
let mangled_name = cursor_mangling(context, &cursor);
570566
let comment = cursor.raw_comment();
571567

572568
let function = Self::new(name, mangled_name, sig, comment, kind, linkage);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
#![allow(
4+
dead_code,
5+
non_snake_case,
6+
non_camel_case_types,
7+
non_upper_case_globals
8+
)]
9+
10+
extern "C" {
11+
#[link_name = "\u{1}_Z11my_functioni"]
12+
pub fn my_function(a: ::std::os::raw::c_int);
13+
}
14+
extern "C" {
15+
#[link_name = "\u{1}_Z11my_functionPKc"]
16+
pub fn my_function1(a: *const ::std::os::raw::c_char);
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void my_function(int a) __attribute__((overloadable));
2+
void my_function(const char *a) __attribute__((overloadable));

0 commit comments

Comments
 (0)