Skip to content

Commit 4614671

Browse files
Update code to account for extern ABI requirement
1 parent 920b5ee commit 4614671

File tree

78 files changed

+155
-166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+155
-166
lines changed

compiler/rustc_error_codes/src/error_codes/E0633.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Erroneous code example:
66
#![feature(unwind_attributes)]
77
88
#[unwind()] // error: expected one argument
9-
pub extern fn something() {}
9+
pub extern "C" fn something() {}
1010
1111
fn main() {}
1212
```

library/std/src/keyword_docs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ mod enum_keyword {}
401401
///
402402
/// ```rust
403403
/// #[no_mangle]
404-
/// pub extern fn callable_from_c(x: i32) -> bool {
404+
/// pub extern "C" fn callable_from_c(x: i32) -> bool {
405405
/// x % 3 == 0
406406
/// }
407407
/// ```

library/std/src/sys/unix/weak.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::sync::atomic::{self, AtomicUsize, Ordering};
2828

2929
macro_rules! weak {
3030
(fn $name:ident($($t:ty),*) -> $ret:ty) => (
31-
static $name: crate::sys::weak::Weak<unsafe extern fn($($t),*) -> $ret> =
31+
static $name: crate::sys::weak::Weak<unsafe extern "C" fn($($t),*) -> $ret> =
3232
crate::sys::weak::Weak::new(concat!(stringify!($name), '\0'));
3333
)
3434
}

src/test/codegen/debug-linkage-name.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ pub mod xyz {
2626
// CHECK: !DISubprogram(name: "e",
2727
// CHECK: linkageName:
2828
// CHECK-SAME: line: 29,
29-
pub extern fn e() {}
29+
pub extern "C" fn e() {}
3030

3131
// CHECK: !DISubprogram(name: "f",
3232
// CHECK-NOT: linkageName:
3333
// CHECK-SAME: line: 35,
3434
#[no_mangle]
35-
pub extern fn f() {}
35+
pub extern "C" fn f() {}
3636

3737
// CHECK: !DISubprogram(name: "g",
3838
// CHECK-NOT: linkageName:
3939
// CHECK-SAME: line: 41,
4040
#[export_name = "g"]
41-
pub extern fn g() {}
41+
pub extern "C" fn g() {}
4242
}

src/test/codegen/export-no-mangle.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ mod private {
1313

1414
// CHECK: void @a()
1515
#[no_mangle]
16-
pub extern fn a() {}
16+
pub extern "C" fn a() {}
1717

1818
// CHECK: void @b()
1919
#[export_name = "b"]
20-
extern fn b() {}
20+
extern "C" fn b() {}
2121

2222
// CHECK: void @c()
2323
#[export_name = "c"]
2424
#[inline]
25-
extern fn c() {}
25+
extern "C" fn c() {}
2626

2727
// CHECK: void @d()
2828
#[export_name = "d"]
2929
#[inline(always)]
30-
extern fn d() {}
30+
extern "C" fn d() {}
3131
}

src/test/codegen/issue-47278.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ pub struct Foo(u64);
66

77
// CHECK: define {{.*}} @foo(
88
#[no_mangle]
9-
pub extern fn foo(_: Foo) -> Foo { loop {} }
9+
pub extern "C" fn foo(_: Foo) -> Foo { loop {} }

src/test/codegen/repr-transparent-aggregates-1.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ pub enum TeBigS {
3636

3737
// CHECK: define void @test_BigS(%BigS* [[BIGS_RET_ATTRS:.*]], %BigS* [[BIGS_ARG_ATTRS1:.*]] byval(%BigS) [[BIGS_ARG_ATTRS2:.*]])
3838
#[no_mangle]
39-
pub extern fn test_BigS(_: BigS) -> BigS { loop {} }
39+
pub extern "C" fn test_BigS(_: BigS) -> BigS { loop {} }
4040

4141
// CHECK: define void @test_TsBigS(%TsBigS* [[BIGS_RET_ATTRS]], %TsBigS* [[BIGS_ARG_ATTRS1]] byval(%TsBigS) [[BIGS_ARG_ATTRS2:.*]])
4242
#[no_mangle]
43-
pub extern fn test_TsBigS(_: TsBigS) -> TsBigS { loop {} }
43+
pub extern "C" fn test_TsBigS(_: TsBigS) -> TsBigS { loop {} }
4444

4545
// CHECK: define void @test_TuBigS(%TuBigS* [[BIGS_RET_ATTRS]], %TuBigS* [[BIGS_ARG_ATTRS1]] byval(%TuBigS) [[BIGS_ARG_ATTRS2:.*]])
4646
#[no_mangle]
47-
pub extern fn test_TuBigS(_: TuBigS) -> TuBigS { loop {} }
47+
pub extern "C" fn test_TuBigS(_: TuBigS) -> TuBigS { loop {} }
4848

4949
// CHECK: define void @test_TeBigS(%"TeBigS::Variant"* [[BIGS_RET_ATTRS]], %"TeBigS::Variant"* [[BIGS_ARG_ATTRS1]] byval(%"TeBigS::Variant") [[BIGS_ARG_ATTRS2]])
5050
#[no_mangle]
51-
pub extern fn test_TeBigS(_: TeBigS) -> TeBigS { loop {} }
51+
pub extern "C" fn test_TeBigS(_: TeBigS) -> TeBigS { loop {} }
5252

5353

5454
#[derive(Clone, Copy)]
@@ -72,16 +72,16 @@ pub enum TeBigU {
7272

7373
// CHECK: define void @test_BigU(%BigU* [[BIGU_RET_ATTRS:.*]], %BigU* [[BIGU_ARG_ATTRS1:.*]] byval(%BigU) [[BIGU_ARG_ATTRS2:.*]])
7474
#[no_mangle]
75-
pub extern fn test_BigU(_: BigU) -> BigU { loop {} }
75+
pub extern "C" fn test_BigU(_: BigU) -> BigU { loop {} }
7676

7777
// CHECK: define void @test_TsBigU(%TsBigU* [[BIGU_RET_ATTRS:.*]], %TsBigU* [[BIGU_ARG_ATTRS1]] byval(%TsBigU) [[BIGU_ARG_ATTRS2]])
7878
#[no_mangle]
79-
pub extern fn test_TsBigU(_: TsBigU) -> TsBigU { loop {} }
79+
pub extern "C" fn test_TsBigU(_: TsBigU) -> TsBigU { loop {} }
8080

8181
// CHECK: define void @test_TuBigU(%TuBigU* [[BIGU_RET_ATTRS]], %TuBigU* [[BIGU_ARG_ATTRS1]] byval(%TuBigU) [[BIGU_ARG_ATTRS2]])
8282
#[no_mangle]
83-
pub extern fn test_TuBigU(_: TuBigU) -> TuBigU { loop {} }
83+
pub extern "C" fn test_TuBigU(_: TuBigU) -> TuBigU { loop {} }
8484

8585
// CHECK: define void @test_TeBigU(%"TeBigU::Variant"* [[BIGU_RET_ATTRS]], %"TeBigU::Variant"* [[BIGU_ARG_ATTRS1]] byval(%"TeBigU::Variant") [[BIGU_ARG_ATTRS2]])
8686
#[no_mangle]
87-
pub extern fn test_TeBigU(_: TeBigU) -> TeBigU { loop {} }
87+
pub extern "C" fn test_TeBigU(_: TeBigU) -> TeBigU { loop {} }

src/test/codegen/repr-transparent.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,36 @@ pub struct F32(f32);
1919

2020
// CHECK: define float @test_F32(float %_1)
2121
#[no_mangle]
22-
pub extern fn test_F32(_: F32) -> F32 { loop {} }
22+
pub extern "C" fn test_F32(_: F32) -> F32 { loop {} }
2323

2424
#[repr(transparent)]
2525
pub struct Ptr(*mut u8);
2626

2727
// CHECK: define i8* @test_Ptr(i8* %_1)
2828
#[no_mangle]
29-
pub extern fn test_Ptr(_: Ptr) -> Ptr { loop {} }
29+
pub extern "C" fn test_Ptr(_: Ptr) -> Ptr { loop {} }
3030

3131
#[repr(transparent)]
3232
pub struct WithZst(u64, Zst1);
3333

3434
// CHECK: define i64 @test_WithZst(i64 %_1)
3535
#[no_mangle]
36-
pub extern fn test_WithZst(_: WithZst) -> WithZst { loop {} }
36+
pub extern "C" fn test_WithZst(_: WithZst) -> WithZst { loop {} }
3737

3838
#[repr(transparent)]
3939
pub struct WithZeroSizedArray(*const f32, [i8; 0]);
4040

4141
// Apparently we use i32* when newtype-unwrapping f32 pointers. Whatever.
4242
// CHECK: define i32* @test_WithZeroSizedArray(i32* %_1)
4343
#[no_mangle]
44-
pub extern fn test_WithZeroSizedArray(_: WithZeroSizedArray) -> WithZeroSizedArray { loop {} }
44+
pub extern "C" fn test_WithZeroSizedArray(_: WithZeroSizedArray) -> WithZeroSizedArray { loop {} }
4545

4646
#[repr(transparent)]
4747
pub struct Generic<T>(T);
4848

4949
// CHECK: define double @test_Generic(double %_1)
5050
#[no_mangle]
51-
pub extern fn test_Generic(_: Generic<f64>) -> Generic<f64> { loop {} }
51+
pub extern "C" fn test_Generic(_: Generic<f64>) -> Generic<f64> { loop {} }
5252

5353
#[repr(transparent)]
5454
pub struct GenericPlusZst<T>(T, Zst2);
@@ -58,14 +58,14 @@ pub enum Bool { True, False, FileNotFound }
5858

5959
// CHECK: define{{( zeroext)?}} i8 @test_Gpz(i8{{( zeroext)?}} %_1)
6060
#[no_mangle]
61-
pub extern fn test_Gpz(_: GenericPlusZst<Bool>) -> GenericPlusZst<Bool> { loop {} }
61+
pub extern "C" fn test_Gpz(_: GenericPlusZst<Bool>) -> GenericPlusZst<Bool> { loop {} }
6262

6363
#[repr(transparent)]
6464
pub struct LifetimePhantom<'a, T: 'a>(*const T, PhantomData<&'a T>);
6565

6666
// CHECK: define i16* @test_LifetimePhantom(i16* %_1)
6767
#[no_mangle]
68-
pub extern fn test_LifetimePhantom(_: LifetimePhantom<i16>) -> LifetimePhantom<i16> { loop {} }
68+
pub extern "C" fn test_LifetimePhantom(_: LifetimePhantom<i16>) -> LifetimePhantom<i16> { loop {} }
6969

7070
// This works despite current alignment resrictions because PhantomData is always align(1)
7171
#[repr(transparent)]
@@ -75,28 +75,28 @@ pub struct Px;
7575

7676
// CHECK: define float @test_UnitPhantom(float %_1)
7777
#[no_mangle]
78-
pub extern fn test_UnitPhantom(_: UnitPhantom<f32, Px>) -> UnitPhantom<f32, Px> { loop {} }
78+
pub extern "C" fn test_UnitPhantom(_: UnitPhantom<f32, Px>) -> UnitPhantom<f32, Px> { loop {} }
7979

8080
#[repr(transparent)]
8181
pub struct TwoZsts(Zst1, i8, Zst2);
8282

8383
// CHECK: define{{( signext)?}} i8 @test_TwoZsts(i8{{( signext)?}} %_1)
8484
#[no_mangle]
85-
pub extern fn test_TwoZsts(_: TwoZsts) -> TwoZsts { loop {} }
85+
pub extern "C" fn test_TwoZsts(_: TwoZsts) -> TwoZsts { loop {} }
8686

8787
#[repr(transparent)]
8888
pub struct Nested1(Zst2, Generic<f64>);
8989

9090
// CHECK: define double @test_Nested1(double %_1)
9191
#[no_mangle]
92-
pub extern fn test_Nested1(_: Nested1) -> Nested1 { loop {} }
92+
pub extern "C" fn test_Nested1(_: Nested1) -> Nested1 { loop {} }
9393

9494
#[repr(transparent)]
9595
pub struct Nested2(Nested1, Zst1);
9696

9797
// CHECK: define double @test_Nested2(double %_1)
9898
#[no_mangle]
99-
pub extern fn test_Nested2(_: Nested2) -> Nested2 { loop {} }
99+
pub extern "C" fn test_Nested2(_: Nested2) -> Nested2 { loop {} }
100100

101101
#[repr(simd)]
102102
struct f32x4(f32, f32, f32, f32);
@@ -106,7 +106,7 @@ pub struct Vector(f32x4);
106106

107107
// CHECK: define <4 x float> @test_Vector(<4 x float> %_1)
108108
#[no_mangle]
109-
pub extern fn test_Vector(_: Vector) -> Vector { loop {} }
109+
pub extern "C" fn test_Vector(_: Vector) -> Vector { loop {} }
110110

111111
trait Mirror { type It: ?Sized; }
112112
impl<T: ?Sized> Mirror for T { type It = Self; }
@@ -116,7 +116,7 @@ pub struct StructWithProjection(<f32 as Mirror>::It);
116116

117117
// CHECK: define float @test_Projection(float %_1)
118118
#[no_mangle]
119-
pub extern fn test_Projection(_: StructWithProjection) -> StructWithProjection { loop {} }
119+
pub extern "C" fn test_Projection(_: StructWithProjection) -> StructWithProjection { loop {} }
120120

121121
#[repr(transparent)]
122122
pub enum EnumF32 {
@@ -125,7 +125,7 @@ pub enum EnumF32 {
125125

126126
// CHECK: define float @test_EnumF32(float %_1)
127127
#[no_mangle]
128-
pub extern fn test_EnumF32(_: EnumF32) -> EnumF32 { loop {} }
128+
pub extern "C" fn test_EnumF32(_: EnumF32) -> EnumF32 { loop {} }
129129

130130
#[repr(transparent)]
131131
pub enum EnumF32WithZsts {
@@ -134,7 +134,7 @@ pub enum EnumF32WithZsts {
134134

135135
// CHECK: define float @test_EnumF32WithZsts(float %_1)
136136
#[no_mangle]
137-
pub extern fn test_EnumF32WithZsts(_: EnumF32WithZsts) -> EnumF32WithZsts { loop {} }
137+
pub extern "C" fn test_EnumF32WithZsts(_: EnumF32WithZsts) -> EnumF32WithZsts { loop {} }
138138

139139
#[repr(transparent)]
140140
pub union UnionF32 {
@@ -143,7 +143,7 @@ pub union UnionF32 {
143143

144144
// CHECK: define float @test_UnionF32(float %_1)
145145
#[no_mangle]
146-
pub extern fn test_UnionF32(_: UnionF32) -> UnionF32 { loop {} }
146+
pub extern "C" fn test_UnionF32(_: UnionF32) -> UnionF32 { loop {} }
147147

148148
#[repr(transparent)]
149149
pub union UnionF32WithZsts {
@@ -154,7 +154,7 @@ pub union UnionF32WithZsts {
154154

155155
// CHECK: define float @test_UnionF32WithZsts(float %_1)
156156
#[no_mangle]
157-
pub extern fn test_UnionF32WithZsts(_: UnionF32WithZsts) -> UnionF32WithZsts { loop {} }
157+
pub extern "C" fn test_UnionF32WithZsts(_: UnionF32WithZsts) -> UnionF32WithZsts { loop {} }
158158

159159

160160
// All that remains to be tested are aggregates. They are tested in separate files called repr-

src/test/codegen/target-cpu-on-functions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
// CHECK-LABEL: define {{.*}} @exported() {{.*}} #0
1111
#[no_mangle]
12-
pub extern fn exported() {
12+
pub extern "C" fn exported() {
1313
not_exported();
1414
}
1515

src/test/codegen/unwind-extern-exports.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// "C" ABI
1212
// pub extern fn foo() {} // FIXME right now we don't abort-on-panic but add `nounwind` nevertheless
1313
#[unwind(allowed)]
14-
pub extern fn foo_allowed() {}
14+
pub extern "C" fn foo_allowed() {}
1515

1616
// "Rust"
1717
// (`extern "Rust"` could be removed as all `fn` get it implicitly; we leave it in for clarity.)

src/test/incremental/hashes/inherent_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl Foo {
271271
impl Foo {
272272
#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,fn_sig,typeck")]
273273
#[rustc_clean(cfg="cfail3")]
274-
pub extern fn make_method_extern(&self) { }
274+
pub extern "C" fn make_method_extern(&self) { }
275275
}
276276

277277

src/test/incremental/hashes/trait_defs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ trait TraitAddExternModifier {
312312
trait TraitAddExternModifier {
313313
#[rustc_dirty(label="hir_owner", cfg="cfail2")]
314314
#[rustc_clean(label="hir_owner", cfg="cfail3")]
315-
extern fn method();
315+
extern "C" fn method();
316316
}
317317

318318

src/test/run-make-fulldeps/cdylib-dylib-linkage/foo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
extern crate bar;
44

55
#[no_mangle]
6-
pub extern fn foo() {
6+
pub extern "C" fn foo() {
77
bar::bar();
88
}
99

1010
#[no_mangle]
11-
pub extern fn bar(a: u32, b: u32) -> u32 {
11+
pub extern "C" fn bar(a: u32, b: u32) -> u32 {
1212
a + b
1313
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![crate_type = "cdylib"]
22

33
#[no_mangle]
4-
pub extern fn foo() -> u32 {
4+
pub extern "C" fn foo() -> u32 {
55
3
66
}

src/test/run-make-fulldeps/cdylib/foo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
extern crate bar;
44

55
#[no_mangle]
6-
pub extern fn foo() {
6+
pub extern "C" fn foo() {
77
bar::bar();
88
}
99

1010
#[no_mangle]
11-
pub extern fn bar(a: u32, b: u32) -> u32 {
11+
pub extern "C" fn bar(a: u32, b: u32) -> u32 {
1212
a + b
1313
}

src/test/run-make-fulldeps/cross-lang-lto-upstream-rlibs/staticlib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
extern crate upstream;
44

55
#[no_mangle]
6-
pub extern fn bar() {
6+
pub extern "C" fn bar() {
77
upstream::foo();
88
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#[no_mangle]
2-
pub extern fn args_check() {
2+
pub extern "C" fn args_check() {
33
assert_ne!(std::env::args_os().count(), 0);
44
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[no_mangle]
2-
pub extern fn foo() {}
2+
pub extern "C" fn foo() {}
33

44
#[no_mangle]
55
pub static FOO_STATIC: u8 = 0;
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[no_mangle]
2-
pub extern fn overflow() {
2+
pub extern "C" fn overflow() {
33
let xs = [0, 1, 2, 3];
44
let _y = unsafe { *xs.as_ptr().offset(4) };
55
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[no_mangle]
2-
pub extern fn overflow() {
2+
pub extern "C" fn overflow() {
33
let xs = [0, 1, 2, 3];
44
let _y = unsafe { *xs.as_ptr().offset(4) };
55
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[no_mangle]
2-
pub extern fn overflow() {
2+
pub extern "C" fn overflow() {
33
let xs = [0, 1, 2, 3];
44
let _y = unsafe { *xs.as_ptr().offset(4) };
55
}

src/test/run-make-fulldeps/static-dylib-by-default/bar.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
extern crate foo;
44

55
#[no_mangle]
6-
pub extern fn bar() {
6+
pub extern "C" fn bar() {
77
foo::foo();
88
}

src/test/run-make-fulldeps/std-core-cycle/foo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ extern crate bar;
66
static A: bar::A = bar::A;
77

88
#[no_mangle]
9-
pub extern fn a(a: u32, b: u32) -> u32 {
9+
pub extern "C" fn a(a: u32, b: u32) -> u32 {
1010
a / b
1111
}

0 commit comments

Comments
 (0)