Skip to content

Commit 21e8e68

Browse files
committed
Change compiler-builtins to edition 2024
Do the same for `builtins-test-intrinsics`. Mostly this means updating `extern` to `unsafe extern`, and fixing a few new Clippy lints.
1 parent bfd4058 commit 21e8e68

File tree

10 files changed

+29
-19
lines changed

10 files changed

+29
-19
lines changed

builtins-test-intrinsics/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "builtins-test-intrinsics"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55
publish = false
66
license = "MIT OR Apache-2.0"
77

builtins-test-intrinsics/src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515

1616
extern crate panic_handler;
1717

18+
// SAFETY: no definitions, only used for linking
1819
#[cfg(all(not(thumb), not(windows), not(target_arch = "wasm32")))]
1920
#[link(name = "c")]
20-
extern "C" {}
21+
unsafe extern "C" {}
2122

2223
// Every function in this module maps will be lowered to an intrinsic by LLVM, if the platform
2324
// doesn't have native support for the operation used in the function. ARM has a naming convention
@@ -663,10 +664,11 @@ pub fn _start() -> ! {
663664
loop {}
664665
}
665666

667+
// SAFETY: no definitions, only used for linking
666668
#[cfg(windows)]
667669
#[link(name = "kernel32")]
668670
#[link(name = "msvcrt")]
669-
extern "C" {}
671+
unsafe extern "C" {}
670672

671673
// ARM targets need these symbols
672674
#[unsafe(no_mangle)]

builtins-test/tests/aeabi_memclr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ macro_rules! panic {
2424
};
2525
}
2626

27-
extern "C" {
27+
// SAFETY: defined in compiler-builtins
28+
unsafe extern "aapcs" {
2829
fn __aeabi_memclr4(dest: *mut u8, n: usize);
2930
fn __aeabi_memset4(dest: *mut u8, n: usize, c: u32);
3031
}

builtins-test/tests/aeabi_memcpy.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ macro_rules! panic {
2222
};
2323
}
2424

25-
extern "C" {
25+
// SAFETY: defined in compiler-builtins
26+
unsafe extern "aapcs" {
2627
fn __aeabi_memcpy(dest: *mut u8, src: *const u8, n: usize);
2728
fn __aeabi_memcpy4(dest: *mut u8, src: *const u8, n: usize);
2829
}

builtins-test/tests/aeabi_memset.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ macro_rules! panic {
2424
};
2525
}
2626

27-
extern "C" {
27+
// SAFETY: defined in compiler-builtins
28+
unsafe extern "aapcs" {
2829
fn __aeabi_memset4(dest: *mut u8, n: usize, c: u32);
2930
}
3031

compiler-builtins/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ readme = "README.md"
77
repository = "https://github.com/rust-lang/compiler-builtins"
88
homepage = "https://github.com/rust-lang/compiler-builtins"
99
documentation = "https://docs.rs/compiler_builtins"
10-
edition = "2021"
10+
edition = "2024"
1111
description = "Compiler intrinsics used by the Rust compiler."
1212
links = "compiler-rt"
1313

compiler-builtins/src/arm.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
#![cfg(not(feature = "no-asm"))]
22

33
// Interfaces used by naked trampolines.
4-
extern "C" {
4+
// SAFETY: these are defined in compiler-builtins
5+
unsafe extern "C" {
56
fn __udivmodsi4(a: u32, b: u32, rem: *mut u32) -> u32;
67
fn __udivmoddi4(a: u64, b: u64, rem: *mut u64) -> u64;
78
fn __divmoddi4(a: i64, b: i64, rem: *mut i64) -> i64;
89
}
910

10-
extern "aapcs" {
11+
// SAFETY: these are defined in compiler-builtins
12+
// FIXME(extern_custom), this isn't always the correct ABI
13+
unsafe extern "aapcs" {
1114
// AAPCS is not always the correct ABI for these intrinsics, but we only use this to
1215
// forward another `__aeabi_` call so it doesn't matter.
1316
fn __aeabi_idiv(a: i32, b: i32) -> i32;

compiler-builtins/src/int/specialized_div_rem/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ impl_normalization_shift!(
125125
/// dependencies.
126126
#[inline]
127127
fn u64_by_u64_div_rem(duo: u64, div: u64) -> (u64, u64) {
128-
if let Some(quo) = duo.checked_div(div) {
129-
if let Some(rem) = duo.checked_rem(div) {
130-
return (quo, rem);
131-
}
128+
if let Some(quo) = duo.checked_div(div)
129+
&& let Some(rem) = duo.checked_rem(div)
130+
{
131+
return (quo, rem);
132132
}
133133
zero_div_fn()
134134
}
@@ -227,10 +227,10 @@ impl_asymmetric!(
227227
#[inline]
228228
#[allow(dead_code)]
229229
fn u32_by_u32_div_rem(duo: u32, div: u32) -> (u32, u32) {
230-
if let Some(quo) = duo.checked_div(div) {
231-
if let Some(rem) = duo.checked_rem(div) {
232-
return (quo, rem);
233-
}
230+
if let Some(quo) = duo.checked_div(div)
231+
&& let Some(rem) = duo.checked_rem(div)
232+
{
233+
return (quo, rem);
234234
}
235235
zero_div_fn()
236236
}

compiler-builtins/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ macro_rules! intrinsics {
435435
pub mod $name {
436436
#[unsafe(naked)]
437437
$(#[$($attr)*])*
438-
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
438+
#[cfg_attr(not(feature = "mangled-names"), unsafe(no_mangle))]
439439
#[cfg_attr(not(any(all(windows, target_env = "gnu"), target_os = "cygwin")), linkage = "weak")]
440440
pub unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
441441
$($body)*

compiler-builtins/src/probestack.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
// We only define stack probing for these architectures today.
5050
#![cfg(any(target_arch = "x86_64", target_arch = "x86"))]
5151

52-
extern "C" {
52+
// SAFETY: defined in this module.
53+
// FIXME(extern_custom): the ABI is not correct.
54+
unsafe extern "C" {
5355
pub fn __rust_probestack();
5456
}
5557

0 commit comments

Comments
 (0)