File tree Expand file tree Collapse file tree 9 files changed +28
-18
lines changed
Expand file tree Collapse file tree 9 files changed +28
-18
lines changed Original file line number Diff line number Diff line change 11[package ]
22name = " builtins-test-intrinsics"
33version = " 0.1.0"
4- edition = " 2021 "
4+ edition = " 2024 "
55publish = false
66license = " MIT OR Apache-2.0"
77
Original file line number Diff line number Diff line change 1515
1616extern 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) ]
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ readme = "README.md"
77repository = " https://github.com/rust-lang/compiler-builtins"
88homepage = " https://github.com/rust-lang/compiler-builtins"
99documentation = " https://docs.rs/compiler_builtins"
10- edition = " 2021 "
10+ edition = " 2024 "
1111description = " Compiler intrinsics used by the Rust compiler."
1212links = " compiler-rt"
1313
Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff line change @@ -125,10 +125,10 @@ impl_normalization_shift!(
125125/// dependencies.
126126#[ inline]
127127fn 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) ]
229229fn 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}
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments