Skip to content

Commit 8556e66

Browse files
committed
Auto merge of #100611 - matthiaskrgr:rollup-rxj10ur, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #100338 (when there are 3 or more return statements in the loop) - #100384 (Add support for generating unique profraw files by default when using `-C instrument-coverage`) - #100460 (Update the minimum external LLVM to 13) - #100567 (Add missing closing quote) - #100590 (Suggest adding an array length if possible) - #100600 (Rename Machine memory hooks to suggest when they run) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents ef9810a + 88af506 commit 8556e66

Some content is hidden

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

50 files changed

+318
-335
lines changed

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
- name: mingw-check
4444
os: ubuntu-20.04-xl
4545
env: {}
46-
- name: x86_64-gnu-llvm-12
46+
- name: x86_64-gnu-llvm-13
4747
os: ubuntu-20.04-xl
4848
env: {}
4949
- name: x86_64-gnu-tools
@@ -274,11 +274,11 @@ jobs:
274274
- name: x86_64-gnu-distcheck
275275
os: ubuntu-20.04-xl
276276
env: {}
277-
- name: x86_64-gnu-llvm-12
277+
- name: x86_64-gnu-llvm-13
278278
env:
279279
RUST_BACKTRACE: 1
280280
os: ubuntu-20.04-xl
281-
- name: x86_64-gnu-llvm-12-stage1
281+
- name: x86_64-gnu-llvm-13-stage1
282282
env:
283283
RUST_BACKTRACE: 1
284284
os: ubuntu-20.04-xl

compiler/rustc_ast_lowering/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use rustc_data_structures::fx::FxHashMap;
4848
use rustc_data_structures::sorted_map::SortedMap;
4949
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
5050
use rustc_data_structures::sync::Lrc;
51-
use rustc_errors::{struct_span_err, Applicability, Handler};
51+
use rustc_errors::{struct_span_err, Applicability, Handler, StashKey};
5252
use rustc_hir as hir;
5353
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
5454
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
@@ -2233,7 +2233,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22332233
c.value.span,
22342234
"using `_` for array lengths is unstable",
22352235
)
2236-
.emit();
2236+
.stash(c.value.span, StashKey::UnderscoreForArrayLengths);
22372237
hir::ArrayLen::Body(self.lower_anon_const(c))
22382238
}
22392239
}

compiler/rustc_codegen_llvm/src/asm.rs

-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::builder::Builder;
33
use crate::common::Funclet;
44
use crate::context::CodegenCx;
55
use crate::llvm;
6-
use crate::llvm_util;
76
use crate::type_::Type;
87
use crate::type_of::LayoutLlvmExt;
98
use crate::value::Value;
@@ -419,13 +418,6 @@ pub(crate) fn inline_asm_call<'ll>(
419418
let constraints_ok = llvm::LLVMRustInlineAsmVerify(fty, cons.as_ptr().cast(), cons.len());
420419
debug!("constraint verification result: {:?}", constraints_ok);
421420
if constraints_ok {
422-
if unwind && llvm_util::get_version() < (13, 0, 0) {
423-
bx.cx.sess().span_fatal(
424-
line_spans[0],
425-
"unwinding from inline assembly is only supported on llvm >= 13.",
426-
);
427-
}
428-
429421
let v = llvm::LLVMRustInlineAsm(
430422
fty,
431423
asm.as_ptr().cast(),

compiler/rustc_codegen_llvm/src/back/write.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::back::profiling::{
55
use crate::base;
66
use crate::common;
77
use crate::consts;
8-
use crate::llvm::{self, DiagnosticInfo, PassManager, SMDiagnostic};
8+
use crate::llvm::{self, DiagnosticInfo, PassManager};
99
use crate::llvm_util;
1010
use crate::type_::Type;
1111
use crate::LlvmCodegenBackend;
@@ -304,17 +304,14 @@ impl<'a> DiagnosticHandlers<'a> {
304304
remark_passes.as_ptr(),
305305
remark_passes.len(),
306306
);
307-
llvm::LLVMRustSetInlineAsmDiagnosticHandler(llcx, inline_asm_handler, data.cast());
308307
DiagnosticHandlers { data, llcx, old_handler }
309308
}
310309
}
311310
}
312311

313312
impl<'a> Drop for DiagnosticHandlers<'a> {
314313
fn drop(&mut self) {
315-
use std::ptr::null_mut;
316314
unsafe {
317-
llvm::LLVMRustSetInlineAsmDiagnosticHandler(self.llcx, inline_asm_handler, null_mut());
318315
llvm::LLVMRustContextSetDiagnosticHandler(self.llcx, self.old_handler);
319316
drop(Box::from_raw(self.data));
320317
}
@@ -342,16 +339,6 @@ fn report_inline_asm(
342339
cgcx.diag_emitter.inline_asm_error(cookie as u32, msg, level, source);
343340
}
344341

345-
unsafe extern "C" fn inline_asm_handler(diag: &SMDiagnostic, user: *const c_void, cookie: c_uint) {
346-
if user.is_null() {
347-
return;
348-
}
349-
let (cgcx, _) = *(user as *const (&CodegenContext<LlvmCodegenBackend>, &Handler));
350-
351-
let smdiag = llvm::diagnostic::SrcMgrDiagnostic::unpack(diag);
352-
report_inline_asm(cgcx, smdiag.message, smdiag.level, cookie, smdiag.source);
353-
}
354-
355342
unsafe extern "C" fn diagnostic_handler(info: &DiagnosticInfo, user: *mut c_void) {
356343
if user.is_null() {
357344
return;
@@ -423,6 +410,14 @@ fn get_pgo_sample_use_path(config: &ModuleConfig) -> Option<CString> {
423410
.map(|path_buf| CString::new(path_buf.to_string_lossy().as_bytes()).unwrap())
424411
}
425412

413+
fn get_instr_profile_output_path(config: &ModuleConfig) -> Option<CString> {
414+
if config.instrument_coverage {
415+
Some(CString::new("default_%m_%p.profraw").unwrap())
416+
} else {
417+
None
418+
}
419+
}
420+
426421
pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
427422
cgcx: &CodegenContext<LlvmCodegenBackend>,
428423
diag_handler: &Handler,
@@ -438,6 +433,7 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
438433
let pgo_use_path = get_pgo_use_path(config);
439434
let pgo_sample_use_path = get_pgo_sample_use_path(config);
440435
let is_lto = opt_stage == llvm::OptStage::ThinLTO || opt_stage == llvm::OptStage::FatLTO;
436+
let instr_profile_output_path = get_instr_profile_output_path(config);
441437
// Sanitizer instrumentation is only inserted during the pre-link optimization stage.
442438
let sanitizer_options = if !is_lto {
443439
Some(llvm::SanitizerOptions {
@@ -488,6 +484,7 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
488484
pgo_gen_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()),
489485
pgo_use_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()),
490486
config.instrument_coverage,
487+
instr_profile_output_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()),
491488
config.instrument_gcov,
492489
pgo_sample_use_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()),
493490
config.debug_info_for_profiling,

compiler/rustc_codegen_llvm/src/builder.rs

+25-54
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::common::Funclet;
33
use crate::context::CodegenCx;
44
use crate::llvm::{self, BasicBlock, False};
55
use crate::llvm::{AtomicOrdering, AtomicRmwBinOp, SynchronizationScope};
6-
use crate::llvm_util;
76
use crate::type_::Type;
87
use crate::type_of::LayoutLlvmExt;
98
use crate::value::Value;
@@ -1038,25 +1037,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
10381037
dst: &'ll Value,
10391038
cmp: &'ll Value,
10401039
src: &'ll Value,
1041-
mut order: rustc_codegen_ssa::common::AtomicOrdering,
1040+
order: rustc_codegen_ssa::common::AtomicOrdering,
10421041
failure_order: rustc_codegen_ssa::common::AtomicOrdering,
10431042
weak: bool,
10441043
) -> &'ll Value {
10451044
let weak = if weak { llvm::True } else { llvm::False };
1046-
if llvm_util::get_version() < (13, 0, 0) {
1047-
use rustc_codegen_ssa::common::AtomicOrdering::*;
1048-
// Older llvm has the pre-C++17 restriction on
1049-
// success and failure memory ordering,
1050-
// requiring the former to be at least as strong as the latter.
1051-
// So, for llvm 12, we upgrade the success ordering to a stronger
1052-
// one if necessary.
1053-
match (order, failure_order) {
1054-
(Relaxed, Acquire) => order = Acquire,
1055-
(Release, Acquire) => order = AcquireRelease,
1056-
(_, SequentiallyConsistent) => order = SequentiallyConsistent,
1057-
_ => {}
1058-
}
1059-
}
10601045
unsafe {
10611046
llvm::LLVMRustBuildAtomicCmpXchg(
10621047
self.llbuilder,
@@ -1444,51 +1429,37 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
14441429
}
14451430
}
14461431

1447-
fn fptoint_sat_broken_in_llvm(&self) -> bool {
1448-
match self.tcx.sess.target.arch.as_ref() {
1449-
// FIXME - https://bugs.llvm.org/show_bug.cgi?id=50083
1450-
"riscv64" => llvm_util::get_version() < (13, 0, 0),
1451-
_ => false,
1452-
}
1453-
}
1454-
14551432
fn fptoint_sat(
14561433
&mut self,
14571434
signed: bool,
14581435
val: &'ll Value,
14591436
dest_ty: &'ll Type,
14601437
) -> Option<&'ll Value> {
1461-
if !self.fptoint_sat_broken_in_llvm() {
1462-
let src_ty = self.cx.val_ty(val);
1463-
let (float_ty, int_ty, vector_length) = if self.cx.type_kind(src_ty) == TypeKind::Vector
1464-
{
1465-
assert_eq!(self.cx.vector_length(src_ty), self.cx.vector_length(dest_ty));
1466-
(
1467-
self.cx.element_type(src_ty),
1468-
self.cx.element_type(dest_ty),
1469-
Some(self.cx.vector_length(src_ty)),
1470-
)
1471-
} else {
1472-
(src_ty, dest_ty, None)
1473-
};
1474-
let float_width = self.cx.float_width(float_ty);
1475-
let int_width = self.cx.int_width(int_ty);
1476-
1477-
let instr = if signed { "fptosi" } else { "fptoui" };
1478-
let name = if let Some(vector_length) = vector_length {
1479-
format!(
1480-
"llvm.{}.sat.v{}i{}.v{}f{}",
1481-
instr, vector_length, int_width, vector_length, float_width
1482-
)
1483-
} else {
1484-
format!("llvm.{}.sat.i{}.f{}", instr, int_width, float_width)
1485-
};
1486-
let f =
1487-
self.declare_cfn(&name, llvm::UnnamedAddr::No, self.type_func(&[src_ty], dest_ty));
1488-
Some(self.call(self.type_func(&[src_ty], dest_ty), f, &[val], None))
1438+
let src_ty = self.cx.val_ty(val);
1439+
let (float_ty, int_ty, vector_length) = if self.cx.type_kind(src_ty) == TypeKind::Vector {
1440+
assert_eq!(self.cx.vector_length(src_ty), self.cx.vector_length(dest_ty));
1441+
(
1442+
self.cx.element_type(src_ty),
1443+
self.cx.element_type(dest_ty),
1444+
Some(self.cx.vector_length(src_ty)),
1445+
)
14891446
} else {
1490-
None
1491-
}
1447+
(src_ty, dest_ty, None)
1448+
};
1449+
let float_width = self.cx.float_width(float_ty);
1450+
let int_width = self.cx.int_width(int_ty);
1451+
1452+
let instr = if signed { "fptosi" } else { "fptoui" };
1453+
let name = if let Some(vector_length) = vector_length {
1454+
format!(
1455+
"llvm.{}.sat.v{}i{}.v{}f{}",
1456+
instr, vector_length, int_width, vector_length, float_width
1457+
)
1458+
} else {
1459+
format!("llvm.{}.sat.i{}.f{}", instr, int_width, float_width)
1460+
};
1461+
let f = self.declare_cfn(&name, llvm::UnnamedAddr::No, self.type_func(&[src_ty], dest_ty));
1462+
Some(self.call(self.type_func(&[src_ty], dest_ty), f, &[val], None))
14921463
}
14931464

14941465
pub(crate) fn landing_pad(

compiler/rustc_codegen_llvm/src/context.rs

-11
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,6 @@ pub unsafe fn create_module<'ll>(
142142

143143
let mut target_data_layout = sess.target.data_layout.to_string();
144144
let llvm_version = llvm_util::get_version();
145-
if llvm_version < (13, 0, 0) {
146-
if sess.target.arch == "powerpc64" {
147-
target_data_layout = target_data_layout.replace("-S128", "");
148-
}
149-
if sess.target.arch == "wasm32" {
150-
target_data_layout = "e-m:e-p:32:32-i64:64-n32:64-S128".to_string();
151-
}
152-
if sess.target.arch == "wasm64" {
153-
target_data_layout = "e-m:e-p:64:64-i64:64-n32:64-S128".to_string();
154-
}
155-
}
156145
if llvm_version < (14, 0, 0) {
157146
if sess.target.llvm_target == "i686-pc-windows-msvc"
158147
|| sess.target.llvm_target == "i586-pc-windows-msvc"

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -2360,6 +2360,7 @@ extern "C" {
23602360
PGOGenPath: *const c_char,
23612361
PGOUsePath: *const c_char,
23622362
InstrumentCoverage: bool,
2363+
InstrProfileOutput: *const c_char,
23632364
InstrumentGCOV: bool,
23642365
PGOSampleUsePath: *const c_char,
23652366
DebugInfoForProfiling: bool,
@@ -2423,12 +2424,6 @@ extern "C" {
24232424
cookie_out: &mut c_uint,
24242425
) -> &'a SMDiagnostic;
24252426

2426-
pub fn LLVMRustSetInlineAsmDiagnosticHandler(
2427-
C: &Context,
2428-
H: InlineAsmDiagHandlerTy,
2429-
CX: *mut c_void,
2430-
);
2431-
24322427
#[allow(improper_ctypes)]
24332428
pub fn LLVMRustUnpackSMDiagnostic(
24342429
d: &SMDiagnostic,

compiler/rustc_codegen_llvm/src/llvm_util.rs

-10
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,6 @@ unsafe fn configure_llvm(sess: &Session) {
9292
add("-generate-arange-section", false);
9393
}
9494

95-
// Disable the machine outliner by default in LLVM versions 11 and LLVM
96-
// version 12, where it leads to miscompilation.
97-
//
98-
// Ref:
99-
// - https://github.com/rust-lang/rust/issues/85351
100-
// - https://reviews.llvm.org/D103167
101-
if llvm_util::get_version() < (13, 0, 0) {
102-
add("-enable-machine-outliner=never", false);
103-
}
104-
10595
match sess.opts.unstable_opts.merge_functions.unwrap_or(sess.target.merge_functions) {
10696
MergeFunctions::Disabled | MergeFunctions::Trampolines => {}
10797
MergeFunctions::Aliases => {

compiler/rustc_const_eval/src/interpret/machine.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
343343
/// operations take `&self`. Use a `RefCell` in `AllocExtra` if you
344344
/// need to mutate.
345345
#[inline(always)]
346-
fn memory_read(
346+
fn before_memory_read(
347347
_tcx: TyCtxt<'tcx>,
348348
_machine: &Self,
349349
_alloc_extra: &Self::AllocExtra,
@@ -355,7 +355,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
355355

356356
/// Hook for performing extra checks on a memory write access.
357357
#[inline(always)]
358-
fn memory_written(
358+
fn before_memory_write(
359359
_tcx: TyCtxt<'tcx>,
360360
_machine: &mut Self,
361361
_alloc_extra: &mut Self::AllocExtra,
@@ -367,7 +367,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
367367

368368
/// Hook for performing extra operations on a memory deallocation.
369369
#[inline(always)]
370-
fn memory_deallocated(
370+
fn before_memory_deallocation(
371371
_tcx: TyCtxt<'tcx>,
372372
_machine: &mut Self,
373373
_alloc_extra: &mut Self::AllocExtra,

compiler/rustc_const_eval/src/interpret/memory.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
327327

328328
// Let the machine take some extra action
329329
let size = alloc.size();
330-
M::memory_deallocated(
330+
M::before_memory_deallocation(
331331
*self.tcx,
332332
&mut self.machine,
333333
&mut alloc.extra,
@@ -575,7 +575,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
575575
)?;
576576
if let Some((alloc_id, offset, prov, alloc)) = ptr_and_alloc {
577577
let range = alloc_range(offset, size);
578-
M::memory_read(*self.tcx, &self.machine, &alloc.extra, (alloc_id, prov), range)?;
578+
M::before_memory_read(*self.tcx, &self.machine, &alloc.extra, (alloc_id, prov), range)?;
579579
Ok(Some(AllocRef { alloc, range, tcx: *self.tcx, alloc_id }))
580580
} else {
581581
// Even in this branch we have to be sure that we actually access the allocation, in
@@ -641,7 +641,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
641641
// We cannot call `get_raw_mut` inside `check_and_deref_ptr` as that would duplicate `&mut self`.
642642
let (alloc, machine) = self.get_alloc_raw_mut(alloc_id)?;
643643
let range = alloc_range(offset, size);
644-
M::memory_written(tcx, machine, &mut alloc.extra, (alloc_id, prov), range)?;
644+
M::before_memory_write(tcx, machine, &mut alloc.extra, (alloc_id, prov), range)?;
645645
Ok(Some(AllocRefMut { alloc, range, tcx, alloc_id }))
646646
} else {
647647
Ok(None)
@@ -1078,7 +1078,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
10781078
};
10791079
let src_alloc = self.get_alloc_raw(src_alloc_id)?;
10801080
let src_range = alloc_range(src_offset, size);
1081-
M::memory_read(*tcx, &self.machine, &src_alloc.extra, (src_alloc_id, src_prov), src_range)?;
1081+
M::before_memory_read(
1082+
*tcx,
1083+
&self.machine,
1084+
&src_alloc.extra,
1085+
(src_alloc_id, src_prov),
1086+
src_range,
1087+
)?;
10821088
// We need the `dest` ptr for the next operation, so we get it now.
10831089
// We already did the source checks and called the hooks so we are good to return early.
10841090
let Some((dest_alloc_id, dest_offset, dest_prov)) = dest_parts else {
@@ -1103,7 +1109,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
11031109
// Destination alloc preparations and access hooks.
11041110
let (dest_alloc, extra) = self.get_alloc_raw_mut(dest_alloc_id)?;
11051111
let dest_range = alloc_range(dest_offset, size * num_copies);
1106-
M::memory_written(
1112+
M::before_memory_write(
11071113
*tcx,
11081114
extra,
11091115
&mut dest_alloc.extra,

compiler/rustc_errors/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ struct HandlerInner {
457457
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
458458
pub enum StashKey {
459459
ItemNoType,
460+
UnderscoreForArrayLengths,
460461
}
461462

462463
fn default_track_diagnostic(_: &Diagnostic) {}

compiler/rustc_feature/src/builtin_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
277277
ungated!(ignore, Normal, template!(Word, NameValueStr: "reason"), WarnFollowing),
278278
ungated!(
279279
should_panic, Normal,
280-
template!(Word, List: r#"expected = "reason"#, NameValueStr: "reason"), FutureWarnFollowing,
280+
template!(Word, List: r#"expected = "reason""#, NameValueStr: "reason"), FutureWarnFollowing,
281281
),
282282
// FIXME(Centril): This can be used on stable but shouldn't.
283283
ungated!(reexport_test_harness_main, CrateLevel, template!(NameValueStr: "name"), ErrorFollowing),

0 commit comments

Comments
 (0)