Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,16 @@ hir_analysis_cannot_capture_late_bound_ty =
hir_analysis_closure_implicit_hrtb = implicit types in closure signatures are forbidden when `for<...>` is present
.label = `for<...>` is here

hir_analysis_cmse_call_generic =
function pointers with the `"cmse-nonsecure-call"` ABI cannot contain generics in their type
hir_analysis_cmse_generic =
generics are not allowed in `extern {$abi}` signatures

hir_analysis_cmse_entry_generic =
functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
hir_analysis_cmse_impl_trait =
`impl Trait` is not allowed in `extern {$abi}` signatures

hir_analysis_cmse_inputs_stack_spill =
arguments for `{$abi}` function too large to pass via registers
.label = {$plural ->
[false] this argument doesn't
*[true] these arguments don't
} fit in the available registers
.note = functions with the `{$abi}` ABI must pass all their arguments via the 4 32-bit available argument registers
.label = does not fit in the available registers
.note = functions with the `{$abi}` ABI must pass all their arguments via the 4 32-bit argument registers

hir_analysis_cmse_output_stack_spill =
return value of `{$abi}` function too large to pass via registers
Expand Down
17 changes: 9 additions & 8 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1616,8 +1616,7 @@ pub(crate) struct InvalidGenericReceiverTy<'tcx> {
pub(crate) struct CmseInputsStackSpill {
#[primary_span]
#[label]
pub span: Span,
pub plural: bool,
pub spans: Vec<Span>,
pub abi: ExternAbi,
}

Expand All @@ -1633,22 +1632,24 @@ pub(crate) struct CmseOutputStackSpill {
}

#[derive(Diagnostic)]
#[diag(hir_analysis_cmse_call_generic, code = E0798)]
pub(crate) struct CmseCallGeneric {
#[diag(hir_analysis_cmse_generic, code = E0798)]
pub(crate) struct CmseGeneric {
#[primary_span]
pub span: Span,
pub abi: ExternAbi,
}

#[derive(Diagnostic)]
#[diag(hir_analysis_bad_return_type_notation_position)]
pub(crate) struct BadReturnTypeNotation {
#[diag(hir_analysis_cmse_impl_trait, code = E0798)]
pub(crate) struct CmseImplTrait {
#[primary_span]
pub span: Span,
pub abi: ExternAbi,
}

#[derive(Diagnostic)]
#[diag(hir_analysis_cmse_entry_generic, code = E0798)]
pub(crate) struct CmseEntryGeneric {
#[diag(hir_analysis_bad_return_type_notation_position)]
pub(crate) struct BadReturnTypeNotation {
#[primary_span]
pub span: Span,
}
Expand Down
138 changes: 50 additions & 88 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use rustc_hir::{self as hir, HirId};
use rustc_middle::bug;
use rustc_middle::ty::layout::{LayoutError, TyAndLayout};
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
use rustc_span::Span;

use crate::errors;

Expand All @@ -17,15 +18,10 @@ pub(crate) fn validate_cmse_abi<'tcx>(
abi: ExternAbi,
fn_sig: ty::PolyFnSig<'tcx>,
) {
match abi {
ExternAbi::CmseNonSecureCall => {
let hir_node = tcx.hir_node(hir_id);
let hir::Node::Ty(hir::Ty {
span: fn_ptr_span,
kind: hir::TyKind::FnPtr(fn_ptr_ty),
..
}) = hir_node
else {
let fn_decl = match abi {
ExternAbi::CmseNonSecureCall => match tcx.hir_node(hir_id) {
hir::Node::Ty(hir::Ty { kind: hir::TyKind::FnPtr(fn_ptr_ty), .. }) => fn_ptr_ty.decl,
_ => {
let span = match tcx.parent_hir_node(hir_id) {
hir::Node::Item(hir::Item {
kind: hir::ItemKind::ForeignMod { .. },
Expand All @@ -42,45 +38,10 @@ pub(crate) fn validate_cmse_abi<'tcx>(
)
.emit();
return;
};

match is_valid_cmse_inputs(tcx, fn_sig) {
Ok(Ok(())) => {}
Ok(Err(index)) => {
// fn(x: u32, u32, u32, u16, y: u16) -> u32,
// ^^^^^^
let span = if let Some(ident) = fn_ptr_ty.param_idents[index] {
ident.span.to(fn_ptr_ty.decl.inputs[index].span)
} else {
fn_ptr_ty.decl.inputs[index].span
}
.to(fn_ptr_ty.decl.inputs.last().unwrap().span);
let plural = fn_ptr_ty.param_idents.len() - index != 1;
dcx.emit_err(errors::CmseInputsStackSpill { span, plural, abi });
}
Err(layout_err) => {
if should_emit_generic_error(abi, layout_err) {
dcx.emit_err(errors::CmseCallGeneric { span: *fn_ptr_span });
}
}
}

match is_valid_cmse_output(tcx, fn_sig) {
Ok(true) => {}
Ok(false) => {
let span = fn_ptr_ty.decl.output.span();
dcx.emit_err(errors::CmseOutputStackSpill { span, abi });
}
Err(layout_err) => {
if should_emit_generic_error(abi, layout_err) {
dcx.emit_err(errors::CmseCallGeneric { span: *fn_ptr_span });
}
}
};
}
},
ExternAbi::CmseNonSecureEntry => {
let hir_node = tcx.hir_node(hir_id);
let Some(hir::FnSig { decl, span: fn_sig_span, .. }) = hir_node.fn_sig() else {
let Some(hir::FnSig { decl, .. }) = tcx.hir_node(hir_id).fn_sig() else {
// might happen when this ABI is used incorrectly. That will be handled elsewhere
return;
};
Expand All @@ -91,53 +52,43 @@ pub(crate) fn validate_cmse_abi<'tcx>(
return;
}

match is_valid_cmse_inputs(tcx, fn_sig) {
Ok(Ok(())) => {}
Ok(Err(index)) => {
// fn f(x: u32, y: u32, z: u32, w: u16, q: u16) -> u32,
// ^^^^^^
let span = decl.inputs[index].span.to(decl.inputs.last().unwrap().span);
let plural = decl.inputs.len() - index != 1;
dcx.emit_err(errors::CmseInputsStackSpill { span, plural, abi });
}
Err(layout_err) => {
if should_emit_generic_error(abi, layout_err) {
dcx.emit_err(errors::CmseEntryGeneric { span: *fn_sig_span });
}
}
}
decl
}
_ => return,
};

match is_valid_cmse_output(tcx, fn_sig) {
Ok(true) => {}
Ok(false) => {
let span = decl.output.span();
dcx.emit_err(errors::CmseOutputStackSpill { span, abi });
}
Err(layout_err) => {
if should_emit_generic_error(abi, layout_err) {
dcx.emit_err(errors::CmseEntryGeneric { span: *fn_sig_span });
}
}
};
if let Err((span, layout_err)) = is_valid_cmse_inputs(tcx, dcx, fn_sig, fn_decl, abi) {
if should_emit_layout_error(abi, layout_err) {
dcx.emit_err(errors::CmseGeneric { span, abi });
}
}

if let Err(layout_err) = is_valid_cmse_output(tcx, dcx, fn_sig, fn_decl, abi) {
if should_emit_layout_error(abi, layout_err) {
dcx.emit_err(errors::CmseGeneric { span: fn_decl.output.span(), abi });
}
_ => (),
}
}

/// Returns whether the inputs will fit into the available registers
fn is_valid_cmse_inputs<'tcx>(
tcx: TyCtxt<'tcx>,
dcx: DiagCtxtHandle<'_>,
fn_sig: ty::PolyFnSig<'tcx>,
) -> Result<Result<(), usize>, &'tcx LayoutError<'tcx>> {
let mut span = None;
fn_decl: &hir::FnDecl<'tcx>,
abi: ExternAbi,
) -> Result<(), (Span, &'tcx LayoutError<'tcx>)> {
let mut accum = 0u64;
let mut excess_argument_spans = Vec::new();

// this type is only used for layout computation, which does not rely on regions
let fn_sig = tcx.instantiate_bound_regions_with_erased(fn_sig);
let fn_sig = tcx.erase_and_anonymize_regions(fn_sig);

for (index, ty) in fn_sig.inputs().iter().enumerate() {
let layout = tcx.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(*ty))?;
for (ty, hir_ty) in fn_sig.inputs().iter().zip(fn_decl.inputs) {
let layout = tcx
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(*ty))
.map_err(|e| (hir_ty.span, e))?;

let align = layout.layout.align().bytes();
let size = layout.layout.size().bytes();
Expand All @@ -147,21 +98,27 @@ fn is_valid_cmse_inputs<'tcx>(

// i.e. exceeds 4 32-bit registers
if accum > 16 {
span = span.or(Some(index));
excess_argument_spans.push(hir_ty.span);
}
}

match span {
None => Ok(Ok(())),
Some(span) => Ok(Err(span)),
if !excess_argument_spans.is_empty() {
// fn f(x: u32, y: u32, z: u32, w: u16, q: u16) -> u32,
// ^^^^^^
dcx.emit_err(errors::CmseInputsStackSpill { spans: excess_argument_spans, abi });
}

Ok(())
}

/// Returns whether the output will fit into the available registers
fn is_valid_cmse_output<'tcx>(
tcx: TyCtxt<'tcx>,
dcx: DiagCtxtHandle<'_>,
fn_sig: ty::PolyFnSig<'tcx>,
) -> Result<bool, &'tcx LayoutError<'tcx>> {
fn_decl: &hir::FnDecl<'tcx>,
abi: ExternAbi,
) -> Result<(), &'tcx LayoutError<'tcx>> {
// this type is only used for layout computation, which does not rely on regions
let fn_sig = tcx.instantiate_bound_regions_with_erased(fn_sig);
let fn_sig = tcx.erase_and_anonymize_regions(fn_sig);
Expand All @@ -176,14 +133,19 @@ fn is_valid_cmse_output<'tcx>(
// `#[no_mangle]` or similar, so generics in the type really don't make sense.
//
// see also https://github.com/rust-lang/rust/issues/147242.
if return_type.has_opaque_types() {
return Err(tcx.arena.alloc(LayoutError::TooGeneric(return_type)));
if abi == ExternAbi::CmseNonSecureEntry && return_type.has_opaque_types() {
dcx.emit_err(errors::CmseImplTrait { span: fn_decl.output.span(), abi });
return Ok(());
}

let typing_env = ty::TypingEnv::fully_monomorphized();
let layout = tcx.layout_of(typing_env.as_query_input(return_type))?;

Ok(is_valid_cmse_output_layout(layout))
if !is_valid_cmse_output_layout(layout) {
dcx.emit_err(errors::CmseOutputStackSpill { span: fn_decl.output.span(), abi });
}

Ok(())
}

/// Returns whether the output will fit into the available registers
Expand All @@ -208,15 +170,15 @@ fn is_valid_cmse_output_layout<'tcx>(layout: TyAndLayout<'tcx>) -> bool {
matches!(value, Primitive::Int(Integer::I64, _) | Primitive::Float(Float::F64))
}

fn should_emit_generic_error<'tcx>(abi: ExternAbi, layout_err: &'tcx LayoutError<'tcx>) -> bool {
fn should_emit_layout_error<'tcx>(abi: ExternAbi, layout_err: &'tcx LayoutError<'tcx>) -> bool {
use LayoutError::*;

match layout_err {
TooGeneric(ty) => {
match abi {
ExternAbi::CmseNonSecureCall => {
// prevent double reporting of this error
!ty.is_impl_trait()
!ty.has_opaque_types()
}
ExternAbi::CmseNonSecureEntry => true,
_ => bug!("invalid ABI: {abi}"),
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_target/src/spec/base/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl OSVersion {
/// to raise the minimum OS version.
///
/// This matches what LLVM does, see in part:
/// <https://github.com/llvm/llvm-project/blob/llvmorg-18.1.8/llvm/lib/TargetParser/Triple.cpp#L1900-L1932>
/// <https://github.com/llvm/llvm-project/blob/llvmorg-21.1.3/llvm/lib/TargetParser/Triple.cpp#L2140-L2175>
pub fn minimum_deployment_target(target: &Target) -> Self {
let (major, minor, patch) = match (&*target.os, &*target.arch, &*target.env) {
("macos", "aarch64", _) => (11, 0, 0),
Expand All @@ -315,6 +315,9 @@ impl OSVersion {
("ios", _, "macabi") => (13, 1, 0),
("tvos", "aarch64", "sim") => (14, 0, 0),
("watchos", "aarch64", "sim") => (7, 0, 0),
// True Aarch64 on watchOS (instead of their Aarch64 Ilp32 called `arm64_32`) has been
// available since Xcode 14, but it's only actually used more recently in watchOS 26.
("watchos", "aarch64", "") if !target.llvm_target.starts_with("arm64_32") => (26, 0, 0),
(os, _, _) => return Self::os_minimum_deployment_target(os),
};
Self { major, minor, patch }
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rustc-perf
Submodule rustc-perf updated 85 files
+3 −3 .github/workflows/ci.yml
+2 −2 Cargo.lock
+3 −0 Cargo.toml
+3 −3 collector/Cargo.toml
+1 −1 collector/benchlib/src/benchmark.rs
+6 −16 collector/src/benchmark_set/mod.rs
+556 −67 collector/src/bin/collector.rs
+16 −10 collector/src/bin/rustc-fake.rs
+2 −2 collector/src/codegen.rs
+9 −0 collector/src/compile/benchmark/codegen_backend.rs
+7 −6 collector/src/compile/benchmark/mod.rs
+19 −6 collector/src/compile/benchmark/profile.rs
+26 −0 collector/src/compile/benchmark/target.rs
+3 −3 collector/src/compile/execute/bencher.rs
+2 −2 collector/src/compile/execute/etw_parser.rs
+4 −9 collector/src/compile/execute/mod.rs
+10 −9 collector/src/compile/execute/profiler.rs
+34 −37 collector/src/compile/execute/rustc.rs
+77 −40 collector/src/lib.rs
+6 −13 collector/src/runtime/mod.rs
+235 −110 collector/src/toolchain.rs
+1 −1 collector/src/utils/cachegrind.rs
+4 −5 collector/src/utils/fs.rs
+5 −4 collector/src/utils/read2.rs
+47 −7 database/schema.md
+2 −2 database/src/bin/import-sqlite.rs
+2 −2 database/src/bin/postgres-to-sqlite.rs
+14 −14 database/src/bin/sqlite-to-postgres.rs
+228 −47 database/src/lib.rs
+652 −79 database/src/pool.rs
+822 −133 database/src/pool/postgres.rs
+137 −23 database/src/pool/sqlite.rs
+5 −5 database/src/selector.rs
+155 −0 database/src/tests/builder.rs
+81 −8 database/src/tests/mod.rs
+0 −3 docker-compose.yml
+4 −0 site/frontend/package.json
+1 −3 site/frontend/src/pages/compare/artifact-size/artifact-size-table.vue
+24 −1 site/frontend/src/pages/compare/compile/common.ts
+12 −0 site/frontend/src/pages/compare/compile/compile-page.vue
+20 −0 site/frontend/src/pages/compare/compile/filters.vue
+5 −1 site/frontend/src/pages/compare/compile/table/comparisons-table.vue
+2 −1 site/frontend/src/pages/compare/compile/table/shortcuts/binary-size-shortcut.vue
+2 −1 site/frontend/src/pages/compare/compile/table/shortcuts/cachegrind-cmd.vue
+10 −0 site/frontend/src/pages/compare/shared.ts
+3 −3 site/frontend/src/pages/detailed-query/utils.ts
+8 −22 site/frontend/src/pages/status/page.vue
+8 −0 site/frontend/src/pages/status_new.ts
+323 −0 site/frontend/src/pages/status_new/collector.vue
+44 −0 site/frontend/src/pages/status_new/data.ts
+334 −0 site/frontend/src/pages/status_new/page.vue
+1 −0 site/frontend/src/urls.ts
+37 −0 site/frontend/src/utils/formatting.ts
+16 −0 site/frontend/src/utils/getType.ts
+10 −0 site/frontend/templates/pages/status_new.html
+86 −0 site/src/api.rs
+1 −4 site/src/benchmark_metadata/mod.rs
+18 −29 site/src/comparison.rs
+33 −29 site/src/github.rs
+2 −2 site/src/github/client.rs
+1 −1 site/src/github/comparison_summary.rs
+366 −168 site/src/job_queue/mod.rs
+6 −2 site/src/load.rs
+10 −6 site/src/main.rs
+2 −0 site/src/request_handlers.rs
+1 −1 site/src/request_handlers/bootstrap.rs
+46 −42 site/src/request_handlers/github.rs
+1 −1 site/src/request_handlers/next_artifact.rs
+9 −9 site/src/request_handlers/self_profile.rs
+253 −0 site/src/request_handlers/status_page_new.rs
+1 −1 site/src/selector.rs
+2 −2 site/src/self_profile.rs
+1 −1 site/src/self_profile/crox.rs
+1 −1 site/src/self_profile/flamegraph.rs
+26 −10 site/src/server.rs
+218 −0 triage/2025/2025-08-04.md
+193 −0 triage/2025/2025-08-12.md
+171 −0 triage/2025/2025-08-18.md
+183 −0 triage/2025/2025-08-25.md
+152 −0 triage/2025/2025-09-02.md
+136 −0 triage/2025/2025-09-07.md
+125 −0 triage/2025/2025-09-15.md
+138 −0 triage/2025/2025-09-23.md
+165 −0 triage/2025/2025-09-28.md
+208 −0 triage/2025/2025-10-06.md
2 changes: 1 addition & 1 deletion tests/assembly-llvm/x86_64-bigint-helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub unsafe extern "sysv64" fn bigint_chain_borrowing_sub(
n: usize,
mut carry: bool,
) -> bool {
// CHECK: mov [[TEMP:r..]], qword ptr [rsi + 8*[[IND:r..]] + 8]
// CHECK: mov [[TEMP:r.+]], qword ptr [rsi + 8*[[IND:r.+]] + 8]
// CHECK: sbb [[TEMP]], qword ptr [rdx + 8*[[IND]] + 8]
// CHECK: mov qword ptr [rdi + 8*[[IND]] + 8], [[TEMP]]
// CHECK: mov [[TEMP]], qword ptr [rsi + 8*[[IND]] + 16]
Expand Down
1 change: 1 addition & 0 deletions tests/run-make/apple-deployment-target/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fn main() {
// armv7s-apple-ios and i386-apple-ios only supports iOS 10.0
"ios" if target() == "armv7s-apple-ios" || target() == "i386-apple-ios" => ("10.0", "10.0"),
"ios" => ("15.0", "16.0"),
"watchos" if target() == "aarch64-apple-watchos" => ("28.0", "30.0"),
"watchos" => ("7.0", "9.0"),
"tvos" => ("14.0", "15.0"),
"visionos" => ("1.1", "1.2"),
Expand Down
7 changes: 5 additions & 2 deletions tests/ui/cmse-nonsecure/cmse-nonsecure-call/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ struct Test<T: Copy> {
f2: extern "cmse-nonsecure-call" fn(impl Copy, u32, u32, u32) -> impl Copy,
//~^ ERROR `impl Trait` is not allowed in `fn` pointer parameters
//~| ERROR `impl Trait` is not allowed in `fn` pointer return types
f3: extern "cmse-nonsecure-call" fn(T, u32, u32, u32) -> u64, //~ ERROR [E0798]
f4: extern "cmse-nonsecure-call" fn(Wrapper<T>, u32, u32, u32) -> u64, //~ ERROR [E0798]
f3: extern "cmse-nonsecure-call" fn((impl Copy, u32), u32, u32, u32) -> (impl Copy, u32),
//~^ ERROR `impl Trait` is not allowed in `fn` pointer parameters
//~| ERROR `impl Trait` is not allowed in `fn` pointer return types
f4: extern "cmse-nonsecure-call" fn(T, u32, u32, u32) -> u64, //~ ERROR [E0798]
f5: extern "cmse-nonsecure-call" fn(Wrapper<T>, u32, u32, u32) -> u64, //~ ERROR [E0798]
}

type WithReference = extern "cmse-nonsecure-call" fn(&usize);
Expand Down
Loading
Loading