Skip to content

Commit 147345d

Browse files
committed
Auto merge of rust-lang#131922 - matthiaskrgr:rollup-hhl3wvk, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - rust-lang#127462 (std: uefi: Add basic Env variables) - rust-lang#131537 (Fix range misleading field access) - rust-lang#131838 (bootstrap: allow setting `--jobs` in config.toml) - rust-lang#131871 (x86-32 float return for 'Rust' ABI: treat all float types consistently) - rust-lang#131876 (compiler: Use LLVM's Comdat support) - rust-lang#131890 (Update `use` keyword docs to describe precise capturing) - rust-lang#131899 (Mark unexpected variant res suggestion as having placeholders) - rust-lang#131908 (rustdoc: Switch from FxHash to sha256 for static file hashing.) - rust-lang#131916 (small interpreter error cleanup) - rust-lang#131919 (zero-sized accesses are fine on null pointers) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b27f33a + db94dd5 commit 147345d

File tree

43 files changed

+445
-223
lines changed

Some content is hidden

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

43 files changed

+445
-223
lines changed

Diff for: Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4584,6 +4584,7 @@ dependencies = [
45844584
"rustdoc-json-types",
45854585
"serde",
45864586
"serde_json",
4587+
"sha2",
45874588
"smallvec",
45884589
"tempfile",
45894590
"threadpool",

Diff for: compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
132132
.collect::<Vec<_>>();
133133
let initializer = cx.const_array(cx.type_ptr(), &name_globals);
134134

135-
let array = llvm::add_global(cx.llmod, cx.val_ty(initializer), "__llvm_coverage_names");
135+
let array = llvm::add_global(cx.llmod, cx.val_ty(initializer), c"__llvm_coverage_names");
136136
llvm::set_global_constant(array, true);
137137
llvm::set_linkage(array, llvm::Linkage::InternalLinkage);
138138
llvm::set_initializer(array, initializer);

Diff for: compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::cell::RefCell;
2+
use std::ffi::CString;
23

34
use libc::c_uint;
45
use rustc_codegen_ssa::traits::{
@@ -12,6 +13,7 @@ use rustc_middle::mir::coverage::CoverageKind;
1213
use rustc_middle::ty::Instance;
1314
use rustc_middle::ty::layout::HasTyCtxt;
1415
use rustc_target::abi::{Align, Size};
16+
use rustc_target::spec::HasTargetSpec;
1517
use tracing::{debug, instrument};
1618

1719
use crate::builder::Builder;
@@ -284,10 +286,10 @@ pub(crate) fn save_cov_data_to_mod<'ll, 'tcx>(
284286
cx: &CodegenCx<'ll, 'tcx>,
285287
cov_data_val: &'ll llvm::Value,
286288
) {
287-
let covmap_var_name = llvm::build_string(|s| unsafe {
289+
let covmap_var_name = CString::new(llvm::build_byte_buffer(|s| unsafe {
288290
llvm::LLVMRustCoverageWriteMappingVarNameToString(s);
289-
})
290-
.expect("Rust Coverage Mapping var name failed UTF-8 conversion");
291+
}))
292+
.unwrap();
291293
debug!("covmap var name: {:?}", covmap_var_name);
292294

293295
let covmap_section_name = llvm::build_string(|s| unsafe {
@@ -322,7 +324,8 @@ pub(crate) fn save_func_record_to_mod<'ll, 'tcx>(
322324
// of descriptions play distinct roles in LLVM IR; therefore, assign them different names (by
323325
// appending "u" to the end of the function record var name, to prevent `linkonce_odr` merging.
324326
let func_record_var_name =
325-
format!("__covrec_{:X}{}", func_name_hash, if is_used { "u" } else { "" });
327+
CString::new(format!("__covrec_{:X}{}", func_name_hash, if is_used { "u" } else { "" }))
328+
.unwrap();
326329
debug!("function record var name: {:?}", func_record_var_name);
327330
debug!("function record section name: {:?}", covfun_section_name);
328331

@@ -334,7 +337,9 @@ pub(crate) fn save_func_record_to_mod<'ll, 'tcx>(
334337
llvm::set_section(llglobal, covfun_section_name);
335338
// LLVM's coverage mapping format specifies 8-byte alignment for items in this section.
336339
llvm::set_alignment(llglobal, Align::EIGHT);
337-
llvm::set_comdat(cx.llmod, llglobal, &func_record_var_name);
340+
if cx.target_spec().supports_comdat() {
341+
llvm::set_comdat(cx.llmod, llglobal, &func_record_var_name);
342+
}
338343
cx.add_used_global(llglobal);
339344
}
340345

Diff for: compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ unsafe extern "C" {
646646
pub type Attribute;
647647
pub type Metadata;
648648
pub type BasicBlock;
649+
pub type Comdat;
649650
}
650651
#[repr(C)]
651652
pub struct Builder<'a>(InvariantOpaque<'a>);
@@ -1490,6 +1491,9 @@ unsafe extern "C" {
14901491
pub fn LLVMSetUnnamedAddress(Global: &Value, UnnamedAddr: UnnamedAddr);
14911492

14921493
pub fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&ConstantInt>;
1494+
1495+
pub fn LLVMGetOrInsertComdat(M: &Module, Name: *const c_char) -> &Comdat;
1496+
pub fn LLVMSetComdat(V: &Value, C: &Comdat);
14931497
}
14941498

14951499
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2320,7 +2324,6 @@ unsafe extern "C" {
23202324

23212325
pub fn LLVMRustPositionBuilderAtStart<'a>(B: &Builder<'a>, BB: &'a BasicBlock);
23222326

2323-
pub fn LLVMRustSetComdat<'a>(M: &'a Module, V: &'a Value, Name: *const c_char, NameLen: size_t);
23242327
pub fn LLVMRustSetModulePICLevel(M: &Module);
23252328
pub fn LLVMRustSetModulePIELevel(M: &Module);
23262329
pub fn LLVMRustSetModuleCodeModel(M: &Module, Model: CodeModel);

Diff for: compiler/rustc_codegen_llvm/src/llvm/mod.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ pub fn SetFunctionCallConv(fn_: &Value, cc: CallConv) {
178178
// function.
179179
// For more details on COMDAT sections see e.g., https://www.airs.com/blog/archives/52
180180
pub fn SetUniqueComdat(llmod: &Module, val: &Value) {
181-
unsafe {
182-
let name = get_value_name(val);
183-
LLVMRustSetComdat(llmod, val, name.as_ptr().cast(), name.len());
184-
}
181+
let name_buf = get_value_name(val).to_vec();
182+
let name =
183+
CString::from_vec_with_nul(name_buf).or_else(|buf| CString::new(buf.into_bytes())).unwrap();
184+
set_comdat(llmod, val, &name);
185185
}
186186

187187
pub fn SetUnnamedAddress(global: &Value, unnamed: UnnamedAddr) {
@@ -217,8 +217,7 @@ pub fn set_section(llglobal: &Value, section_name: &str) {
217217
}
218218
}
219219

220-
pub fn add_global<'a>(llmod: &'a Module, ty: &'a Type, name: &str) -> &'a Value {
221-
let name_cstr = CString::new(name).expect("unexpected CString error");
220+
pub fn add_global<'a>(llmod: &'a Module, ty: &'a Type, name_cstr: &CStr) -> &'a Value {
222221
unsafe { LLVMAddGlobal(llmod, ty, name_cstr.as_ptr()) }
223222
}
224223

@@ -252,9 +251,14 @@ pub fn set_alignment(llglobal: &Value, align: Align) {
252251
}
253252
}
254253

255-
pub fn set_comdat(llmod: &Module, llglobal: &Value, name: &str) {
254+
/// Get the `name`d comdat from `llmod` and assign it to `llglobal`.
255+
///
256+
/// Inserts the comdat into `llmod` if it does not exist.
257+
/// It is an error to call this if the target does not support comdat.
258+
pub fn set_comdat(llmod: &Module, llglobal: &Value, name: &CStr) {
256259
unsafe {
257-
LLVMRustSetComdat(llmod, llglobal, name.as_ptr().cast(), name.len());
260+
let comdat = LLVMGetOrInsertComdat(llmod, name.as_ptr());
261+
LLVMSetComdat(llglobal, comdat);
258262
}
259263
}
260264

Diff for: compiler/rustc_const_eval/src/const_eval/error.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use rustc_span::{Span, Symbol};
1111
use super::CompileTimeMachine;
1212
use crate::errors::{self, FrameNote, ReportErrorExt};
1313
use crate::interpret::{
14-
ErrorHandled, Frame, InterpError, InterpErrorInfo, MachineStopType, err_inval, err_machine_stop,
14+
ErrorHandled, Frame, InterpErrorInfo, InterpErrorKind, MachineStopType, err_inval,
15+
err_machine_stop,
1516
};
1617

1718
/// The CTFE machine has some custom error kinds.
@@ -57,7 +58,7 @@ impl MachineStopType for ConstEvalErrKind {
5758
}
5859
}
5960

60-
/// The errors become [`InterpError::MachineStop`] when being raised.
61+
/// The errors become [`InterpErrorKind::MachineStop`] when being raised.
6162
impl<'tcx> Into<InterpErrorInfo<'tcx>> for ConstEvalErrKind {
6263
fn into(self) -> InterpErrorInfo<'tcx> {
6364
err_machine_stop!(self).into()
@@ -124,7 +125,7 @@ pub fn get_span_and_frames<'tcx>(
124125
/// `get_span_and_frames`.
125126
pub(super) fn report<'tcx, C, F, E>(
126127
tcx: TyCtxt<'tcx>,
127-
error: InterpError<'tcx>,
128+
error: InterpErrorKind<'tcx>,
128129
span: Span,
129130
get_span_and_frames: C,
130131
mk: F,

Diff for: compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use tracing::{debug, instrument, trace};
1818
use super::{CanAccessMutGlobal, CompileTimeInterpCx, CompileTimeMachine};
1919
use crate::const_eval::CheckAlignment;
2020
use crate::interpret::{
21-
CtfeValidationMode, GlobalId, Immediate, InternKind, InternResult, InterpCx, InterpError,
21+
CtfeValidationMode, GlobalId, Immediate, InternKind, InternResult, InterpCx, InterpErrorKind,
2222
InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking, StackPopCleanup, create_static_alloc,
2323
eval_nullary_intrinsic, intern_const_alloc_recursive, interp_ok, throw_exhaust,
2424
};
@@ -463,7 +463,7 @@ fn report_validation_error<'tcx>(
463463
error: InterpErrorInfo<'tcx>,
464464
alloc_id: AllocId,
465465
) -> ErrorHandled {
466-
if !matches!(error.kind(), InterpError::UndefinedBehavior(_)) {
466+
if !matches!(error.kind(), InterpErrorKind::UndefinedBehavior(_)) {
467467
// Some other error happened during validation, e.g. an unsupported operation.
468468
return report_eval_error(ecx, cid, error);
469469
}

Diff for: compiler/rustc_const_eval/src/errors.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_errors::{
99
use rustc_hir::ConstContext;
1010
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
1111
use rustc_middle::mir::interpret::{
12-
CheckInAllocMsg, CtfeProvenance, ExpectedKind, InterpError, InvalidMetaKind,
12+
CheckInAllocMsg, CtfeProvenance, ExpectedKind, InterpErrorKind, InvalidMetaKind,
1313
InvalidProgramInfo, Misalignment, Pointer, PointerKind, ResourceExhaustionInfo,
1414
UndefinedBehaviorInfo, UnsupportedOpInfo, ValidationErrorInfo,
1515
};
@@ -835,23 +835,23 @@ impl ReportErrorExt for UnsupportedOpInfo {
835835
}
836836
}
837837

838-
impl<'tcx> ReportErrorExt for InterpError<'tcx> {
838+
impl<'tcx> ReportErrorExt for InterpErrorKind<'tcx> {
839839
fn diagnostic_message(&self) -> DiagMessage {
840840
match self {
841-
InterpError::UndefinedBehavior(ub) => ub.diagnostic_message(),
842-
InterpError::Unsupported(e) => e.diagnostic_message(),
843-
InterpError::InvalidProgram(e) => e.diagnostic_message(),
844-
InterpError::ResourceExhaustion(e) => e.diagnostic_message(),
845-
InterpError::MachineStop(e) => e.diagnostic_message(),
841+
InterpErrorKind::UndefinedBehavior(ub) => ub.diagnostic_message(),
842+
InterpErrorKind::Unsupported(e) => e.diagnostic_message(),
843+
InterpErrorKind::InvalidProgram(e) => e.diagnostic_message(),
844+
InterpErrorKind::ResourceExhaustion(e) => e.diagnostic_message(),
845+
InterpErrorKind::MachineStop(e) => e.diagnostic_message(),
846846
}
847847
}
848848
fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
849849
match self {
850-
InterpError::UndefinedBehavior(ub) => ub.add_args(diag),
851-
InterpError::Unsupported(e) => e.add_args(diag),
852-
InterpError::InvalidProgram(e) => e.add_args(diag),
853-
InterpError::ResourceExhaustion(e) => e.add_args(diag),
854-
InterpError::MachineStop(e) => e.add_args(&mut |name, value| {
850+
InterpErrorKind::UndefinedBehavior(ub) => ub.add_args(diag),
851+
InterpErrorKind::Unsupported(e) => e.add_args(diag),
852+
InterpErrorKind::InvalidProgram(e) => e.add_args(diag),
853+
InterpErrorKind::ResourceExhaustion(e) => e.add_args(diag),
854+
InterpErrorKind::MachineStop(e) => e.add_args(&mut |name, value| {
855855
diag.arg(name, value);
856856
}),
857857
}

Diff for: compiler/rustc_const_eval/src/interpret/call.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
471471
// Don't forget to mark "initially live" locals as live.
472472
self.storage_live_for_always_live_locals()?;
473473
};
474-
res.inspect_err(|_| {
474+
res.inspect_err_kind(|_| {
475475
// Don't show the incomplete stack frame in the error stacktrace.
476476
self.stack_mut().pop();
477477
})

Diff for: compiler/rustc_const_eval/src/interpret/eval_context.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_trait_selection::traits::ObligationCtxt;
1919
use tracing::{debug, instrument, trace};
2020

2121
use super::{
22-
Frame, FrameInfo, GlobalId, InterpError, InterpErrorInfo, InterpResult, MPlaceTy, Machine,
22+
Frame, FrameInfo, GlobalId, InterpErrorInfo, InterpErrorKind, InterpResult, MPlaceTy, Machine,
2323
MemPlaceMeta, Memory, OpTy, Place, PlaceTy, PointerArithmetic, Projectable, Provenance,
2424
err_inval, interp_ok, throw_inval, throw_ub, throw_ub_custom,
2525
};
@@ -73,7 +73,7 @@ where
7373
}
7474

7575
impl<'tcx, M: Machine<'tcx>> LayoutOfHelpers<'tcx> for InterpCx<'tcx, M> {
76-
type LayoutOfResult = Result<TyAndLayout<'tcx>, InterpError<'tcx>>;
76+
type LayoutOfResult = Result<TyAndLayout<'tcx>, InterpErrorKind<'tcx>>;
7777

7878
#[inline]
7979
fn layout_tcx_at_span(&self) -> Span {
@@ -82,20 +82,25 @@ impl<'tcx, M: Machine<'tcx>> LayoutOfHelpers<'tcx> for InterpCx<'tcx, M> {
8282
}
8383

8484
#[inline]
85-
fn handle_layout_err(&self, err: LayoutError<'tcx>, _: Span, _: Ty<'tcx>) -> InterpError<'tcx> {
85+
fn handle_layout_err(
86+
&self,
87+
err: LayoutError<'tcx>,
88+
_: Span,
89+
_: Ty<'tcx>,
90+
) -> InterpErrorKind<'tcx> {
8691
err_inval!(Layout(err))
8792
}
8893
}
8994

9095
impl<'tcx, M: Machine<'tcx>> FnAbiOfHelpers<'tcx> for InterpCx<'tcx, M> {
91-
type FnAbiOfResult = Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, InterpError<'tcx>>;
96+
type FnAbiOfResult = Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, InterpErrorKind<'tcx>>;
9297

9398
fn handle_fn_abi_err(
9499
&self,
95100
err: FnAbiError<'tcx>,
96101
_span: Span,
97102
_fn_abi_request: FnAbiRequest<'tcx>,
98-
) -> InterpError<'tcx> {
103+
) -> InterpErrorKind<'tcx> {
99104
match err {
100105
FnAbiError::Layout(err) => err_inval!(Layout(err)),
101106
FnAbiError::AdjustForForeignAbi(err) => {

Diff for: compiler/rustc_const_eval/src/interpret/intrinsics.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
324324
dist.checked_neg().unwrap(), // i64::MIN is impossible as no allocation can be that large
325325
CheckInAllocMsg::OffsetFromTest,
326326
)
327-
.map_err(|_| {
327+
.map_err_kind(|_| {
328328
// Make the error more specific.
329329
err_ub_custom!(
330330
fluent::const_eval_offset_from_different_allocations,
331331
name = intrinsic_name,
332332
)
333-
.into()
334333
})?;
335334

336335
// Perform division by size to compute return value.

Diff for: compiler/rustc_const_eval/src/interpret/validity.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use rustc_hir as hir;
1717
use rustc_middle::bug;
1818
use rustc_middle::mir::interpret::ValidationErrorKind::{self, *};
1919
use rustc_middle::mir::interpret::{
20-
ExpectedKind, InterpError, InterpErrorInfo, InvalidMetaKind, Misalignment, PointerKind,
21-
Provenance, UnsupportedOpInfo, ValidationErrorInfo, alloc_range, interp_ok,
20+
ExpectedKind, InterpErrorKind, InvalidMetaKind, Misalignment, PointerKind, Provenance,
21+
UnsupportedOpInfo, ValidationErrorInfo, alloc_range, interp_ok,
2222
};
2323
use rustc_middle::ty::layout::{LayoutCx, LayoutOf, TyAndLayout};
2424
use rustc_middle::ty::{self, Ty};
@@ -37,8 +37,8 @@ use super::{
3737

3838
// for the validation errors
3939
#[rustfmt::skip]
40-
use super::InterpError::UndefinedBehavior as Ub;
41-
use super::InterpError::Unsupported as Unsup;
40+
use super::InterpErrorKind::UndefinedBehavior as Ub;
41+
use super::InterpErrorKind::Unsupported as Unsup;
4242
use super::UndefinedBehaviorInfo::*;
4343
use super::UnsupportedOpInfo::*;
4444

@@ -97,20 +97,19 @@ macro_rules! try_validation {
9797
($e:expr, $where:expr,
9898
$( $( $p:pat_param )|+ => $kind: expr ),+ $(,)?
9999
) => {{
100-
$e.map_err(|e| {
100+
$e.map_err_kind(|e| {
101101
// We catch the error and turn it into a validation failure. We are okay with
102102
// allocation here as this can only slow down builds that fail anyway.
103-
let (kind, backtrace) = e.into_parts();
104-
match kind {
103+
match e {
105104
$(
106105
$($p)|+ => {
107106
err_validation_failure!(
108107
$where,
109108
$kind
110-
).into()
109+
)
111110
}
112111
),+,
113-
_ => InterpErrorInfo::from_parts(kind, backtrace),
112+
e => e,
114113
}
115114
})?
116115
}};
@@ -1230,11 +1229,10 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt,
12301229
// No need for an alignment check here, this is not an actual memory access.
12311230
let alloc = self.ecx.get_ptr_alloc(mplace.ptr(), size)?.expect("we already excluded size 0");
12321231

1233-
alloc.get_bytes_strip_provenance().map_err(|err| {
1232+
alloc.get_bytes_strip_provenance().map_err_kind(|kind| {
12341233
// Some error happened, try to provide a more detailed description.
12351234
// For some errors we might be able to provide extra information.
12361235
// (This custom logic does not fit the `try_validation!` macro.)
1237-
let (kind, backtrace) = err.into_parts();
12381236
match kind {
12391237
Ub(InvalidUninitBytes(Some((_alloc_id, access)))) | Unsup(ReadPointerAsInt(Some((_alloc_id, access)))) => {
12401238
// Some byte was uninitialized, determine which
@@ -1247,14 +1245,14 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt,
12471245
self.path.push(PathElem::ArrayElem(i));
12481246

12491247
if matches!(kind, Ub(InvalidUninitBytes(_))) {
1250-
err_validation_failure!(self.path, Uninit { expected }).into()
1248+
err_validation_failure!(self.path, Uninit { expected })
12511249
} else {
1252-
err_validation_failure!(self.path, PointerAsInt { expected }).into()
1250+
err_validation_failure!(self.path, PointerAsInt { expected })
12531251
}
12541252
}
12551253

12561254
// Propagate upwards (that will also check for unexpected errors).
1257-
_ => return InterpErrorInfo::from_parts(kind, backtrace),
1255+
err => err,
12581256
}
12591257
})?;
12601258

@@ -1368,12 +1366,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
13681366
v.reset_padding(val)?;
13691367
interp_ok(())
13701368
})
1371-
.map_err(|err| {
1369+
.map_err_info(|err| {
13721370
if !matches!(
13731371
err.kind(),
13741372
err_ub!(ValidationError { .. })
1375-
| InterpError::InvalidProgram(_)
1376-
| InterpError::Unsupported(UnsupportedOpInfo::ExternTypeField)
1373+
| InterpErrorKind::InvalidProgram(_)
1374+
| InterpErrorKind::Unsupported(UnsupportedOpInfo::ExternTypeField)
13771375
) {
13781376
bug!(
13791377
"Unexpected error during validation: {}",

Diff for: compiler/rustc_hir_typeck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ fn report_unexpected_variant_res(
419419
}
420420
}
421421

422-
err.multipart_suggestion_verbose(descr, suggestion, Applicability::MaybeIncorrect);
422+
err.multipart_suggestion_verbose(descr, suggestion, Applicability::HasPlaceholders);
423423
err
424424
}
425425
Res::Def(DefKind::Variant, _) if expr.is_none() => {

0 commit comments

Comments
 (0)