Skip to content

Commit 2c9471f

Browse files
committed
Auto merge of #158435 - JonathanBrouwer:rollup-BKpv1B2, r=JonathanBrouwer
Rollup of 4 pull requests Successful merges: - #157127 (cg_LLVM: Stop needing an alloca for volatile loads) - #158244 (Attribute docs `deprecated` , `warn`, `allow`, `cfg`, `deny`, and `forbid` ) - #158399 (std: truncate thread names on NetBSD) - #158430 (Guard clone suggestion against empty obligation errors)
2 parents 40557f6 + 75ea249 commit 2c9471f

14 files changed

Lines changed: 469 additions & 45 deletions

File tree

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,15 +1461,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
14611461
let cause = ObligationCause::misc(expr.span, self.mir_def_id());
14621462
ocx.register_bound(cause, self.infcx.param_env, ty, clone_trait);
14631463
let errors = ocx.evaluate_obligations_error_on_ambiguity();
1464-
if errors.iter().all(|error| {
1465-
match error.obligation.predicate.as_clause().and_then(|c| c.as_trait_clause()) {
1466-
Some(clause) => match clause.self_ty().skip_binder().kind() {
1467-
ty::Adt(def, _) => def.did().is_local() && clause.def_id() == clone_trait,
1468-
_ => false,
1469-
},
1470-
None => false,
1471-
}
1472-
}) {
1464+
if !errors.is_empty()
1465+
&& errors.iter().all(|error| {
1466+
match error.obligation.predicate.as_clause().and_then(|c| c.as_trait_clause()) {
1467+
Some(clause) => match clause.self_ty().skip_binder().kind() {
1468+
ty::Adt(def, _) => {
1469+
def.did().is_local() && clause.def_id() == clone_trait
1470+
}
1471+
_ => false,
1472+
},
1473+
None => false,
1474+
}
1475+
})
1476+
{
14731477
let mut type_spans = vec![];
14741478
let mut types = FxIndexSet::default();
14751479
for clause in errors

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
993993
loaded_value.to_rvalue()
994994
}
995995

996-
fn volatile_load(&mut self, ty: Type<'gcc>, ptr: RValue<'gcc>) -> RValue<'gcc> {
996+
fn volatile_load(&mut self, ty: Type<'gcc>, ptr: RValue<'gcc>, _: Align) -> RValue<'gcc> {
997+
// FIXME(antoyo): set alignment.
997998
let ptr = self.context.new_cast(self.location, ptr, ty.make_volatile().make_pointer());
998999
// (FractalFir): We insert a local here, to ensure this volatile load can't move across
9991000
// blocks.

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod simd;
55
use std::iter;
66

77
use gccjit::{ComparisonOp, Function, FunctionType, RValue, ToRValue, Type, UnaryOp};
8-
use rustc_abi::{BackendRepr, HasDataLayout, WrappingRange};
8+
use rustc_abi::{Align, BackendRepr, HasDataLayout, WrappingRange};
99
use rustc_codegen_ssa::base::wants_msvc_seh;
1010
use rustc_codegen_ssa::common::IntPredicate;
1111
use rustc_codegen_ssa::errors::InvalidMonomorphization;
@@ -368,8 +368,9 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
368368

369369
sym::volatile_load | sym::unaligned_volatile_load => {
370370
let ptr = args[0].immediate();
371-
let load = self.volatile_load(result.layout.gcc_type(self), ptr);
372-
// FIXME(antoyo): set alignment.
371+
let abi_align = result_layout.align.abi;
372+
let ptr_align = if name == sym::volatile_load { abi_align } else { Align::ONE };
373+
let load = self.volatile_load(result.layout.gcc_type(self), ptr, ptr_align);
373374
if let BackendRepr::Scalar(scalar) = result.layout.backend_repr {
374375
self.to_immediate_scalar(load, scalar)
375376
} else {

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
682682
}
683683
}
684684

685-
fn volatile_load(&mut self, ty: &'ll Type, ptr: &'ll Value) -> &'ll Value {
685+
fn volatile_load(&mut self, ty: &'ll Type, ptr: &'ll Value, align: Align) -> &'ll Value {
686686
unsafe {
687-
let load = llvm::LLVMBuildLoad2(self.llbuilder, ty, ptr, UNNAMED);
687+
let load = self.load(ty, ptr, align);
688688
llvm::LLVMSetVolatile(load, llvm::TRUE);
689689
load
690690
}

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
978978
}
979979

980980
fn intrinsic_call_expects_place_always(&self, name: Symbol) -> bool {
981-
matches!(name, sym::volatile_load | sym::unaligned_volatile_load | sym::black_box)
981+
matches!(name, sym::black_box)
982982
}
983983
}
984984

compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// .debug_gdb_scripts binary section.
22

3+
use rustc_abi::Align;
34
use rustc_codegen_ssa::base::collect_debugger_visualizers_transitive;
45
use rustc_codegen_ssa::traits::*;
56
use rustc_hir::attrs::DebuggerVisualizerType;
@@ -18,10 +19,7 @@ pub(crate) fn insert_reference_to_gdb_debug_scripts_section_global(bx: &mut Buil
1819
let gdb_debug_scripts_section = get_or_insert_gdb_debug_scripts_section_global(bx);
1920
// Load just the first byte as that's all that's necessary to force
2021
// LLVM to keep around the reference to the global.
21-
let volatile_load_instruction = bx.volatile_load(bx.type_i8(), gdb_debug_scripts_section);
22-
unsafe {
23-
llvm::LLVMSetAlignment(volatile_load_instruction, 1);
24-
}
22+
bx.volatile_load(bx.type_i8(), gdb_debug_scripts_section, Align::ONE);
2523
}
2624
}
2725

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -354,25 +354,39 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
354354
}
355355

356356
sym::volatile_load | sym::unaligned_volatile_load => {
357-
let result = PlaceRef {
358-
val: result_place.unwrap(),
359-
layout: result_layout,
360-
};
361-
357+
// Note that we cannot just load the `llvm_type` because we should never load non-scalars.
358+
// Trying to do so blows up horribly in some cases -- for example loading a
359+
// `MaybeUninint<&dyn Trait>` would load as `{ [i64x2] }` which gives assertions later
360+
// (if we're lucky) from things not being pointers that ought to be.
362361
let ptr = args[0].immediate();
363-
let load = self.volatile_load(result_layout.llvm_type(self), ptr);
364-
let align = if name == sym::unaligned_volatile_load {
365-
1
362+
let abi_align = result_layout.align.abi;
363+
let ptr_align = if name == sym::volatile_load { abi_align } else { Align::ONE };
364+
if result_layout.is_zst() {
365+
return IntrinsicResult::Operand(OperandValue::ZeroSized);
366+
} else if let BackendRepr::Scalar(scalar) = result_layout.backend_repr {
367+
let load = self.volatile_load(self.type_from_scalar(scalar), ptr, ptr_align);
368+
self.to_immediate_scalar(load, scalar)
366369
} else {
367-
result_layout.align.bytes() as u32
368-
};
369-
unsafe {
370-
llvm::LLVMSetAlignment(load, align);
371-
}
372-
if !result_layout.is_zst() {
373-
self.store_to_place(load, result.val);
370+
// One day Rust will probably want to define how we split up a volatile load
371+
// of something that's *not* just an ordinary scalar, but for now we can just
372+
// use an LLVM integer type of the correct width and let it split it however.
373+
let llty = self.type_ix(result_layout.size.bits());
374+
let temp = if let Some(result_place) = result_place {
375+
PlaceRef {
376+
val: result_place,
377+
layout: result_layout,
378+
}
379+
} else {
380+
PlaceRef::alloca(self, result_layout)
381+
};
382+
let llval = self.volatile_load(llty, ptr, ptr_align);
383+
self.store(llval, temp.val.llval, abi_align);
384+
return if result_place.is_none() {
385+
IntrinsicResult::Operand(self.load_operand(temp).val)
386+
} else {
387+
IntrinsicResult::WroteIntoPlace
388+
};
374389
}
375-
return IntrinsicResult::WroteIntoPlace;
376390
}
377391
sym::volatile_store => {
378392
let dst = args[0].deref(self.cx());

compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ pub trait BuilderMethods<'a, 'tcx>:
242242
fn alloca_with_ty(&mut self, layout: TyAndLayout<'tcx>) -> Self::Value;
243243

244244
fn load(&mut self, ty: Self::Type, ptr: Self::Value, align: Align) -> Self::Value;
245-
fn volatile_load(&mut self, ty: Self::Type, ptr: Self::Value) -> Self::Value;
245+
fn volatile_load(&mut self, ty: Self::Type, ptr: Self::Value, align: Align) -> Self::Value;
246246
fn atomic_load(
247247
&mut self,
248248
ty: Self::Type,

0 commit comments

Comments
 (0)