Skip to content

Commit 8269be1

Browse files
committed
Auto merge of rust-lang#129398 - matthiaskrgr:rollup-50l01ry, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#128432 (WASI: forbid `unsafe_op_in_unsafe_fn` for `std::{os, sys}`) - rust-lang#129373 (Add missing module flags for CFI and KCFI sanitizers) - rust-lang#129374 (Use `assert_unsafe_precondition!` in `AsciiChar::digit_unchecked`) - rust-lang#129376 (Change `assert_unsafe_precondition` docs to refer to `check_language_ub`) - rust-lang#129382 (Add `const_cell_into_inner` to `OnceCell`) - rust-lang#129387 (Advise against removing the remaining Python scripts from `tests/run-make`) - rust-lang#129388 (Do not rely on names to find lifetimes.) - rust-lang#129395 (Pretty-print own args of existential projections (dyn-Trait w/ GAT constraints)) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 739b1fd + 9d39b59 commit 8269be1

File tree

40 files changed

+204
-85
lines changed

40 files changed

+204
-85
lines changed

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustc_data_structures::base_n::{ToBaseN, ALPHANUMERIC_ONLY};
1111
use rustc_data_structures::fx::FxHashMap;
1212
use rustc_data_structures::small_c_str::SmallCStr;
1313
use rustc_hir::def_id::DefId;
14+
use rustc_middle::middle::codegen_fn_attrs::PatchableFunctionEntry;
1415
use rustc_middle::mir::mono::CodegenUnit;
1516
use rustc_middle::ty::layout::{
1617
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, LayoutError, LayoutOfHelpers,
@@ -226,6 +227,20 @@ pub unsafe fn create_module<'ll>(
226227
}
227228
}
228229

230+
// If we're normalizing integers with CFI, ensure LLVM generated functions do the same.
231+
// See https://github.com/llvm/llvm-project/pull/104826
232+
if sess.is_sanitizer_cfi_normalize_integers_enabled() {
233+
let cfi_normalize_integers = c"cfi-normalize-integers".as_ptr().cast();
234+
unsafe {
235+
llvm::LLVMRustAddModuleFlagU32(
236+
llmod,
237+
llvm::LLVMModFlagBehavior::Override,
238+
cfi_normalize_integers,
239+
1,
240+
);
241+
}
242+
}
243+
229244
// Enable LTO unit splitting if specified or if CFI is enabled. (See https://reviews.llvm.org/D53891.)
230245
if sess.is_split_lto_unit_enabled() || sess.is_sanitizer_cfi_enabled() {
231246
let enable_split_lto_unit = c"EnableSplitLTOUnit".as_ptr();
@@ -245,6 +260,22 @@ pub unsafe fn create_module<'ll>(
245260
unsafe {
246261
llvm::LLVMRustAddModuleFlagU32(llmod, llvm::LLVMModFlagBehavior::Override, kcfi, 1);
247262
}
263+
264+
// Add "kcfi-offset" module flag with -Z patchable-function-entry (See
265+
// https://reviews.llvm.org/D141172).
266+
let pfe =
267+
PatchableFunctionEntry::from_config(sess.opts.unstable_opts.patchable_function_entry);
268+
if pfe.prefix() > 0 {
269+
let kcfi_offset = c"kcfi-offset".as_ptr().cast();
270+
unsafe {
271+
llvm::LLVMRustAddModuleFlagU32(
272+
llmod,
273+
llvm::LLVMModFlagBehavior::Override,
274+
kcfi_offset,
275+
pfe.prefix().into(),
276+
);
277+
}
278+
}
248279
}
249280

250281
// Control Flow Guard is currently only supported by the MSVC linker on Windows.

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3119,7 +3119,10 @@ define_print! {
31193119

31203120
ty::ExistentialProjection<'tcx> {
31213121
let name = cx.tcx().associated_item(self.def_id).name;
3122-
p!(write("{} = ", name), print(self.term))
3122+
// The args don't contain the self ty (as it has been erased) but the corresp.
3123+
// generics do as the trait always has a self ty param. We need to offset.
3124+
let args = &self.args[cx.tcx().generics_of(self.def_id).parent_count - 1..];
3125+
p!(path_generic_args(|cx| write!(cx, "{name}"), args), " = ", print(self.term))
31233126
}
31243127

31253128
ty::ProjectionPredicate<'tcx> {

compiler/rustc_trait_selection/src/error_reporting/infer/region.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,16 +1099,8 @@ fn msg_span_from_named_region<'tcx>(
10991099
) -> (String, Option<Span>) {
11001100
match *region {
11011101
ty::ReEarlyParam(br) => {
1102-
let scope = tcx
1103-
.parent(tcx.generics_of(generic_param_scope).region_param(br, tcx).def_id)
1104-
.expect_local();
1105-
let span = if let Some(param) =
1106-
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name))
1107-
{
1108-
param.span
1109-
} else {
1110-
tcx.def_span(scope)
1111-
};
1102+
let param_def_id = tcx.generics_of(generic_param_scope).region_param(br, tcx).def_id;
1103+
let span = tcx.def_span(param_def_id);
11121104
let text = if br.has_name() {
11131105
format!("the lifetime `{}` as defined here", br.name)
11141106
} else {
@@ -1124,16 +1116,8 @@ fn msg_span_from_named_region<'tcx>(
11241116
("the anonymous lifetime defined here".to_string(), Some(ty.span))
11251117
} else {
11261118
match fr.bound_region {
1127-
ty::BoundRegionKind::BrNamed(_, name) => {
1128-
let span = if let Some(param) = tcx
1129-
.hir()
1130-
.get_generics(generic_param_scope)
1131-
.and_then(|generics| generics.get_named(name))
1132-
{
1133-
param.span
1134-
} else {
1135-
tcx.def_span(generic_param_scope)
1136-
};
1119+
ty::BoundRegionKind::BrNamed(param_def_id, name) => {
1120+
let span = tcx.def_span(param_def_id);
11371121
let text = if name == kw::UnderscoreLifetime {
11381122
"the anonymous lifetime as defined here".to_string()
11391123
} else {

library/core/src/ascii/ascii_char.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
//! suggestions from rustc if you get anything slightly wrong in here, and overall
44
//! helps with clarity as we're also referring to `char` intentionally in here.
55
6-
use crate::fmt;
76
use crate::mem::transmute;
7+
use crate::{assert_unsafe_precondition, fmt};
88

99
/// One of the 128 Unicode characters from U+0000 through U+007F,
1010
/// often known as the [ASCII] subset.
@@ -497,14 +497,18 @@ impl AsciiChar {
497497
/// Notably, it should not be expected to return hex digits, or any other
498498
/// reasonable extension of the decimal digits.
499499
///
500-
/// (This lose safety condition is intended to simplify soundness proofs
500+
/// (This loose safety condition is intended to simplify soundness proofs
501501
/// when writing code using this method, since the implementation doesn't
502502
/// need something really specific, not to make those other arguments do
503503
/// something useful. It might be tightened before stabilization.)
504504
#[unstable(feature = "ascii_char", issue = "110998")]
505505
#[inline]
506506
pub const unsafe fn digit_unchecked(d: u8) -> Self {
507-
debug_assert!(d < 10);
507+
assert_unsafe_precondition!(
508+
check_language_ub,
509+
"`AsciiChar::digit_unchecked` input cannot exceed 9.",
510+
(d: u8 = d) => d < 10
511+
);
508512

509513
// SAFETY: `'0'` through `'9'` are U+00030 through U+0039,
510514
// so because `d` must be 64 or less the addition can return at most

library/core/src/cell/once.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ impl<T> OnceCell<T> {
309309
/// ```
310310
#[inline]
311311
#[stable(feature = "once_cell", since = "1.70.0")]
312-
pub fn into_inner(self) -> Option<T> {
312+
#[rustc_const_unstable(feature = "const_cell_into_inner", issue = "78729")]
313+
pub const fn into_inner(self) -> Option<T> {
313314
// Because `into_inner` takes `self` by value, the compiler statically verifies
314315
// that it is not currently borrowed. So it is safe to move out `Option<T>`.
315316
self.inner.into_inner()

library/core/src/ub_checks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::intrinsics::{self, const_eval_select};
1010
/// macro for language UB are always ignored.
1111
///
1212
/// This macro should be called as
13-
/// `assert_unsafe_precondition!(check_{library,lang}_ub, "message", (ident: type = expr, ident: type = expr) => check_expr)`
13+
/// `assert_unsafe_precondition!(check_{library,language}_ub, "message", (ident: type = expr, ident: type = expr) => check_expr)`
1414
/// where each `expr` will be evaluated and passed in as function argument `ident: type`. Then all
1515
/// those arguments are passed to a function with the body `check_expr`.
1616
/// Pick `check_language_ub` when this is guarding a violation of language UB, i.e., immediate UB

library/std/src/os/wasi/fs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//!
33
//! [`std::fs`]: crate::fs
44
5-
#![deny(unsafe_op_in_unsafe_fn)]
65
#![unstable(feature = "wasi_ext", issue = "71213")]
76

87
// Used for `File::read` on intra-doc links

library/std/src/os/wasi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
3131
#![cfg_attr(not(target_env = "p2"), stable(feature = "rust1", since = "1.0.0"))]
3232
#![cfg_attr(target_env = "p2", unstable(feature = "wasip2", issue = "none"))]
33-
#![deny(unsafe_op_in_unsafe_fn)]
33+
#![forbid(unsafe_op_in_unsafe_fn)]
3434
#![doc(cfg(target_os = "wasi"))]
3535

3636
pub mod ffi;

library/std/src/os/wasip2/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
//!
33
//! This module is currently empty, but will be filled over time as wasi-libc support for WASI Preview 2 is stabilized.
44
5+
#![forbid(unsafe_op_in_unsafe_fn)]
56
#![stable(feature = "raw_ext", since = "1.1.0")]

library/std/src/sys/pal/wasi/args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![deny(unsafe_op_in_unsafe_fn)]
1+
#![forbid(unsafe_op_in_unsafe_fn)]
22

33
use crate::ffi::{CStr, OsStr, OsString};
44
use crate::os::wasi::ffi::OsStrExt;

0 commit comments

Comments
 (0)