about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-01-13 13:56:15 +0000
committerbors <bors@rust-lang.org>2021-01-13 13:56:15 +0000
commitfd2df74902fa98bcb71f85fd548c3eb399e6a96a (patch)
treed88a7bde6091f82bd2ae5d492c66088ef705600d /src/test/codegen
parent116d1a7056830ccf649f74f823de4333ed329392 (diff)
parent4614671cae99ff35e61708ab64e9ba7850711750 (diff)
downloadrust-fd2df74902fa98bcb71f85fd548c3eb399e6a96a.tar.gz
rust-fd2df74902fa98bcb71f85fd548c3eb399e6a96a.zip
Auto merge of #76219 - Mark-Simulacrum:extern-require-abi, r=estebank
Add allow-by-default lint on implicit ABI in extern function pointers and items

This adds a new lint, missing_abi, which lints on omitted ABIs on extern blocks, function declarations, and function pointers.

It is currently not emitting the best possible diagnostics -- we need to track the span of "extern" at least or do some heuristic searching based on the available spans -- but seems good enough for an initial pass than can be expanded in future PRs.

This is a pretty large PR, but mostly due to updating a large number of tests to include ABIs; I can split that into a separate PR if it would be helpful, but test updates are already in dedicated commits.
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/call-llvm-intrinsics.rs2
-rw-r--r--src/test/codegen/dealloc-no-unwind.rs2
-rw-r--r--src/test/codegen/debug-column.rs2
-rw-r--r--src/test/codegen/debug-linkage-name.rs6
-rw-r--r--src/test/codegen/export-no-mangle.rs8
-rw-r--r--src/test/codegen/ffi-const.rs2
-rw-r--r--src/test/codegen/ffi-out-of-bounds-loads.rs2
-rw-r--r--src/test/codegen/ffi-pure.rs2
-rw-r--r--src/test/codegen/ffi-returns-twice.rs2
-rw-r--r--src/test/codegen/issue-47278.rs2
-rw-r--r--src/test/codegen/repr-transparent-aggregates-1.rs16
-rw-r--r--src/test/codegen/repr-transparent.rs34
-rw-r--r--src/test/codegen/riscv-abi/call-llvm-intrinsics.rs2
-rw-r--r--src/test/codegen/target-cpu-on-functions.rs2
-rw-r--r--src/test/codegen/unwind-extern-exports.rs2
-rw-r--r--src/test/codegen/unwind-extern-imports.rs2
16 files changed, 44 insertions, 44 deletions
diff --git a/src/test/codegen/call-llvm-intrinsics.rs b/src/test/codegen/call-llvm-intrinsics.rs
index 24e3d3cd64b..998099c2390 100644
--- a/src/test/codegen/call-llvm-intrinsics.rs
+++ b/src/test/codegen/call-llvm-intrinsics.rs
@@ -13,7 +13,7 @@ impl Drop for A {
     }
 }
 
-extern {
+extern "C" {
     #[link_name = "llvm.sqrt.f32"]
     fn sqrt(x: f32) -> f32;
 }
diff --git a/src/test/codegen/dealloc-no-unwind.rs b/src/test/codegen/dealloc-no-unwind.rs
index ff21b4caa83..f047c7a180c 100644
--- a/src/test/codegen/dealloc-no-unwind.rs
+++ b/src/test/codegen/dealloc-no-unwind.rs
@@ -8,7 +8,7 @@ struct A;
 
 impl Drop for A {
     fn drop(&mut self) {
-        extern { fn foo(); }
+        extern "C" { fn foo(); }
         unsafe { foo(); }
     }
 }
diff --git a/src/test/codegen/debug-column.rs b/src/test/codegen/debug-column.rs
index f348c48566d..5d3afef5289 100644
--- a/src/test/codegen/debug-column.rs
+++ b/src/test/codegen/debug-column.rs
@@ -18,7 +18,7 @@ fn main() {
     }
 }
 
-extern {
+extern "C" {
     fn giraffe();
     fn turtle();
 }
diff --git a/src/test/codegen/debug-linkage-name.rs b/src/test/codegen/debug-linkage-name.rs
index 0d7dca3aba3..9011a7da51d 100644
--- a/src/test/codegen/debug-linkage-name.rs
+++ b/src/test/codegen/debug-linkage-name.rs
@@ -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() {}
 }
diff --git a/src/test/codegen/export-no-mangle.rs b/src/test/codegen/export-no-mangle.rs
index 59e97601c83..a89d48ee153 100644
--- a/src/test/codegen/export-no-mangle.rs
+++ b/src/test/codegen/export-no-mangle.rs
@@ -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() {}
 }
diff --git a/src/test/codegen/ffi-const.rs b/src/test/codegen/ffi-const.rs
index 440d022a12c..67baf6fdd3e 100644
--- a/src/test/codegen/ffi-const.rs
+++ b/src/test/codegen/ffi-const.rs
@@ -4,7 +4,7 @@
 
 pub fn bar() { unsafe { foo() } }
 
-extern {
+extern "C" {
     // CHECK-LABEL: declare void @foo()
     // CHECK-SAME: [[ATTRS:#[0-9]+]]
     // CHECK-DAG: attributes [[ATTRS]] = { {{.*}}readnone{{.*}} }
diff --git a/src/test/codegen/ffi-out-of-bounds-loads.rs b/src/test/codegen/ffi-out-of-bounds-loads.rs
index 139a06ab53d..dc16306eb96 100644
--- a/src/test/codegen/ffi-out-of-bounds-loads.rs
+++ b/src/test/codegen/ffi-out-of-bounds-loads.rs
@@ -11,7 +11,7 @@ struct S {
     f3: i32,
 }
 
-extern {
+extern "C" {
     fn foo(s: S);
 }
 
diff --git a/src/test/codegen/ffi-pure.rs b/src/test/codegen/ffi-pure.rs
index f0ebc1caa09..3afb0856c9d 100644
--- a/src/test/codegen/ffi-pure.rs
+++ b/src/test/codegen/ffi-pure.rs
@@ -4,7 +4,7 @@
 
 pub fn bar() { unsafe { foo() } }
 
-extern {
+extern "C" {
     // CHECK-LABEL: declare void @foo()
     // CHECK-SAME: [[ATTRS:#[0-9]+]]
     // CHECK-DAG: attributes [[ATTRS]] = { {{.*}}readonly{{.*}} }
diff --git a/src/test/codegen/ffi-returns-twice.rs b/src/test/codegen/ffi-returns-twice.rs
index 4db328f1cdf..75301dfd346 100644
--- a/src/test/codegen/ffi-returns-twice.rs
+++ b/src/test/codegen/ffi-returns-twice.rs
@@ -4,7 +4,7 @@
 
 pub fn bar() { unsafe { foo() } }
 
-extern {
+extern "C" {
     // CHECK-LABEL: declare void @foo()
     // CHECK-SAME: [[ATTRS:#[0-9]+]]
     // CHECK-DAG: attributes [[ATTRS]] = { {{.*}}returns_twice{{.*}} }
diff --git a/src/test/codegen/issue-47278.rs b/src/test/codegen/issue-47278.rs
index 590e8ea8502..9076274f45e 100644
--- a/src/test/codegen/issue-47278.rs
+++ b/src/test/codegen/issue-47278.rs
@@ -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 {} }
diff --git a/src/test/codegen/repr-transparent-aggregates-1.rs b/src/test/codegen/repr-transparent-aggregates-1.rs
index 59f29e756fc..2b8d3c8bc1d 100644
--- a/src/test/codegen/repr-transparent-aggregates-1.rs
+++ b/src/test/codegen/repr-transparent-aggregates-1.rs
@@ -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)]
@@ -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 {} }
diff --git a/src/test/codegen/repr-transparent.rs b/src/test/codegen/repr-transparent.rs
index 7647e019876..29997313511 100644
--- a/src/test/codegen/repr-transparent.rs
+++ b/src/test/codegen/repr-transparent.rs
@@ -19,21 +19,21 @@ 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]);
@@ -41,14 +41,14 @@ 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);
@@ -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)]
@@ -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);
@@ -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; }
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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-
diff --git a/src/test/codegen/riscv-abi/call-llvm-intrinsics.rs b/src/test/codegen/riscv-abi/call-llvm-intrinsics.rs
index f100a23a318..31a88f2c0a9 100644
--- a/src/test/codegen/riscv-abi/call-llvm-intrinsics.rs
+++ b/src/test/codegen/riscv-abi/call-llvm-intrinsics.rs
@@ -13,7 +13,7 @@ impl Drop for A {
     }
 }
 
-extern {
+extern "C" {
     #[link_name = "llvm.sqrt.f32"]
     fn sqrt(x: f32) -> f32;
 }
diff --git a/src/test/codegen/target-cpu-on-functions.rs b/src/test/codegen/target-cpu-on-functions.rs
index 523216deb84..7544ac01309 100644
--- a/src/test/codegen/target-cpu-on-functions.rs
+++ b/src/test/codegen/target-cpu-on-functions.rs
@@ -9,7 +9,7 @@
 
 // CHECK-LABEL: define {{.*}} @exported() {{.*}} #0
 #[no_mangle]
-pub extern fn exported() {
+pub extern "C" fn exported() {
     not_exported();
 }
 
diff --git a/src/test/codegen/unwind-extern-exports.rs b/src/test/codegen/unwind-extern-exports.rs
index e5a2936b924..487de20671a 100644
--- a/src/test/codegen/unwind-extern-exports.rs
+++ b/src/test/codegen/unwind-extern-exports.rs
@@ -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.)
diff --git a/src/test/codegen/unwind-extern-imports.rs b/src/test/codegen/unwind-extern-imports.rs
index 8403e1e9da9..a2ba24aca25 100644
--- a/src/test/codegen/unwind-extern-imports.rs
+++ b/src/test/codegen/unwind-extern-imports.rs
@@ -4,7 +4,7 @@
 #![crate_type = "lib"]
 #![feature(unwind_attributes)]
 
-extern {
+extern "C" {
 // CHECK: Function Attrs:{{.*}}nounwind
 // CHECK-NEXT: declare void @extern_fn
     fn extern_fn();