Skip to content

Commit f0aceed

Browse files
committed
Auto merge of #126817 - workingjubilee:rollup-0rg0k55, r=workingjubilee
Rollup of 7 pull requests Successful merges: - #126530 (Add `f16` inline ASM support for RISC-V) - #126712 (Migrate `relocation-model`, `error-writing-dependencies` and `crate-name-priority` `run-make` tests to rmake) - #126722 (Add method to get `FnAbi` of function pointer) - #126787 (Add direct accessors for memory addresses in `Machine` (for Miri)) - #126798 ([fuchsia-test-runner] Remove usage of kw_only) - #126809 (Remove stray `.` from error message) - #126811 (Add a tidy rule to check that fluent messages and attrs don't end in `.`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 10e1f5d + 1916b3d commit f0aceed

File tree

51 files changed

+412
-128
lines changed

Some content is hidden

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

51 files changed

+412
-128
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5700,6 +5700,7 @@ name = "tidy"
57005700
version = "0.1.0"
57015701
dependencies = [
57025702
"cargo_metadata 0.15.4",
5703+
"fluent-syntax",
57035704
"ignore",
57045705
"miropt-test-tools",
57055706
"regex",

compiler/rustc_ast_lowering/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ ast_lowering_inline_asm_unsupported_target =
7878
ast_lowering_invalid_abi =
7979
invalid ABI: found `{$abi}`
8080
.label = invalid ABI
81-
.note = invoke `{$command}` for a full list of supported calling conventions.
81+
.note = invoke `{$command}` for a full list of supported calling conventions
8282
8383
ast_lowering_invalid_abi_clobber_abi =
8484
invalid ABI for `clobber_abi`

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_codegen_ssa::traits::*;
1313
use rustc_data_structures::fx::FxHashMap;
1414
use rustc_middle::ty::layout::TyAndLayout;
1515
use rustc_middle::{bug, span_bug, ty::Instance};
16-
use rustc_span::{Pos, Span};
16+
use rustc_span::{sym, Pos, Span, Symbol};
1717
use rustc_target::abi::*;
1818
use rustc_target::asm::*;
1919
use tracing::debug;
@@ -64,7 +64,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
6464
let mut layout = None;
6565
let ty = if let Some(ref place) = place {
6666
layout = Some(&place.layout);
67-
llvm_fixup_output_type(self.cx, reg.reg_class(), &place.layout)
67+
llvm_fixup_output_type(self.cx, reg.reg_class(), &place.layout, instance)
6868
} else if matches!(
6969
reg.reg_class(),
7070
InlineAsmRegClass::X86(
@@ -112,7 +112,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
112112
// so we just use the type of the input.
113113
&in_value.layout
114114
};
115-
let ty = llvm_fixup_output_type(self.cx, reg.reg_class(), layout);
115+
let ty = llvm_fixup_output_type(self.cx, reg.reg_class(), layout, instance);
116116
output_types.push(ty);
117117
op_idx.insert(idx, constraints.len());
118118
let prefix = if late { "=" } else { "=&" };
@@ -127,8 +127,13 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
127127
for (idx, op) in operands.iter().enumerate() {
128128
match *op {
129129
InlineAsmOperandRef::In { reg, value } => {
130-
let llval =
131-
llvm_fixup_input(self, value.immediate(), reg.reg_class(), &value.layout);
130+
let llval = llvm_fixup_input(
131+
self,
132+
value.immediate(),
133+
reg.reg_class(),
134+
&value.layout,
135+
instance,
136+
);
132137
inputs.push(llval);
133138
op_idx.insert(idx, constraints.len());
134139
constraints.push(reg_to_llvm(reg, Some(&value.layout)));
@@ -139,6 +144,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
139144
in_value.immediate(),
140145
reg.reg_class(),
141146
&in_value.layout,
147+
instance,
142148
);
143149
inputs.push(value);
144150

@@ -341,7 +347,8 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
341347
} else {
342348
self.extract_value(result, op_idx[&idx] as u64)
343349
};
344-
let value = llvm_fixup_output(self, value, reg.reg_class(), &place.layout);
350+
let value =
351+
llvm_fixup_output(self, value, reg.reg_class(), &place.layout, instance);
345352
OperandValue::Immediate(value).store(self, place);
346353
}
347354
}
@@ -913,12 +920,22 @@ fn llvm_asm_scalar_type<'ll>(cx: &CodegenCx<'ll, '_>, scalar: Scalar) -> &'ll Ty
913920
}
914921
}
915922

923+
fn any_target_feature_enabled(
924+
cx: &CodegenCx<'_, '_>,
925+
instance: Instance<'_>,
926+
features: &[Symbol],
927+
) -> bool {
928+
let enabled = cx.tcx.asm_target_features(instance.def_id());
929+
features.iter().any(|feat| enabled.contains(feat))
930+
}
931+
916932
/// Fix up an input value to work around LLVM bugs.
917933
fn llvm_fixup_input<'ll, 'tcx>(
918934
bx: &mut Builder<'_, 'll, 'tcx>,
919935
mut value: &'ll Value,
920936
reg: InlineAsmRegClass,
921937
layout: &TyAndLayout<'tcx>,
938+
instance: Instance<'_>,
922939
) -> &'ll Value {
923940
let dl = &bx.tcx.data_layout;
924941
match (reg, layout.abi) {
@@ -1029,6 +1046,16 @@ fn llvm_fixup_input<'ll, 'tcx>(
10291046
_ => value,
10301047
}
10311048
}
1049+
(InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg), Abi::Scalar(s))
1050+
if s.primitive() == Primitive::Float(Float::F16)
1051+
&& !any_target_feature_enabled(bx, instance, &[sym::zfhmin, sym::zfh]) =>
1052+
{
1053+
// Smaller floats are always "NaN-boxed" inside larger floats on RISC-V.
1054+
let value = bx.bitcast(value, bx.type_i16());
1055+
let value = bx.zext(value, bx.type_i32());
1056+
let value = bx.or(value, bx.const_u32(0xFFFF_0000));
1057+
bx.bitcast(value, bx.type_f32())
1058+
}
10321059
_ => value,
10331060
}
10341061
}
@@ -1039,6 +1066,7 @@ fn llvm_fixup_output<'ll, 'tcx>(
10391066
mut value: &'ll Value,
10401067
reg: InlineAsmRegClass,
10411068
layout: &TyAndLayout<'tcx>,
1069+
instance: Instance<'_>,
10421070
) -> &'ll Value {
10431071
match (reg, layout.abi) {
10441072
(InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg), Abi::Scalar(s)) => {
@@ -1140,6 +1168,14 @@ fn llvm_fixup_output<'ll, 'tcx>(
11401168
_ => value,
11411169
}
11421170
}
1171+
(InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg), Abi::Scalar(s))
1172+
if s.primitive() == Primitive::Float(Float::F16)
1173+
&& !any_target_feature_enabled(bx, instance, &[sym::zfhmin, sym::zfh]) =>
1174+
{
1175+
let value = bx.bitcast(value, bx.type_i32());
1176+
let value = bx.trunc(value, bx.type_i16());
1177+
bx.bitcast(value, bx.type_f16())
1178+
}
11431179
_ => value,
11441180
}
11451181
}
@@ -1149,6 +1185,7 @@ fn llvm_fixup_output_type<'ll, 'tcx>(
11491185
cx: &CodegenCx<'ll, 'tcx>,
11501186
reg: InlineAsmRegClass,
11511187
layout: &TyAndLayout<'tcx>,
1188+
instance: Instance<'_>,
11521189
) -> &'ll Type {
11531190
match (reg, layout.abi) {
11541191
(InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg), Abi::Scalar(s)) => {
@@ -1242,6 +1279,12 @@ fn llvm_fixup_output_type<'ll, 'tcx>(
12421279
_ => layout.llvm_type(cx),
12431280
}
12441281
}
1282+
(InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg), Abi::Scalar(s))
1283+
if s.primitive() == Primitive::Float(Float::F16)
1284+
&& !any_target_feature_enabled(cx, instance, &[sym::zfhmin, sym::zfh]) =>
1285+
{
1286+
cx.type_f32()
1287+
}
12451288
_ => layout.llvm_type(cx),
12461289
}
12471290
}

compiler/rustc_const_eval/messages.ftl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,7 @@ const_eval_unallowed_fn_pointer_call = function pointer calls are not allowed in
341341
const_eval_unallowed_heap_allocations =
342342
allocations are not allowed in {const_eval_const_context}s
343343
.label = allocation not allowed in {const_eval_const_context}s
344-
.teach_note =
345-
The value of statics and constants must be known at compile time, and they live for the entire lifetime of a program. Creating a boxed value allocates memory on the heap at runtime, and therefore cannot be done at compile time.
344+
.teach_note = The value of statics and constants must be known at compile time, and they live for the entire lifetime of a program. Creating a boxed value allocates memory on the heap at runtime, and therefore cannot be done at compile time.
346345
347346
const_eval_unallowed_inline_asm =
348347
inline assembly is not allowed in {const_eval_const_context}s

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
630630
}
631631
}
632632

633+
/// Gives raw, immutable access to the `Allocation` address, without bounds or alignment checks.
634+
/// The caller is responsible for calling the access hooks!
635+
pub fn get_alloc_bytes_unchecked_raw(&self, id: AllocId) -> InterpResult<'tcx, *const u8> {
636+
let alloc = self.get_alloc_raw(id)?;
637+
Ok(alloc.get_bytes_unchecked_raw())
638+
}
639+
633640
/// Bounds-checked *but not align-checked* allocation access.
634641
pub fn get_ptr_alloc<'a>(
635642
&'a self,
@@ -713,6 +720,16 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
713720
Ok((alloc, &mut self.machine))
714721
}
715722

723+
/// Gives raw, mutable access to the `Allocation` address, without bounds or alignment checks.
724+
/// The caller is responsible for calling the access hooks!
725+
pub fn get_alloc_bytes_unchecked_raw_mut(
726+
&mut self,
727+
id: AllocId,
728+
) -> InterpResult<'tcx, *mut u8> {
729+
let alloc = self.get_alloc_raw_mut(id)?.0;
730+
Ok(alloc.get_bytes_unchecked_raw_mut())
731+
}
732+
716733
/// Bounds-checked *but not align-checked* allocation access.
717734
pub fn get_ptr_alloc_mut<'a>(
718735
&'a mut self,

compiler/rustc_hir_analysis/messages.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ hir_analysis_inherent_ty_outside = cannot define inherent `impl` for a type outs
194194
.span_help = alternatively add `#[rustc_has_incoherent_inherent_impls]` to the type and `#[rustc_allow_incoherent_impl]` to the relevant impl items
195195
196196
hir_analysis_inherent_ty_outside_new = cannot define inherent `impl` for a type outside of the crate where the type is defined
197-
.label = impl for type defined outside of crate.
197+
.label = impl for type defined outside of crate
198198
.note = define and implement a trait or new type instead
199199
200200
hir_analysis_inherent_ty_outside_primitive = cannot define inherent `impl` for primitive types outside of `core`
@@ -544,7 +544,7 @@ hir_analysis_unrecognized_intrinsic_function =
544544
545545
hir_analysis_unused_associated_type_bounds =
546546
unnecessary associated type bound for not object safe associated type
547-
.note = this associated type has a `where Self: Sized` bound. Thus, while the associated type can be specified, it cannot be used in any way, because trait objects are not `Sized`.
547+
.note = this associated type has a `where Self: Sized` bound, and while the associated type can be specified, it cannot be used because trait objects are never `Sized`
548548
.suggestion = remove this bound
549549
550550
hir_analysis_unused_generic_parameter =

compiler/rustc_lint/messages.ftl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ lint_builtin_deprecated_attr_default_suggestion = remove this attribute
7575
lint_builtin_deprecated_attr_link = use of deprecated attribute `{$name}`: {$reason}. See {$link}
7676
.msg_suggestion = {$msg}
7777
.default_suggestion = remove this attribute
78-
lint_builtin_deprecated_attr_used = use of deprecated attribute `{$name}`: no longer used.
78+
lint_builtin_deprecated_attr_used = use of deprecated attribute `{$name}`: no longer used
7979
lint_builtin_deref_nullptr = dereferencing a null pointer
8080
.label = this code causes undefined behavior when executed
8181
@@ -213,7 +213,7 @@ lint_default_hash_types = prefer `{$preferred}` over `{$used}`, it has better pe
213213
lint_default_source = `forbid` lint level is the default for {$id}
214214
215215
lint_deprecated_lint_name =
216-
lint name `{$name}` is deprecated and may not have an effect in the future.
216+
lint name `{$name}` is deprecated and may not have an effect in the future
217217
.suggestion = change it to
218218
.help = change it to {$replace}
219219
@@ -244,11 +244,11 @@ lint_duplicate_matcher_binding = duplicate matcher binding
244244
245245
lint_enum_intrinsics_mem_discriminant =
246246
the return value of `mem::discriminant` is unspecified when called with a non-enum type
247-
.note = the argument to `discriminant` should be a reference to an enum, but it was passed a reference to a `{$ty_param}`, which is not an enum.
247+
.note = the argument to `discriminant` should be a reference to an enum, but it was passed a reference to a `{$ty_param}`, which is not an enum
248248
249249
lint_enum_intrinsics_mem_variant =
250250
the return value of `mem::variant_count` is unspecified when called with a non-enum type
251-
.note = the type parameter of `variant_count` should be an enum, but it was instantiated with the type `{$ty_param}`, which is not an enum.
251+
.note = the type parameter of `variant_count` should be an enum, but it was instantiated with the type `{$ty_param}`, which is not an enum
252252
253253
lint_expectation = this lint expectation is unfulfilled
254254
.note = the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message

compiler/rustc_metadata/messages.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,13 @@ metadata_rustc_lib_required =
248248
.help = try adding `extern crate rustc_driver;` at the top level of this crate
249249
250250
metadata_stable_crate_id_collision =
251-
found crates (`{$crate_name0}` and `{$crate_name1}`) with colliding StableCrateId values.
251+
found crates (`{$crate_name0}` and `{$crate_name1}`) with colliding StableCrateId values
252252
253253
metadata_std_required =
254254
`std` is required by `{$current_crate}` because it does not declare `#![no_std]`
255255
256256
metadata_symbol_conflicts_current =
257-
the current crate is indistinguishable from one of its dependencies: it has the same crate-name `{$crate_name}` and was compiled with the same `-C metadata` arguments. This will result in symbol conflicts between the two.
257+
the current crate is indistinguishable from one of its dependencies: it has the same crate-name `{$crate_name}` and was compiled with the same `-C metadata` arguments, so this will result in symbol conflicts between the two
258258
259259
metadata_target_no_std_support =
260260
the `{$locator_triple}` target may not support the standard library

compiler/rustc_middle/src/mir/interpret/allocation.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,16 @@ pub trait AllocBytes: Clone + fmt::Debug + Deref<Target = [u8]> + DerefMut<Targe
4040
/// Gives direct access to the raw underlying storage.
4141
///
4242
/// Crucially this pointer is compatible with:
43-
/// - other pointers retunred by this method, and
43+
/// - other pointers returned by this method, and
4444
/// - references returned from `deref()`, as long as there was no write.
4545
fn as_mut_ptr(&mut self) -> *mut u8;
46+
47+
/// Gives direct access to the raw underlying storage.
48+
///
49+
/// Crucially this pointer is compatible with:
50+
/// - other pointers returned by this method, and
51+
/// - references returned from `deref()`, as long as there was no write.
52+
fn as_ptr(&self) -> *const u8;
4653
}
4754

4855
/// Default `bytes` for `Allocation` is a `Box<u8>`.
@@ -62,6 +69,11 @@ impl AllocBytes for Box<[u8]> {
6269
// Carefully avoiding any intermediate references.
6370
ptr::addr_of_mut!(**self).cast()
6471
}
72+
73+
fn as_ptr(&self) -> *const u8 {
74+
// Carefully avoiding any intermediate references.
75+
ptr::addr_of!(**self).cast()
76+
}
6577
}
6678

6779
/// This type represents an Allocation in the Miri/CTFE core engine.
@@ -490,19 +502,27 @@ impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes>
490502
self.provenance.clear(range, cx)?;
491503

492504
assert!(range.end().bytes_usize() <= self.bytes.len()); // need to do our own bounds-check
493-
// Cruciall, we go via `AllocBytes::as_mut_ptr`, not `AllocBytes::deref_mut`.
505+
// Crucially, we go via `AllocBytes::as_mut_ptr`, not `AllocBytes::deref_mut`.
494506
let begin_ptr = self.bytes.as_mut_ptr().wrapping_add(range.start.bytes_usize());
495507
let len = range.end().bytes_usize() - range.start.bytes_usize();
496508
Ok(ptr::slice_from_raw_parts_mut(begin_ptr, len))
497509
}
498510

499511
/// This gives direct mutable access to the entire buffer, just exposing their internal state
500-
/// without reseting anything. Directly exposes `AllocBytes::as_mut_ptr`. Only works if
512+
/// without resetting anything. Directly exposes `AllocBytes::as_mut_ptr`. Only works if
501513
/// `OFFSET_IS_ADDR` is true.
502514
pub fn get_bytes_unchecked_raw_mut(&mut self) -> *mut u8 {
503515
assert!(Prov::OFFSET_IS_ADDR);
504516
self.bytes.as_mut_ptr()
505517
}
518+
519+
/// This gives direct immutable access to the entire buffer, just exposing their internal state
520+
/// without resetting anything. Directly exposes `AllocBytes::as_ptr`. Only works if
521+
/// `OFFSET_IS_ADDR` is true.
522+
pub fn get_bytes_unchecked_raw(&self) -> *const u8 {
523+
assert!(Prov::OFFSET_IS_ADDR);
524+
self.bytes.as_ptr()
525+
}
506526
}
507527

508528
/// Reading and writing.

compiler/rustc_mir_build/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ mir_build_deref_raw_pointer_requires_unsafe_unsafe_op_in_unsafe_fn_allowed =
103103
.note = raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
104104
.label = dereference of raw pointer
105105
106-
mir_build_exceeds_mcdc_condition_limit = Number of conditions in decision ({$num_conditions}) exceeds limit ({$max_conditions}). MC/DC analysis will not count this expression.
106+
mir_build_exceeds_mcdc_condition_limit = number of conditions in decision ({$num_conditions}) exceeds limit ({$max_conditions}), so MC/DC analysis will not count this expression
107107
108108
mir_build_extern_static_requires_unsafe =
109109
use of extern static is unsafe and requires unsafe block

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy