Skip to content

Commit ef15265

Browse files
committed
Auto merge of #146318 - matthiaskrgr:rollup-9a8s6fv, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #144549 (match clang's `va_arg` assembly on arm targets) - #146184 (In the rustc_llvm build script, don't consider arm64* to be 32-bit) - #146298 (GVN: Ensure indirect is first projection in try_as_place.) - #146299 (docs(std): add error docs for path canonicalize) - #146300 (Implement `Sum` and `Product` for `f16` and `f128`.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a09fbe2 + 2c7abaa commit ef15265

File tree

9 files changed

+85
-3
lines changed

9 files changed

+85
-3
lines changed

compiler/rustc_codegen_llvm/src/va_arg.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,21 @@ pub(super) fn emit_va_arg<'ll, 'tcx>(
908908
)
909909
}
910910
"aarch64" => emit_aapcs_va_arg(bx, addr, target_ty),
911+
"arm" => {
912+
// Types wider than 16 bytes are not currently supported. Clang has special logic for
913+
// such types, but `VaArgSafe` is not implemented for any type that is this large.
914+
assert!(bx.cx.size_of(target_ty).bytes() <= 16);
915+
916+
emit_ptr_va_arg(
917+
bx,
918+
addr,
919+
target_ty,
920+
PassMode::Direct,
921+
SlotSize::Bytes4,
922+
AllowHigherAlign::Yes,
923+
ForceRightAdjust::No,
924+
)
925+
}
911926
"s390x" => emit_s390x_va_arg(bx, addr, target_ty),
912927
"powerpc" => emit_powerpc_va_arg(bx, addr, target_ty),
913928
"powerpc64" | "powerpc64le" => emit_ptr_va_arg(

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
520520
LocalRef::Place(va_list) => {
521521
bx.va_end(va_list.val.llval);
522522

523-
// Explicitly end the lifetime of the `va_list`, this matters for LLVM.
523+
// Explicitly end the lifetime of the `va_list`, improves LLVM codegen.
524524
bx.lifetime_end(va_list.val.llval, va_list.layout.size);
525525
}
526526
_ => bug!("C-variadic function must have a `VaList` place"),

compiler/rustc_codegen_ssa/src/mir/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,10 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
438438

439439
if fx.fn_abi.c_variadic && arg_index == fx.fn_abi.args.len() {
440440
let va_list = PlaceRef::alloca(bx, bx.layout_of(arg_ty));
441+
442+
// Explicitly start the lifetime of the `va_list`, improves LLVM codegen.
443+
bx.lifetime_start(va_list.val.llval, va_list.layout.size);
444+
441445
bx.va_start(va_list.val.llval);
442446

443447
return LocalRef::Place(va_list);

compiler/rustc_llvm/build.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,10 @@ fn main() {
254254
println!("cargo:rustc-link-lib=kstat");
255255
}
256256

257-
if (target.starts_with("arm") && !target.contains("freebsd") && !target.contains("ohos"))
257+
if (target.starts_with("arm")
258+
&& !target.starts_with("arm64")
259+
&& !target.contains("freebsd")
260+
&& !target.contains("ohos"))
258261
|| target.starts_with("mips-")
259262
|| target.starts_with("mipsel-")
260263
|| target.starts_with("powerpc-")

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,11 @@ impl<'tcx> VnState<'_, 'tcx> {
16441644
let place =
16451645
Place { local, projection: self.tcx.mk_place_elems(projection.as_slice()) };
16461646
return Some(place);
1647+
} else if projection.last() == Some(&PlaceElem::Deref) {
1648+
// `Deref` can only be the first projection in a place.
1649+
// If we are here, we failed to find a local, and we already have a `Deref`.
1650+
// Trying to add projections will only result in an ill-formed place.
1651+
return None;
16471652
} else if let Value::Projection(pointer, proj) = *self.get(index)
16481653
&& (allow_complex_projection || proj.is_stable_offset())
16491654
&& let Some(proj) = self.try_as_place_elem(self.ty(index), proj, loc)

library/core/src/iter/traits/accum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ macro_rules! float_sum_product {
203203

204204
integer_sum_product! { i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize }
205205
saturating_integer_sum_product! { u8 u16 u32 u64 u128 usize }
206-
float_sum_product! { f32 f64 }
206+
float_sum_product! { f16 f32 f64 f128 }
207207

208208
#[stable(feature = "iter_arith_traits_result", since = "1.16.0")]
209209
impl<T, U, E> Sum<Result<U, E>> for Result<T, E>

library/std/src/path.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3037,6 +3037,14 @@ impl Path {
30373037
///
30383038
/// This is an alias to [`fs::canonicalize`].
30393039
///
3040+
/// # Errors
3041+
///
3042+
/// This method will return an error in the following situations, but is not
3043+
/// limited to just these cases:
3044+
///
3045+
/// * `path` does not exist.
3046+
/// * A non-final component in path is not a directory.
3047+
///
30403048
/// # Examples
30413049
///
30423050
/// ```no_run
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//@ assembly-output: emit-asm
2+
//@ compile-flags: -Copt-level=3
3+
//@ only-arm
4+
//@ ignore-thumb
5+
#![no_std]
6+
#![crate_type = "lib"]
7+
#![feature(c_variadic)]
8+
9+
// Check that the assembly that rustc generates matches what clang emits.
10+
11+
#[unsafe(no_mangle)]
12+
unsafe extern "C" fn variadic(a: f64, mut args: ...) -> f64 {
13+
// CHECK-LABEL: variadic
14+
// CHECK: sub sp, sp, #12
15+
16+
// CHECK: vldr
17+
let b = args.arg::<f64>();
18+
// CHECK: vldr
19+
let c = args.arg::<f64>();
20+
21+
// CHECK: vadd.f64
22+
// CHECK: vadd.f64
23+
a + b + c
24+
25+
// CHECK: add sp, sp, #12
26+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ add-core-stubs
2+
//@ compile-flags: -Copt-level=3
3+
#![feature(c_variadic)]
4+
#![crate_type = "lib"]
5+
6+
// Check that `%args` explicitly has its lifetime start and end. Being explicit can improve
7+
// instruction and register selection, see e.g. https://github.com/rust-lang/rust/pull/144549
8+
9+
#[unsafe(no_mangle)]
10+
unsafe extern "C" fn variadic(a: f64, mut args: ...) -> f64 {
11+
// CHECK: call void @llvm.lifetime.start.p0(i64 {{[0-9]+}}, ptr nonnull %args)
12+
// CHECK: call void @llvm.va_start.p0(ptr nonnull %args)
13+
14+
let b = args.arg::<f64>();
15+
let c = args.arg::<f64>();
16+
17+
a + b + c
18+
19+
// CHECK: call void @llvm.va_end.p0(ptr nonnull %args)
20+
// CHECK: call void @llvm.lifetime.end.p0(i64 {{[0-9]+}}, ptr nonnull %args)
21+
}

0 commit comments

Comments
 (0)