Skip to content

Change compiler-builtins to edition 2024 #757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion builtins-test-intrinsics/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "builtins-test-intrinsics"
version = "0.1.0"
edition = "2021"
edition = "2024"
publish = false
license = "MIT OR Apache-2.0"

Expand Down
6 changes: 4 additions & 2 deletions builtins-test-intrinsics/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@

extern crate panic_handler;

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

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

// SAFETY: no definitions, only used for linking
#[cfg(windows)]
#[link(name = "kernel32")]
#[link(name = "msvcrt")]
extern "C" {}
unsafe extern "C" {}

// ARM targets need these symbols
#[unsafe(no_mangle)]
Expand Down
3 changes: 2 additions & 1 deletion builtins-test/tests/aeabi_memclr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ macro_rules! panic {
};
}

extern "C" {
// SAFETY: defined in compiler-builtins
unsafe extern "aapcs" {
fn __aeabi_memclr4(dest: *mut u8, n: usize);
fn __aeabi_memset4(dest: *mut u8, n: usize, c: u32);
}
Expand Down
3 changes: 2 additions & 1 deletion builtins-test/tests/aeabi_memcpy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ macro_rules! panic {
};
}

extern "C" {
// SAFETY: defined in compiler-builtins
unsafe extern "aapcs" {
fn __aeabi_memcpy(dest: *mut u8, src: *const u8, n: usize);
fn __aeabi_memcpy4(dest: *mut u8, src: *const u8, n: usize);
}
Expand Down
3 changes: 2 additions & 1 deletion builtins-test/tests/aeabi_memset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ macro_rules! panic {
};
}

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

Expand Down
2 changes: 1 addition & 1 deletion compiler-builtins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ readme = "README.md"
repository = "https://github.com/rust-lang/compiler-builtins"
homepage = "https://github.com/rust-lang/compiler-builtins"
documentation = "https://docs.rs/compiler_builtins"
edition = "2021"
edition = "2024"
description = "Compiler intrinsics used by the Rust compiler."
links = "compiler-rt"

Expand Down
7 changes: 5 additions & 2 deletions compiler-builtins/src/arm.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#![cfg(not(feature = "no-asm"))]

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

extern "aapcs" {
// SAFETY: these are defined in compiler-builtins
// FIXME(extern_custom), this isn't always the correct ABI
unsafe extern "aapcs" {
// AAPCS is not always the correct ABI for these intrinsics, but we only use this to
// forward another `__aeabi_` call so it doesn't matter.
fn __aeabi_idiv(a: i32, b: i32) -> i32;
Expand Down
16 changes: 8 additions & 8 deletions compiler-builtins/src/int/specialized_div_rem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ impl_normalization_shift!(
/// dependencies.
#[inline]
fn u64_by_u64_div_rem(duo: u64, div: u64) -> (u64, u64) {
if let Some(quo) = duo.checked_div(div) {
if let Some(rem) = duo.checked_rem(div) {
return (quo, rem);
}
if let Some(quo) = duo.checked_div(div)
&& let Some(rem) = duo.checked_rem(div)
{
return (quo, rem);
}
zero_div_fn()
}
Expand Down Expand Up @@ -227,10 +227,10 @@ impl_asymmetric!(
#[inline]
#[allow(dead_code)]
fn u32_by_u32_div_rem(duo: u32, div: u32) -> (u32, u32) {
if let Some(quo) = duo.checked_div(div) {
if let Some(rem) = duo.checked_rem(div) {
return (quo, rem);
}
if let Some(quo) = duo.checked_div(div)
&& let Some(rem) = duo.checked_rem(div)
{
return (quo, rem);
}
zero_div_fn()
}
Expand Down
4 changes: 2 additions & 2 deletions compiler-builtins/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ macro_rules! intrinsics {
) => (
#[cfg($name = "optimized-c")]
pub $(unsafe $($empty)? )? extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
extern $abi {
unsafe extern $abi {
fn $name($($argname: $ty),*) $(-> $ret)?;
}
unsafe {
Expand Down Expand Up @@ -435,7 +435,7 @@ macro_rules! intrinsics {
pub mod $name {
#[unsafe(naked)]
$(#[$($attr)*])*
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
#[cfg_attr(not(feature = "mangled-names"), unsafe(no_mangle))]
#[cfg_attr(not(any(all(windows, target_env = "gnu"), target_os = "cygwin")), linkage = "weak")]
pub unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
$($body)*
Expand Down
4 changes: 3 additions & 1 deletion compiler-builtins/src/probestack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
// We only define stack probing for these architectures today.
#![cfg(any(target_arch = "x86_64", target_arch = "x86"))]

extern "C" {
// SAFETY: defined in this module.
// FIXME(extern_custom): the ABI is not correct.
unsafe extern "C" {
pub fn __rust_probestack();
}

Expand Down
15 changes: 8 additions & 7 deletions crates/symbol-check/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ fn main() {
/// Run `cargo build` with the provided additional arguments, collecting the list of created
/// libraries.
fn exec_cargo_with_args(args: &[&str]) -> Vec<PathBuf> {
let mut cmd = Command::new("cargo")
.arg("build")
let mut cmd = Command::new("cargo");
cmd.arg("build")
.arg("--message-format=json")
.args(args)
.stdout(Stdio::piped())
.spawn()
.expect("failed to launch Cargo");
.stdout(Stdio::piped());

let stdout = cmd.stdout.take().unwrap();
println!("running: {cmd:?}");
let mut child = cmd.spawn().expect("failed to launch Cargo");

let stdout = child.stdout.take().unwrap();
let reader = BufReader::new(stdout);
let mut check_files = Vec::new();

Expand Down Expand Up @@ -84,7 +85,7 @@ fn exec_cargo_with_args(args: &[&str]) -> Vec<PathBuf> {
}
}

assert!(cmd.wait().expect("failed to wait on Cargo").success());
assert!(child.wait().expect("failed to wait on Cargo").success());

assert!(!check_files.is_empty(), "no compiler_builtins rlibs found");
println!("Collected the following rlibs to check: {check_files:#?}");
Expand Down
Loading