Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit dbf7748

Browse files
committed
Auto merge of rust-lang#131914 - workingjubilee:rollup-o0p7v51, r=workingjubilee
Rollup of 8 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.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b27f33a + 8d3e989 commit dbf7748

File tree

23 files changed

+321
-115
lines changed

23 files changed

+321
-115
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
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",

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

Lines changed: 1 addition & 1 deletion
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);

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

Lines changed: 10 additions & 5 deletions
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

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 4 additions & 1 deletion
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);

compiler/rustc_codegen_llvm/src/llvm/mod.rs

Lines changed: 12 additions & 8 deletions
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

compiler/rustc_hir_typeck/src/lib.rs

Lines changed: 1 addition & 1 deletion
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() => {

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,16 +1658,6 @@ extern "C" void LLVMRustPositionBuilderAtStart(LLVMBuilderRef B,
16581658
unwrap(B)->SetInsertPoint(unwrap(BB), Point);
16591659
}
16601660

1661-
extern "C" void LLVMRustSetComdat(LLVMModuleRef M, LLVMValueRef V,
1662-
const char *Name, size_t NameLen) {
1663-
Triple TargetTriple = Triple(unwrap(M)->getTargetTriple());
1664-
GlobalObject *GV = unwrap<GlobalObject>(V);
1665-
if (TargetTriple.supportsCOMDAT()) {
1666-
StringRef NameRef(Name, NameLen);
1667-
GV->setComdat(unwrap(M)->getOrInsertComdat(NameRef));
1668-
}
1669-
}
1670-
16711661
enum class LLVMRustLinkage {
16721662
ExternalLinkage = 0,
16731663
AvailableExternallyLinkage = 1,

compiler/rustc_resolve/src/late.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4011,6 +4011,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
40114011
let instead = res.is_some();
40124012
let suggestion = if let Some((start, end)) = this.diag_metadata.in_range
40134013
&& path[0].ident.span.lo() == end.span.lo()
4014+
&& !matches!(start.kind, ExprKind::Lit(_))
40144015
{
40154016
let mut sugg = ".";
40164017
let mut span = start.span.between(end.span);

compiler/rustc_target/src/spec/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,6 +2514,13 @@ fn add_link_args(link_args: &mut LinkArgs, flavor: LinkerFlavor, args: &[&'stati
25142514
add_link_args_iter(link_args, flavor, args.iter().copied().map(Cow::Borrowed))
25152515
}
25162516

2517+
impl TargetOptions {
2518+
pub fn supports_comdat(&self) -> bool {
2519+
// XCOFF and MachO don't support COMDAT.
2520+
!self.is_like_aix && !self.is_like_osx
2521+
}
2522+
}
2523+
25172524
impl TargetOptions {
25182525
fn link_args(flavor: LinkerFlavor, args: &[&'static str]) -> LinkArgs {
25192526
let mut link_args = LinkArgs::new();

compiler/rustc_ty_utils/src/abi.rs

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::iter;
22

3-
use rustc_abi::Float::*;
43
use rustc_abi::Primitive::{Float, Pointer};
54
use rustc_abi::{Abi, AddressSpace, PointerKind, Scalar, Size};
65
use rustc_hir as hir;
@@ -695,37 +694,31 @@ fn fn_abi_adjust_for_abi<'tcx>(
695694
}
696695

697696
// Avoid returning floats in x87 registers on x86 as loading and storing from x87
698-
// registers will quiet signalling NaNs.
697+
// registers will quiet signalling NaNs. Also avoid using SSE registers since they
698+
// are not always available (depending on target features).
699699
if tcx.sess.target.arch == "x86"
700700
&& arg_idx.is_none()
701701
// Intrinsics themselves are not actual "real" functions, so theres no need to
702702
// change their ABIs.
703703
&& abi != SpecAbi::RustIntrinsic
704704
{
705-
match arg.layout.abi {
706-
// Handle similar to the way arguments with an `Abi::Aggregate` abi are handled
707-
// below, by returning arguments up to the size of a pointer (32 bits on x86)
708-
// cast to an appropriately sized integer.
709-
Abi::Scalar(s) if s.primitive() == Float(F32) => {
710-
// Same size as a pointer, return in a register.
711-
arg.cast_to(Reg::i32());
712-
return;
705+
let has_float = match arg.layout.abi {
706+
Abi::Scalar(s) => matches!(s.primitive(), Float(_)),
707+
Abi::ScalarPair(s1, s2) => {
708+
matches!(s1.primitive(), Float(_)) || matches!(s2.primitive(), Float(_))
713709
}
714-
Abi::Scalar(s) if s.primitive() == Float(F64) => {
715-
// Larger than a pointer, return indirectly.
716-
arg.make_indirect();
717-
return;
718-
}
719-
Abi::ScalarPair(s1, s2)
720-
if matches!(s1.primitive(), Float(F32 | F64))
721-
|| matches!(s2.primitive(), Float(F32 | F64)) =>
722-
{
710+
_ => false, // anyway not passed via registers on x86
711+
};
712+
if has_float {
713+
if arg.layout.size <= Pointer(AddressSpace::DATA).size(cx) {
714+
// Same size or smaller than pointer, return in a register.
715+
arg.cast_to(Reg { kind: RegKind::Integer, size: arg.layout.size });
716+
} else {
723717
// Larger than a pointer, return indirectly.
724718
arg.make_indirect();
725-
return;
726719
}
727-
_ => {}
728-
};
720+
return;
721+
}
729722
}
730723

731724
match arg.layout.abi {

0 commit comments

Comments
 (0)