Skip to content

Commit 58f38eb

Browse files
author
The Miri Cronjob Bot
committed
Merge ref '873d4682c7d2' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: 873d468 Filtered ref: rust-lang/miri@57f1e8b Upstream diff: 5a07626...873d468 This merge was created using https://github.com/rust-lang/josh-sync.
2 parents 20c31e0 + b235cc2 commit 58f38eb

104 files changed

Lines changed: 1569 additions & 856 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

RELEASES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ Stabilized APIs
6262
- [`<uN>::unchecked_shl`](https://doc.rust-lang.org/stable/std/primitive.usize.html#method.unchecked_shl)
6363
- [`<uN>::unchecked_shr`](https://doc.rust-lang.org/stable/std/primitive.usize.html#method.unchecked_shr)
6464
- [`<[T]>::as_array`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.as_array)
65-
- [`<[T]>::as_array_mut`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.as_mut_array)
65+
- [`<[T]>::as_mut_array`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.as_mut_array)
6666
- [`<*const [T]>::as_array`](https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.as_array)
67-
- [`<*mut [T]>::as_array_mut`](https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.as_mut_array)
67+
- [`<*mut [T]>::as_mut_array`](https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.as_mut_array)
6868
- [`VecDeque::pop_front_if`](https://doc.rust-lang.org/stable/std/collections/struct.VecDeque.html#method.pop_front_if)
6969
- [`VecDeque::pop_back_if`](https://doc.rust-lang.org/stable/std/collections/struct.VecDeque.html#method.pop_back_if)
7070
- [`Duration::from_nanos_u128`](https://doc.rust-lang.org/stable/std/time/struct.Duration.html#method.from_nanos_u128)

compiler/rustc_abi/src/canon_abi.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub enum CanonAbi {
2727
C,
2828
Rust,
2929
RustCold,
30+
RustPreserveNone,
3031

3132
/// An ABI that rustc does not know how to call or define.
3233
Custom,
@@ -54,7 +55,7 @@ pub enum CanonAbi {
5455
impl CanonAbi {
5556
pub fn is_rustic_abi(self) -> bool {
5657
match self {
57-
CanonAbi::Rust | CanonAbi::RustCold => true,
58+
CanonAbi::Rust | CanonAbi::RustCold | CanonAbi::RustPreserveNone => true,
5859
CanonAbi::C
5960
| CanonAbi::Custom
6061
| CanonAbi::Arm(_)
@@ -74,6 +75,7 @@ impl fmt::Display for CanonAbi {
7475
CanonAbi::C => ExternAbi::C { unwind: false },
7576
CanonAbi::Rust => ExternAbi::Rust,
7677
CanonAbi::RustCold => ExternAbi::RustCold,
78+
CanonAbi::RustPreserveNone => ExternAbi::RustPreserveNone,
7779
CanonAbi::Custom => ExternAbi::Custom,
7880
CanonAbi::Arm(arm_call) => match arm_call {
7981
ArmCall::Aapcs => ExternAbi::Aapcs { unwind: false },

compiler/rustc_abi/src/extern_abi.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ pub enum ExternAbi {
4242
/// in a platform-agnostic way.
4343
RustInvalid,
4444

45+
/// Preserves no registers.
46+
///
47+
/// Note, that this ABI is not stable in the registers it uses, is intended as an optimization
48+
/// and may fall-back to a more conservative calling convention if the backend does not support
49+
/// forcing callers to save all registers.
50+
RustPreserveNone,
51+
4552
/// Unstable impl detail that directly uses Rust types to describe the ABI to LLVM.
4653
/// Even normally-compatible Rust types can become ABI-incompatible with this ABI!
4754
Unadjusted,
@@ -163,6 +170,7 @@ abi_impls! {
163170
RustCall =><= "rust-call",
164171
RustCold =><= "rust-cold",
165172
RustInvalid =><= "rust-invalid",
173+
RustPreserveNone =><= "rust-preserve-none",
166174
Stdcall { unwind: false } =><= "stdcall",
167175
Stdcall { unwind: true } =><= "stdcall-unwind",
168176
System { unwind: false } =><= "system",
@@ -243,7 +251,7 @@ impl ExternAbi {
243251
/// - are subject to change between compiler versions
244252
pub fn is_rustic_abi(self) -> bool {
245253
use ExternAbi::*;
246-
matches!(self, Rust | RustCall | RustCold)
254+
matches!(self, Rust | RustCall | RustCold | RustPreserveNone)
247255
}
248256

249257
/// Returns whether the ABI supports C variadics. This only controls whether we allow *imports*
@@ -315,7 +323,8 @@ impl ExternAbi {
315323
| Self::Thiscall { .. }
316324
| Self::Vectorcall { .. }
317325
| Self::SysV64 { .. }
318-
| Self::Win64 { .. } => true,
326+
| Self::Win64 { .. }
327+
| Self::RustPreserveNone => true,
319328
}
320329
}
321330
}

compiler/rustc_ast_lowering/src/stability.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ pub fn extern_abi_stability(abi: ExternAbi) -> Result<(), UnstableAbi> {
9595
ExternAbi::RustCold => {
9696
Err(UnstableAbi { abi, feature: sym::rust_cold_cc, explain: GateReason::Experimental })
9797
}
98+
ExternAbi::RustPreserveNone => Err(UnstableAbi {
99+
abi,
100+
feature: sym::rust_preserve_none_cc,
101+
explain: GateReason::Experimental,
102+
}),
98103
ExternAbi::RustInvalid => {
99104
Err(UnstableAbi { abi, feature: sym::rustc_attrs, explain: GateReason::ImplDetail })
100105
}

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ impl<'a> AstValidator<'a> {
400400
CanonAbi::C
401401
| CanonAbi::Rust
402402
| CanonAbi::RustCold
403+
| CanonAbi::RustPreserveNone
403404
| CanonAbi::Arm(_)
404405
| CanonAbi::X86(_) => { /* nothing to check */ }
405406

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ pub(crate) fn conv_to_call_conv(
5656
CanonAbi::Rust | CanonAbi::C => default_call_conv,
5757
CanonAbi::RustCold => CallConv::Cold,
5858

59+
// Cranelift doesn't currently have anything for this.
60+
CanonAbi::RustPreserveNone => default_call_conv,
61+
5962
// Functions with this calling convention can only be called from assembly, but it is
6063
// possible to declare an `extern "custom"` block, so the backend still needs a calling
6164
// convention for declaring foreign functions.

compiler/rustc_codegen_gcc/src/abi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
243243
pub fn conv_to_fn_attribute<'gcc>(conv: CanonAbi, arch: &Arch) -> Option<FnAttribute<'gcc>> {
244244
let attribute = match conv {
245245
CanonAbi::C | CanonAbi::Rust => return None,
246+
// gcc/gccjit does not have anything for this.
247+
CanonAbi::RustPreserveNone => return None,
246248
CanonAbi::RustCold => FnAttribute::Cold,
247249
// Functions with this calling convention can only be called from assembly, but it is
248250
// possible to declare an `extern "custom"` block, so the backend still needs a calling

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,10 @@ pub(crate) fn to_llvm_calling_convention(sess: &Session, abi: CanonAbi) -> llvm:
694694
match abi {
695695
CanonAbi::C | CanonAbi::Rust => llvm::CCallConv,
696696
CanonAbi::RustCold => llvm::PreserveMost,
697+
CanonAbi::RustPreserveNone => match &sess.target.arch {
698+
Arch::X86_64 | Arch::AArch64 => llvm::PreserveNone,
699+
_ => llvm::CCallConv,
700+
},
697701
// Functions with this calling convention can only be called from assembly, but it is
698702
// possible to declare an `extern "custom"` block, so the backend still needs a calling
699703
// convention for declaring foreign functions.

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ fn create_alloc_family_attr(llcx: &llvm::Context) -> &llvm::Attribute {
370370
llvm::CreateAttrStringValue(llcx, "alloc-family", "__rust_alloc")
371371
}
372372

373-
/// Helper for `FnAbi::apply_attrs_llfn`:
373+
/// Helper for `FnAbiLlvmExt::apply_attrs_llfn`:
374374
/// Composite function which sets LLVM attributes for function depending on its AST (`#[attribute]`)
375375
/// attributes.
376376
pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
@@ -516,7 +516,16 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
516516
to_add.push(llvm::CreateAllocKindAttr(cx.llcx, AllocKindFlags::Free));
517517
// applies to argument place instead of function place
518518
let allocated_pointer = AttributeKind::AllocatedPointer.create_attr(cx.llcx);
519-
attributes::apply_to_llfn(llfn, AttributePlace::Argument(0), &[allocated_pointer]);
519+
let attrs: &[_] = if llvm_util::get_version() >= (21, 0, 0) {
520+
// "Does not capture provenance" means "if the function call stashes the pointer somewhere,
521+
// accessing that pointer after the function returns is UB". That is definitely the case here since
522+
// freeing will destroy the provenance.
523+
let captures_addr = AttributeKind::CapturesAddress.create_attr(cx.llcx);
524+
&[allocated_pointer, captures_addr]
525+
} else {
526+
&[allocated_pointer]
527+
};
528+
attributes::apply_to_llfn(llfn, AttributePlace::Argument(0), attrs);
520529
}
521530
if let Some(align) = codegen_fn_attrs.alignment {
522531
llvm::set_alignment(llfn, align);

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ pub(crate) enum CallConv {
167167
PreserveMost = 14,
168168
PreserveAll = 15,
169169
Tail = 18,
170+
PreserveNone = 21,
170171
X86StdcallCallConv = 64,
171172
X86FastcallCallConv = 65,
172173
ArmAapcsCallConv = 67,

0 commit comments

Comments
 (0)