Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_passes/src/eii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ pub(crate) fn check_externally_implementable_items<'tcx>(tcx: TyCtxt<'tcx>, ():
}

if default_impls.len() > 1 {
panic!("multiple not supported right now");
let decl_span = tcx.def_ident_span(decl_did).unwrap();
tcx.dcx().span_delayed_bug(decl_span, "multiple not supported right now");
}

let (local_impl, is_default) =
Expand Down
24 changes: 24 additions & 0 deletions library/core/src/bstr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,30 @@ impl ByteStr {
ByteStr::from_bytes(bytes.as_ref())
}

/// Returns the same string as `&ByteStr`.
///
/// This method is redundant when used directly on `&ByteStr`, but
/// it helps dereferencing other "container" types,
/// for example `Box<ByteStr>` or `Arc<ByteStr>`.
#[inline]
// #[unstable(feature = "str_as_str", issue = "130366")]
#[unstable(feature = "bstr", issue = "134915")]
pub const fn as_byte_str(&self) -> &ByteStr {
self
}

/// Returns the same string as `&mut ByteStr`.
///
/// This method is redundant when used directly on `&mut ByteStr`, but
/// it helps dereferencing other "container" types,
/// for example `Box<ByteStr>` or `MutexGuard<ByteStr>`.
#[inline]
// #[unstable(feature = "str_as_str", issue = "130366")]
#[unstable(feature = "bstr", issue = "134915")]
pub const fn as_mut_byte_str(&mut self) -> &mut ByteStr {
self
}

#[doc(hidden)]
#[unstable(feature = "bstr_internals", issue = "none")]
#[inline]
Expand Down
11 changes: 11 additions & 0 deletions library/core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,17 @@ impl CStr {
pub fn display(&self) -> impl fmt::Display {
crate::bstr::ByteStr::from_bytes(self.to_bytes())
}

/// Returns the same string as a string slice `&CStr`.
///
/// This method is redundant when used directly on `&CStr`, but
/// it helps dereferencing other string-like types to string slices,
/// for example references to `Box<CStr>` or `Arc<CStr>`.
#[inline]
#[unstable(feature = "str_as_str", issue = "130366")]
pub const fn as_c_str(&self) -> &CStr {
self
}
}

#[stable(feature = "c_string_eq_c_str", since = "1.90.0")]
Expand Down
22 changes: 22 additions & 0 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4908,6 +4908,28 @@ impl<T> [T] {

if start <= self.len() && end <= self.len() { Some(start..end) } else { None }
}

/// Returns the same slice `&[T]`.
///
/// This method is redundant when used directly on `&[T]`, but
/// it helps dereferencing other "container" types to slices,
/// for example `Box<[T]>` or `Arc<[T]>`.
#[inline]
#[unstable(feature = "str_as_str", issue = "130366")]
pub const fn as_slice(&self) -> &[T] {
self
}

/// Returns the same slice `&mut [T]`.
///
/// This method is redundant when used directly on `&mut [T]`, but
/// it helps dereferencing other "container" types to slices,
/// for example `Box<[T]>` or `MutexGuard<[T]>`.
#[inline]
#[unstable(feature = "str_as_str", issue = "130366")]
pub const fn as_mut_slice(&mut self) -> &mut [T] {
self
}
}

impl<T> [MaybeUninit<T>] {
Expand Down
11 changes: 11 additions & 0 deletions library/std/src/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,17 @@ impl OsStr {
pub fn display(&self) -> Display<'_> {
Display { os_str: self }
}

/// Returns the same string as a string slice `&OsStr`.
///
/// This method is redundant when used directly on `&OsStr`, but
/// it helps dereferencing other string-like types to string slices,
/// for example references to `Box<OsStr>` or `Arc<OsStr>`.
#[inline]
#[unstable(feature = "str_as_str", issue = "130366")]
pub const fn as_os_str(&self) -> &OsStr {
self
}
}

#[stable(feature = "box_from_os_str", since = "1.17.0")]
Expand Down
11 changes: 11 additions & 0 deletions library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3206,6 +3206,17 @@ impl Path {
Display { inner: self.inner.display() }
}

/// Returns the same path as `&Path`.
///
/// This method is redundant when used directly on `&Path`, but
/// it helps dereferencing other `PathBuf`-like types to `Path`s,
/// for example references to `Box<Path>` or `Arc<Path>`.
#[inline]
#[unstable(feature = "str_as_str", issue = "130366")]
pub const fn as_path(&self) -> &Path {
self
}

/// Queries the file system to get information about a file, directory, etc.
///
/// This function will traverse symbolic links to query information about the
Expand Down
4 changes: 4 additions & 0 deletions library/std_detect/src/detect/os/darwin/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ pub(crate) fn detect_features() -> cache::Initializer {
let sme = _sysctlbyname(c"hw.optional.arm.FEAT_SME");
let sme2 = _sysctlbyname(c"hw.optional.arm.FEAT_SME2");
let sme2p1 = _sysctlbyname(c"hw.optional.arm.FEAT_SME2p1");
let sme_b16b16 = _sysctlbyname(c"hw.optional.arm.FEAT_SME_B16B16");
let sme_f16f16 = _sysctlbyname(c"hw.optional.arm.FEAT_SME_F16F16");
let sme_f64f64 = _sysctlbyname(c"hw.optional.arm.FEAT_SME_F64F64");
let sme_i16i64 = _sysctlbyname(c"hw.optional.arm.FEAT_SME_I16I64");
let ssbs = _sysctlbyname(c"hw.optional.arm.FEAT_SSBS");
Expand Down Expand Up @@ -153,6 +155,8 @@ pub(crate) fn detect_features() -> cache::Initializer {
enable_feature(Feature::sme, sme);
enable_feature(Feature::sme2, sme2);
enable_feature(Feature::sme2p1, sme2p1);
enable_feature(Feature::sme_b16b16, sme_b16b16);
enable_feature(Feature::sme_f16f16, sme_f16f16);
enable_feature(Feature::sme_f64f64, sme_f64f64);
enable_feature(Feature::sme_i16i64, sme_i16i64);
enable_feature(Feature::ssbs, ssbs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//@ [strong] compile-flags: -Z stack-protector=strong
//@ [basic] compile-flags: -Z stack-protector=basic
//@ [none] compile-flags: -Z stack-protector=none
//@ compile-flags: -C opt-level=2 -Z merge-functions=disabled
//@ compile-flags: -C opt-level=2 -Z merge-functions=disabled -Cpanic=abort -Cdebuginfo=1

#![crate_type = "lib"]
#![allow(internal_features)]
Expand Down Expand Up @@ -39,6 +39,8 @@ pub fn array_char(f: fn(*const char)) {
// basic: __security_check_cookie
// none-NOT: __security_check_cookie
// missing-NOT: __security_check_cookie

// CHECK-DAG: .cv_fpo_endproc
}

// CHECK-LABEL: array_u8_1
Expand All @@ -55,6 +57,8 @@ pub fn array_u8_1(f: fn(*const u8)) {
// basic-NOT: __security_check_cookie
// none-NOT: __security_check_cookie
// missing-NOT: __security_check_cookie

// CHECK-DAG: .cv_fpo_endproc
}

// CHECK-LABEL: array_u8_small:
Expand All @@ -72,6 +76,8 @@ pub fn array_u8_small(f: fn(*const u8)) {
// basic-NOT: __security_check_cookie
// none-NOT: __security_check_cookie
// missing-NOT: __security_check_cookie

// CHECK-DAG: .cv_fpo_endproc
}

// CHECK-LABEL: array_u8_large:
Expand All @@ -88,6 +94,8 @@ pub fn array_u8_large(f: fn(*const u8)) {
// basic: __security_check_cookie
// none-NOT: __security_check_cookie
// missing-NOT: __security_check_cookie

// CHECK-DAG: .cv_fpo_endproc
}

#[derive(Copy, Clone)]
Expand All @@ -107,6 +115,8 @@ pub fn array_bytesizednewtype_9(f: fn(*const ByteSizedNewtype)) {
// basic: __security_check_cookie
// none-NOT: __security_check_cookie
// missing-NOT: __security_check_cookie

// CHECK-DAG: .cv_fpo_endproc
}

// CHECK-LABEL: local_var_addr_used_indirectly
Expand Down Expand Up @@ -134,6 +144,8 @@ pub fn local_var_addr_used_indirectly(f: fn(bool)) {
// basic-NOT: __security_check_cookie
// none-NOT: __security_check_cookie
// missing-NOT: __security_check_cookie

// CHECK-DAG: .cv_fpo_endproc
}

// CHECK-LABEL: local_string_addr_taken
Expand All @@ -143,28 +155,15 @@ pub fn local_string_addr_taken(f: fn(&String)) {
f(&x);

// Taking the address of the local variable `x` leads to stack smash
// protection with the `strong` heuristic, but not with the `basic`
// heuristic. It does not matter that the reference is not mut.
//
// An interesting note is that a similar function in C++ *would* be
// protected by the `basic` heuristic, because `std::string` has a char
// array internally as a small object optimization:
// ```
// cat <<EOF | clang++ -O2 -fstack-protector -S -x c++ - -o - | grep stack_chk
// #include <string>
// void f(void (*g)(const std::string&)) {
// std::string x;
// g(x);
// }
// EOF
// ```
//
// protection. It does not matter that the reference is not mut.

// all: __security_check_cookie
// strong-NOT: __security_check_cookie
// basic-NOT: __security_check_cookie
// strong: __security_check_cookie
// basic: __security_check_cookie
// none-NOT: __security_check_cookie
// missing-NOT: __security_check_cookie

// CHECK-DAG: .cv_fpo_endproc
}

pub trait SelfByRef {
Expand Down Expand Up @@ -194,6 +193,8 @@ pub fn local_var_addr_taken_used_locally_only(factory: fn() -> i32, sink: fn(i32
// basic-NOT: __security_check_cookie
// none-NOT: __security_check_cookie
// missing-NOT: __security_check_cookie

// CHECK-DAG: .cv_fpo_endproc
}

pub struct Gigastruct {
Expand Down Expand Up @@ -231,6 +232,8 @@ pub fn local_large_var_moved(f: fn(Gigastruct)) {
// basic: __security_check_cookie
// none-NOT: __security_check_cookie
// missing-NOT: __security_check_cookie

// CHECK-DAG: .cv_fpo_endproc
}

// CHECK-LABEL: local_large_var_cloned
Expand Down Expand Up @@ -260,6 +263,8 @@ pub fn local_large_var_cloned(f: fn(Gigastruct)) {
// basic: __security_check_cookie
// none-NOT: __security_check_cookie
// missing-NOT: __security_check_cookie

// CHECK-DAG: .cv_fpo_endproc
}

extern "C" {
Expand Down Expand Up @@ -300,6 +305,8 @@ pub fn alloca_small_compile_time_constant_arg(f: fn(*mut ())) {
// basic-NOT: __security_check_cookie
// none-NOT: __security_check_cookie
// missing-NOT: __security_check_cookie

// CHECK-DAG: .cv_fpo_endproc
}

// CHECK-LABEL: alloca_large_compile_time_constant_arg
Expand All @@ -312,6 +319,8 @@ pub fn alloca_large_compile_time_constant_arg(f: fn(*mut ())) {
// basic-NOT: __security_check_cookie
// none-NOT: __security_check_cookie
// missing-NOT: __security_check_cookie

// CHECK-DAG: .cv_fpo_endproc
}

// CHECK-LABEL: alloca_dynamic_arg
Expand All @@ -324,14 +333,14 @@ pub fn alloca_dynamic_arg(f: fn(*mut ()), n: usize) {
// basic-NOT: __security_check_cookie
// none-NOT: __security_check_cookie
// missing-NOT: __security_check_cookie

// CHECK-DAG: .cv_fpo_endproc
}

// The question then is: in what ways can Rust code generate array-`alloca`
// LLVM instructions? This appears to only be generated by
// rustc_codegen_ssa::traits::Builder::array_alloca() through
// rustc_codegen_ssa::mir::operand::OperandValue::store_unsized(). FWICT
// this is support for the "unsized locals" unstable feature:
// https://doc.rust-lang.org/unstable-book/language-features/unsized-locals.html.
// rustc_codegen_ssa::mir::operand::OperandValue::store_unsized().

// CHECK-LABEL: unsized_fn_param
#[no_mangle]
Expand All @@ -346,14 +355,11 @@ pub fn unsized_fn_param(s: [u8], l: bool, f: fn([u8])) {
// alloca, and is therefore not protected by the `strong` or `basic`
// heuristics.

// We should have a __security_check_cookie call in `all` and `strong` modes but
// LLVM does not support generating stack protectors in functions with funclet
// based EH personalities.
// https://github.com/llvm/llvm-project/blob/37fd3c96b917096d8a550038f6e61cdf0fc4174f/llvm/lib/CodeGen/StackProtector.cpp#L103C1-L109C4
// all-NOT: __security_check_cookie
// strong-NOT: __security_check_cookie

// basic-NOT: __security_check_cookie
// none-NOT: __security_check_cookie
// missing-NOT: __security_check_cookie

// CHECK-DAG: .cv_fpo_endproc
}
Loading
Loading