Skip to content

Commit

Permalink
Update code to account for extern ABI requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Jan 13, 2021
1 parent 920b5ee commit 4614671
Show file tree
Hide file tree
Showing 78 changed files with 155 additions and 166 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes/E0633.md
Expand Up @@ -6,7 +6,7 @@ Erroneous code example:
#![feature(unwind_attributes)]
#[unwind()] // error: expected one argument
pub extern fn something() {}
pub extern "C" fn something() {}
fn main() {}
```
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/keyword_docs.rs
Expand Up @@ -401,7 +401,7 @@ mod enum_keyword {}
///
/// ```rust
/// #[no_mangle]
/// pub extern fn callable_from_c(x: i32) -> bool {
/// pub extern "C" fn callable_from_c(x: i32) -> bool {
/// x % 3 == 0
/// }
/// ```
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/unix/weak.rs
Expand Up @@ -28,7 +28,7 @@ use crate::sync::atomic::{self, AtomicUsize, Ordering};

macro_rules! weak {
(fn $name:ident($($t:ty),*) -> $ret:ty) => (
static $name: crate::sys::weak::Weak<unsafe extern fn($($t),*) -> $ret> =
static $name: crate::sys::weak::Weak<unsafe extern "C" fn($($t),*) -> $ret> =
crate::sys::weak::Weak::new(concat!(stringify!($name), '\0'));
)
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/codegen/debug-linkage-name.rs
Expand Up @@ -26,17 +26,17 @@ pub mod xyz {
// CHECK: !DISubprogram(name: "e",
// CHECK: linkageName:
// CHECK-SAME: line: 29,
pub extern fn e() {}
pub extern "C" fn e() {}

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

// CHECK: !DISubprogram(name: "g",
// CHECK-NOT: linkageName:
// CHECK-SAME: line: 41,
#[export_name = "g"]
pub extern fn g() {}
pub extern "C" fn g() {}
}
8 changes: 4 additions & 4 deletions src/test/codegen/export-no-mangle.rs
Expand Up @@ -13,19 +13,19 @@ mod private {

// CHECK: void @a()
#[no_mangle]
pub extern fn a() {}
pub extern "C" fn a() {}

// CHECK: void @b()
#[export_name = "b"]
extern fn b() {}
extern "C" fn b() {}

// CHECK: void @c()
#[export_name = "c"]
#[inline]
extern fn c() {}
extern "C" fn c() {}

// CHECK: void @d()
#[export_name = "d"]
#[inline(always)]
extern fn d() {}
extern "C" fn d() {}
}
2 changes: 1 addition & 1 deletion src/test/codegen/issue-47278.rs
Expand Up @@ -6,4 +6,4 @@ pub struct Foo(u64);

// CHECK: define {{.*}} @foo(
#[no_mangle]
pub extern fn foo(_: Foo) -> Foo { loop {} }
pub extern "C" fn foo(_: Foo) -> Foo { loop {} }
16 changes: 8 additions & 8 deletions src/test/codegen/repr-transparent-aggregates-1.rs
Expand Up @@ -36,19 +36,19 @@ pub enum TeBigS {

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

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

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

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


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

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

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

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

// CHECK: define void @test_TeBigU(%"TeBigU::Variant"* [[BIGU_RET_ATTRS]], %"TeBigU::Variant"* [[BIGU_ARG_ATTRS1]] byval(%"TeBigU::Variant") [[BIGU_ARG_ATTRS2]])
#[no_mangle]
pub extern fn test_TeBigU(_: TeBigU) -> TeBigU { loop {} }
pub extern "C" fn test_TeBigU(_: TeBigU) -> TeBigU { loop {} }
34 changes: 17 additions & 17 deletions src/test/codegen/repr-transparent.rs
Expand Up @@ -19,36 +19,36 @@ pub struct F32(f32);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#[repr(simd)]
struct f32x4(f32, f32, f32, f32);
Expand All @@ -106,7 +106,7 @@ pub struct Vector(f32x4);

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

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

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

#[repr(transparent)]
pub enum EnumF32 {
Expand All @@ -125,7 +125,7 @@ pub enum EnumF32 {

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

#[repr(transparent)]
pub enum EnumF32WithZsts {
Expand All @@ -134,7 +134,7 @@ pub enum EnumF32WithZsts {

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

#[repr(transparent)]
pub union UnionF32 {
Expand All @@ -143,7 +143,7 @@ pub union UnionF32 {

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

#[repr(transparent)]
pub union UnionF32WithZsts {
Expand All @@ -154,7 +154,7 @@ pub union UnionF32WithZsts {

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


// All that remains to be tested are aggregates. They are tested in separate files called repr-
Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/target-cpu-on-functions.rs
Expand Up @@ -9,7 +9,7 @@

// CHECK-LABEL: define {{.*}} @exported() {{.*}} #0
#[no_mangle]
pub extern fn exported() {
pub extern "C" fn exported() {
not_exported();
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/unwind-extern-exports.rs
Expand Up @@ -11,7 +11,7 @@
// "C" ABI
// pub extern fn foo() {} // FIXME right now we don't abort-on-panic but add `nounwind` nevertheless
#[unwind(allowed)]
pub extern fn foo_allowed() {}
pub extern "C" fn foo_allowed() {}

// "Rust"
// (`extern "Rust"` could be removed as all `fn` get it implicitly; we leave it in for clarity.)
Expand Down
2 changes: 1 addition & 1 deletion src/test/incremental/hashes/inherent_impls.rs
Expand Up @@ -271,7 +271,7 @@ impl Foo {
impl Foo {
#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,fn_sig,typeck")]
#[rustc_clean(cfg="cfail3")]
pub extern fn make_method_extern(&self) { }
pub extern "C" fn make_method_extern(&self) { }
}


Expand Down
2 changes: 1 addition & 1 deletion src/test/incremental/hashes/trait_defs.rs
Expand Up @@ -312,7 +312,7 @@ trait TraitAddExternModifier {
trait TraitAddExternModifier {
#[rustc_dirty(label="hir_owner", cfg="cfail2")]
#[rustc_clean(label="hir_owner", cfg="cfail3")]
extern fn method();
extern "C" fn method();
}


Expand Down
4 changes: 2 additions & 2 deletions src/test/run-make-fulldeps/cdylib-dylib-linkage/foo.rs
Expand Up @@ -3,11 +3,11 @@
extern crate bar;

#[no_mangle]
pub extern fn foo() {
pub extern "C" fn foo() {
bar::bar();
}

#[no_mangle]
pub extern fn bar(a: u32, b: u32) -> u32 {
pub extern "C" fn bar(a: u32, b: u32) -> u32 {
a + b
}
2 changes: 1 addition & 1 deletion src/test/run-make-fulldeps/cdylib-fewer-symbols/foo.rs
@@ -1,6 +1,6 @@
#![crate_type = "cdylib"]

#[no_mangle]
pub extern fn foo() -> u32 {
pub extern "C" fn foo() -> u32 {
3
}
4 changes: 2 additions & 2 deletions src/test/run-make-fulldeps/cdylib/foo.rs
Expand Up @@ -3,11 +3,11 @@
extern crate bar;

#[no_mangle]
pub extern fn foo() {
pub extern "C" fn foo() {
bar::bar();
}

#[no_mangle]
pub extern fn bar(a: u32, b: u32) -> u32 {
pub extern "C" fn bar(a: u32, b: u32) -> u32 {
a + b
}
Expand Up @@ -3,6 +3,6 @@
extern crate upstream;

#[no_mangle]
pub extern fn bar() {
pub extern "C" fn bar() {
upstream::foo();
}
2 changes: 1 addition & 1 deletion src/test/run-make-fulldeps/glibc-staticlib-args/library.rs
@@ -1,4 +1,4 @@
#[no_mangle]
pub extern fn args_check() {
pub extern "C" fn args_check() {
assert_ne!(std::env::args_os().count(), 0);
}
2 changes: 1 addition & 1 deletion src/test/run-make-fulldeps/issue-14500/foo.rs
@@ -1,5 +1,5 @@
#[no_mangle]
pub extern fn foo() {}
pub extern "C" fn foo() {}

#[no_mangle]
pub static FOO_STATIC: u8 = 0;
@@ -1,5 +1,5 @@
#[no_mangle]
pub extern fn overflow() {
pub extern "C" fn overflow() {
let xs = [0, 1, 2, 3];
let _y = unsafe { *xs.as_ptr().offset(4) };
}
2 changes: 1 addition & 1 deletion src/test/run-make-fulldeps/sanitizer-dylib-link/library.rs
@@ -1,5 +1,5 @@
#[no_mangle]
pub extern fn overflow() {
pub extern "C" fn overflow() {
let xs = [0, 1, 2, 3];
let _y = unsafe { *xs.as_ptr().offset(4) };
}
@@ -1,5 +1,5 @@
#[no_mangle]
pub extern fn overflow() {
pub extern "C" fn overflow() {
let xs = [0, 1, 2, 3];
let _y = unsafe { *xs.as_ptr().offset(4) };
}
2 changes: 1 addition & 1 deletion src/test/run-make-fulldeps/static-dylib-by-default/bar.rs
Expand Up @@ -3,6 +3,6 @@
extern crate foo;

#[no_mangle]
pub extern fn bar() {
pub extern "C" fn bar() {
foo::foo();
}
2 changes: 1 addition & 1 deletion src/test/run-make-fulldeps/std-core-cycle/foo.rs
Expand Up @@ -6,6 +6,6 @@ extern crate bar;
static A: bar::A = bar::A;

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

0 comments on commit 4614671

Please sign in to comment.