Skip to content

Commit ef4512b

Browse files
committed
Codegen 128bit atomic loads and stores for compiler builtins as trap
128bit atomics are unstable and only enabled on AArch64 and x86_64 macOS. Cranelift doesn't support 128bit atomics yet.
1 parent 31329f9 commit ef4512b

File tree

6 files changed

+39
-75
lines changed

6 files changed

+39
-75
lines changed

build_sysroot/Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build_sysroot/Cargo.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ compiler_builtins = { version = "0.1.39", default-features = false, features = [
1414
rustc-std-workspace-core = { path = "./sysroot_src/library/rustc-std-workspace-core" }
1515
rustc-std-workspace-alloc = { path = "./sysroot_src/library/rustc-std-workspace-alloc" }
1616
rustc-std-workspace-std = { path = "./sysroot_src/library/rustc-std-workspace-std" }
17-
compiler_builtins = { path = "./compiler-builtins" }
1817

1918
[profile.dev]
2019
lto = "off"
@@ -23,3 +22,14 @@ lto = "off"
2322
debug = true
2423
incremental = true
2524
lto = "off"
25+
26+
# Mandatory for correctly compiling compiler-builtins
27+
[profile.dev.package.compiler_builtins]
28+
debug-assertions = false
29+
overflow-checks = false
30+
codegen-units = 10000
31+
32+
[profile.release.package.compiler_builtins]
33+
debug-assertions = false
34+
overflow-checks = false
35+
codegen-units = 10000

build_system/prepare.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,6 @@ fn prepare_sysroot() {
8181
init_git_repo(&sysroot_src);
8282

8383
apply_patches("sysroot", &sysroot_src);
84-
85-
clone_repo_shallow_github(
86-
"build_sysroot/compiler-builtins",
87-
"rust-lang",
88-
"compiler-builtins",
89-
"0.1.70",
90-
);
91-
apply_patches("compiler-builtins", Path::new("build_sysroot/compiler-builtins"));
9284
}
9385

9486
#[allow(dead_code)]

patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch

Lines changed: 0 additions & 48 deletions
This file was deleted.

scripts/setup_rust_fork.sh

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@ git checkout -- .
1212
git checkout "$(rustc -V | cut -d' ' -f3 | tr -d '(')"
1313

1414
git apply - <<EOF
15-
diff --git a/Cargo.toml b/Cargo.toml
16-
index 5bd1147cad5..10d68a2ff14 100644
17-
--- a/Cargo.toml
18-
+++ b/Cargo.toml
19-
@@ -111,5 +111,7 @@ rustc-std-workspace-std = { path = 'library/rustc-std-workspace-std' }
20-
rustc-std-workspace-alloc = { path = 'library/rustc-std-workspace-alloc' }
21-
rustc-std-workspace-std = { path = 'library/rustc-std-workspace-std' }
22-
23-
+compiler_builtins = { path = "../build_sysroot/compiler-builtins" }
24-
+
25-
[patch."https://github.com/rust-lang/rust-clippy"]
26-
clippy_lints = { path = "src/tools/clippy/clippy_lints" }
2715
diff --git a/library/alloc/Cargo.toml b/library/alloc/Cargo.toml
2816
index d95b5b7f17f..00b6f0e3635 100644
2917
--- a/library/alloc/Cargo.toml

src/intrinsics/mod.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,18 @@ fn codegen_regular_intrinsic_call<'tcx>(
749749
_ if intrinsic.as_str().starts_with("atomic_load"), (v ptr) {
750750
let ty = substs.type_at(0);
751751
match ty.kind() {
752+
ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => {
753+
// FIXME implement 128bit atomics
754+
if fx.tcx.is_compiler_builtins(LOCAL_CRATE) {
755+
// special case for compiler-builtins to avoid having to patch it
756+
crate::trap::trap_unimplemented(fx, "128bit atomics not yet supported");
757+
let ret_block = fx.get_block(destination.unwrap().1);
758+
fx.bcx.ins().jump(ret_block, &[]);
759+
return;
760+
} else {
761+
fx.tcx.sess.span_fatal(span, "128bit atomics not yet supported");
762+
}
763+
}
752764
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
753765
_ => {
754766
report_atomic_type_validation_error(fx, intrinsic, span, ty);
@@ -765,6 +777,18 @@ fn codegen_regular_intrinsic_call<'tcx>(
765777
_ if intrinsic.as_str().starts_with("atomic_store"), (v ptr, c val) {
766778
let ty = substs.type_at(0);
767779
match ty.kind() {
780+
ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => {
781+
// FIXME implement 128bit atomics
782+
if fx.tcx.is_compiler_builtins(LOCAL_CRATE) {
783+
// special case for compiler-builtins to avoid having to patch it
784+
crate::trap::trap_unimplemented(fx, "128bit atomics not yet supported");
785+
let ret_block = fx.get_block(destination.unwrap().1);
786+
fx.bcx.ins().jump(ret_block, &[]);
787+
return;
788+
} else {
789+
fx.tcx.sess.span_fatal(span, "128bit atomics not yet supported");
790+
}
791+
}
768792
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
769793
_ => {
770794
report_atomic_type_validation_error(fx, intrinsic, span, ty);
@@ -1115,10 +1139,6 @@ fn codegen_regular_intrinsic_call<'tcx>(
11151139
};
11161140
}
11171141

1118-
if let Some((_, dest)) = destination {
1119-
let ret_block = fx.get_block(dest);
1120-
fx.bcx.ins().jump(ret_block, &[]);
1121-
} else {
1122-
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
1123-
}
1142+
let ret_block = fx.get_block(destination.unwrap().1);
1143+
fx.bcx.ins().jump(ret_block, &[]);
11241144
}

0 commit comments

Comments
 (0)