Skip to content

Commit c9c9f52

Browse files
committed
Auto merge of rust-lang#119117 - bjorn3:sync_cg_clif-2023-12-19, r=bjorn3
Subtree sync for rustc_codegen_cranelift The main highlight is a couple of fixes around size, alignment and field offset computations for foreign and packed unsized types. As well as a fix for the signature of simd_scatter which a recent PR accidentally messed up. r? `@ghost` `@rustbot` label +A-codegen +A-cranelift +T-compiler
2 parents 558ac1c + d5c38de commit c9c9f52

13 files changed

+225
-117
lines changed

compiler/rustc_codegen_cranelift/build_system/tests.rs

+7
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
232232
if runner.is_native {
233233
let mut test_cmd = PORTABLE_SIMD.test(&runner.target_compiler, &runner.dirs);
234234
test_cmd.arg("-q");
235+
// FIXME remove after portable-simd update
236+
test_cmd
237+
.arg("--")
238+
.arg("--skip")
239+
.arg("core_simd::swizzle::simd_swizzle")
240+
.arg("--skip")
241+
.arg("core_simd::vector::Simd<T,N>::lanes");
235242
spawn_and_wait(test_cmd);
236243
}
237244
}),

compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs

-11
Original file line numberDiff line numberDiff line change
@@ -337,17 +337,6 @@ fn main() {
337337
static REF2: &u8 = REF1;
338338
assert_eq!(*REF1, *REF2);
339339

340-
extern "C" {
341-
type A;
342-
}
343-
344-
fn main() {
345-
let x: &A = unsafe { &*(1usize as *const A) };
346-
347-
assert_eq!(unsafe { intrinsics::size_of_val(x) }, 0);
348-
assert_eq!(unsafe { intrinsics::min_align_of_val(x) }, 1);
349-
}
350-
351340
#[repr(simd)]
352341
struct V([f64; 2]);
353342

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
From a101a43b795431ce617e7782afb451f4853afc00 Mon Sep 17 00:00:00 2001
2+
From: bjorn3 <17426603+bjorn3@users.noreply.github.com>
3+
Date: Thu, 7 Dec 2023 14:51:35 +0000
4+
Subject: [PATCH] Enable the exposed_provenance feature
5+
6+
---
7+
crates/core_simd/tests/pointers.rs | 2 +-
8+
1 file changed, 1 insertion(+), 1 deletion(-)
9+
10+
diff --git a/crates/core_simd/tests/pointers.rs b/crates/core_simd/tests/pointers.rs
11+
index 0ae8f83..06620d6 100644
12+
--- a/crates/core_simd/tests/pointers.rs
13+
+++ b/crates/core_simd/tests/pointers.rs
14+
@@ -1,4 +1,4 @@
15+
-#![feature(portable_simd, strict_provenance)]
16+
+#![feature(exposed_provenance, portable_simd, strict_provenance)]
17+
18+
use core_simd::simd::{Simd, SimdConstPtr, SimdMutPtr};
19+
20+
--
21+
2.34.1
22+

compiler/rustc_codegen_cranelift/patches/stdlib-lock.toml

+35-20
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,18 @@ dependencies = [
3636

3737
[[package]]
3838
name = "allocator-api2"
39-
version = "0.2.15"
39+
version = "0.2.16"
4040
source = "registry+https://github.com/rust-lang/crates.io-index"
41-
checksum = "56fc6cf8dc8c4158eed8649f9b8b0ea1518eb62b544fe9490d66fa0b349eafe9"
41+
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
4242

4343
[[package]]
4444
name = "cc"
45-
version = "1.0.79"
45+
version = "1.0.83"
4646
source = "registry+https://github.com/rust-lang/crates.io-index"
47-
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
47+
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
48+
dependencies = [
49+
"libc",
50+
]
4851

4952
[[package]]
5053
name = "cfg-if"
@@ -58,9 +61,9 @@ dependencies = [
5861

5962
[[package]]
6063
name = "compiler_builtins"
61-
version = "0.1.103"
64+
version = "0.1.104"
6265
source = "registry+https://github.com/rust-lang/crates.io-index"
63-
checksum = "a3b73c3443a5fd2438d7ba4853c64e4c8efc2404a9e28a9234cc2d5eebc6c242"
66+
checksum = "99c3f9035afc33f4358773239573f7d121099856753e1bbd2a6a5207098fc741"
6467
dependencies = [
6568
"cc",
6669
"rustc-std-workspace-core",
@@ -124,9 +127,9 @@ dependencies = [
124127

125128
[[package]]
126129
name = "gimli"
127-
version = "0.28.0"
130+
version = "0.28.1"
128131
source = "registry+https://github.com/rust-lang/crates.io-index"
129-
checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"
132+
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
130133
dependencies = [
131134
"compiler_builtins",
132135
"rustc-std-workspace-alloc",
@@ -135,9 +138,9 @@ dependencies = [
135138

136139
[[package]]
137140
name = "hashbrown"
138-
version = "0.14.0"
141+
version = "0.14.3"
139142
source = "registry+https://github.com/rust-lang/crates.io-index"
140-
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
143+
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
141144
dependencies = [
142145
"allocator-api2",
143146
"compiler_builtins",
@@ -147,9 +150,9 @@ dependencies = [
147150

148151
[[package]]
149152
name = "hermit-abi"
150-
version = "0.3.2"
153+
version = "0.3.3"
151154
source = "registry+https://github.com/rust-lang/crates.io-index"
152-
checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b"
155+
checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
153156
dependencies = [
154157
"compiler_builtins",
155158
"rustc-std-workspace-alloc",
@@ -167,9 +170,9 @@ dependencies = [
167170

168171
[[package]]
169172
name = "memchr"
170-
version = "2.5.0"
173+
version = "2.6.4"
171174
source = "registry+https://github.com/rust-lang/crates.io-index"
172-
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
175+
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
173176
dependencies = [
174177
"compiler_builtins",
175178
"rustc-std-workspace-core",
@@ -189,9 +192,9 @@ dependencies = [
189192

190193
[[package]]
191194
name = "object"
192-
version = "0.32.0"
195+
version = "0.32.1"
193196
source = "registry+https://github.com/rust-lang/crates.io-index"
194-
checksum = "77ac5bbd07aea88c60a577a1ce218075ffd59208b2d7ca97adf9bfc5aeb21ebe"
197+
checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0"
195198
dependencies = [
196199
"compiler_builtins",
197200
"memchr",
@@ -241,9 +244,9 @@ dependencies = [
241244

242245
[[package]]
243246
name = "r-efi"
244-
version = "4.2.0"
247+
version = "4.3.0"
245248
source = "registry+https://github.com/rust-lang/crates.io-index"
246-
checksum = "575fc2d9b3da54adbdfaddf6eca48fec256d977c8630a1750b8991347d1ac911"
249+
checksum = "0e244f96e03a3067f9e521d3167bd42657594cb8588c8d3a2db01545dc1af2e0"
247250
dependencies = [
248251
"compiler_builtins",
249252
"rustc-std-workspace-core",
@@ -402,9 +405,9 @@ dependencies = [
402405

403406
[[package]]
404407
name = "unicode-width"
405-
version = "0.1.10"
408+
version = "0.1.11"
406409
source = "registry+https://github.com/rust-lang/crates.io-index"
407-
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
410+
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
408411
dependencies = [
409412
"compiler_builtins",
410413
"rustc-std-workspace-core",
@@ -419,6 +422,18 @@ dependencies = [
419422
"compiler_builtins",
420423
"core",
421424
"libc",
425+
"unwinding",
426+
]
427+
428+
[[package]]
429+
name = "unwinding"
430+
version = "0.2.1"
431+
source = "registry+https://github.com/rust-lang/crates.io-index"
432+
checksum = "37a19a21a537f635c16c7576f22d0f2f7d63353c1337ad4ce0d8001c7952a25b"
433+
dependencies = [
434+
"compiler_builtins",
435+
"gimli",
436+
"rustc-std-workspace-core",
422437
]
423438

424439
[[package]]
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2023-11-25"
2+
channel = "nightly-2023-12-19"
33
components = ["rust-src", "rustc-dev", "llvm-tools"]

compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ rm tests/ui/proc-macro/no-mangle-in-proc-macro-issue-111888.rs
4444
# vendor intrinsics
4545
rm tests/ui/sse2.rs # CodegenBackend::target_features not yet implemented
4646
rm tests/ui/simd/array-type.rs # "Index argument for `simd_insert` is not a constant"
47+
rm tests/ui/simd/masked-load-store.rs
4748

4849
# exotic linkages
4950
rm tests/ui/issues/issue-33992.rs # unsupported linkages

compiler/rustc_codegen_cranelift/src/base.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
353353
fx,
354354
rustc_hir::LangItem::PanicBoundsCheck,
355355
&[index, len, location],
356-
source_info.span,
356+
Some(source_info.span),
357357
);
358358
}
359359
AssertKind::MisalignedPointerDereference { ref required, ref found } => {
@@ -365,7 +365,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
365365
fx,
366366
rustc_hir::LangItem::PanicMisalignedPointerDereference,
367367
&[required, found, location],
368-
source_info.span,
368+
Some(source_info.span),
369369
);
370370
}
371371
_ => {
@@ -945,19 +945,19 @@ pub(crate) fn codegen_panic<'tcx>(
945945
let msg_len = fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(msg_str.len()).unwrap());
946946
let args = [msg_ptr, msg_len, location];
947947

948-
codegen_panic_inner(fx, rustc_hir::LangItem::Panic, &args, source_info.span);
948+
codegen_panic_inner(fx, rustc_hir::LangItem::Panic, &args, Some(source_info.span));
949949
}
950950

951951
pub(crate) fn codegen_panic_nounwind<'tcx>(
952952
fx: &mut FunctionCx<'_, '_, 'tcx>,
953953
msg_str: &str,
954-
source_info: mir::SourceInfo,
954+
span: Option<Span>,
955955
) {
956956
let msg_ptr = fx.anonymous_str(msg_str);
957957
let msg_len = fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(msg_str.len()).unwrap());
958958
let args = [msg_ptr, msg_len];
959959

960-
codegen_panic_inner(fx, rustc_hir::LangItem::PanicNounwind, &args, source_info.span);
960+
codegen_panic_inner(fx, rustc_hir::LangItem::PanicNounwind, &args, span);
961961
}
962962

963963
pub(crate) fn codegen_unwind_terminate<'tcx>(
@@ -967,16 +967,16 @@ pub(crate) fn codegen_unwind_terminate<'tcx>(
967967
) {
968968
let args = [];
969969

970-
codegen_panic_inner(fx, reason.lang_item(), &args, source_info.span);
970+
codegen_panic_inner(fx, reason.lang_item(), &args, Some(source_info.span));
971971
}
972972

973973
fn codegen_panic_inner<'tcx>(
974974
fx: &mut FunctionCx<'_, '_, 'tcx>,
975975
lang_item: rustc_hir::LangItem,
976976
args: &[Value],
977-
span: Span,
977+
span: Option<Span>,
978978
) {
979-
let def_id = fx.tcx.require_lang_item(lang_item, Some(span));
979+
let def_id = fx.tcx.require_lang_item(lang_item, span);
980980

981981
let instance = Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx);
982982
let symbol_name = fx.tcx.symbol_name(instance).name;

compiler/rustc_codegen_cranelift/src/common.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,15 @@ fn clif_pair_type_from_ty<'tcx>(
9898

9999
/// Is a pointer to this type a fat ptr?
100100
pub(crate) fn has_ptr_meta<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
101-
let ptr_ty = Ty::new_ptr(tcx, TypeAndMut { ty, mutbl: rustc_hir::Mutability::Not });
102-
match &tcx.layout_of(ParamEnv::reveal_all().and(ptr_ty)).unwrap().abi {
103-
Abi::Scalar(_) => false,
104-
Abi::ScalarPair(_, _) => true,
105-
abi => unreachable!("Abi of ptr to {:?} is {:?}???", ty, abi),
101+
if ty.is_sized(tcx, ParamEnv::reveal_all()) {
102+
return false;
103+
}
104+
105+
let tail = tcx.struct_tail_erasing_lifetimes(ty, ParamEnv::reveal_all());
106+
match tail.kind() {
107+
ty::Foreign(..) => false,
108+
ty::Str | ty::Slice(..) | ty::Dynamic(..) => true,
109+
_ => bug!("unexpected unsized tail: {:?}", tail),
106110
}
107111
}
108112

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -487,13 +487,12 @@ fn codegen_regular_intrinsic_call<'tcx>(
487487
let layout = fx.layout_of(generic_args.type_at(0));
488488
// Note: Can't use is_unsized here as truly unsized types need to take the fixed size
489489
// branch
490-
let size = if let Abi::ScalarPair(_, _) = ptr.layout().abi {
491-
let (_ptr, info) = ptr.load_scalar_pair(fx);
492-
let (size, _align) = crate::unsize::size_and_align_of_dst(fx, layout, info);
493-
size
490+
let meta = if let Abi::ScalarPair(_, _) = ptr.layout().abi {
491+
Some(ptr.load_scalar_pair(fx).1)
494492
} else {
495-
fx.bcx.ins().iconst(fx.pointer_type, layout.size.bytes() as i64)
493+
None
496494
};
495+
let (size, _align) = crate::unsize::size_and_align_of(fx, layout, meta);
497496
ret.write_cvalue(fx, CValue::by_val(size, usize_layout));
498497
}
499498
sym::min_align_of_val => {
@@ -502,13 +501,12 @@ fn codegen_regular_intrinsic_call<'tcx>(
502501
let layout = fx.layout_of(generic_args.type_at(0));
503502
// Note: Can't use is_unsized here as truly unsized types need to take the fixed size
504503
// branch
505-
let align = if let Abi::ScalarPair(_, _) = ptr.layout().abi {
506-
let (_ptr, info) = ptr.load_scalar_pair(fx);
507-
let (_size, align) = crate::unsize::size_and_align_of_dst(fx, layout, info);
508-
align
504+
let meta = if let Abi::ScalarPair(_, _) = ptr.layout().abi {
505+
Some(ptr.load_scalar_pair(fx).1)
509506
} else {
510-
fx.bcx.ins().iconst(fx.pointer_type, layout.align.abi.bytes() as i64)
507+
None
511508
};
509+
let (_size, align) = crate::unsize::size_and_align_of(fx, layout, meta);
512510
ret.write_cvalue(fx, CValue::by_val(align, usize_layout));
513511
}
514512

@@ -688,7 +686,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
688686
}
689687
})
690688
});
691-
crate::base::codegen_panic_nounwind(fx, &msg_str, source_info);
689+
crate::base::codegen_panic_nounwind(fx, &msg_str, Some(source_info.span));
692690
return;
693691
}
694692
}

0 commit comments

Comments
 (0)