From 9fb4f4f76ce33ca3b749a29ebdddc50cd11d04aa Mon Sep 17 00:00:00 2001 From: Swapna Iyer Date: Fri, 12 Jan 2024 20:06:58 -0800 Subject: [PATCH] Use Translatable Diagnostic --- compiler/rustc_codegen_ssa/messages.ftl | 2 ++ compiler/rustc_codegen_ssa/src/errors.rs | 6 ++++++ compiler/rustc_codegen_ssa/src/mir/mod.rs | 8 +++----- tests/ui/codegen/issue-83060-large-stack-size.rs | 2 +- tests/ui/codegen/issue-83060-large-stack-size.stderr | 4 ++-- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_codegen_ssa/messages.ftl b/compiler/rustc_codegen_ssa/messages.ftl index 5881c6236ece6..586aa313ccdad 100644 --- a/compiler/rustc_codegen_ssa/messages.ftl +++ b/compiler/rustc_codegen_ssa/messages.ftl @@ -22,6 +22,8 @@ codegen_ssa_copy_path_buf = unable to copy {$source_file} to {$output_path}: {$e codegen_ssa_create_temp_dir = couldn't create a temp dir: {$error} +codegen_ssa_dangerous_stack_allocation = Dangerous stack allocation of size: {$output} exceeds most architecture limits + codegen_ssa_error_creating_remark_dir = failed to create remark directory: {$error} codegen_ssa_expected_coverage_symbol = expected `coverage(off)` or `coverage(on)` diff --git a/compiler/rustc_codegen_ssa/src/errors.rs b/compiler/rustc_codegen_ssa/src/errors.rs index f90e1906caf0a..9e617bea476b0 100644 --- a/compiler/rustc_codegen_ssa/src/errors.rs +++ b/compiler/rustc_codegen_ssa/src/errors.rs @@ -413,6 +413,12 @@ pub struct CheckInstalledVisualStudio; #[diag(codegen_ssa_insufficient_vs_code_product)] pub struct InsufficientVSCodeProduct; +#[derive(Diagnostic)] +#[diag(codegen_ssa_dangerous_stack_allocation)] +pub struct DangerousStackAllocation { + pub output: String, +} + #[derive(Diagnostic)] #[diag(codegen_ssa_processing_dymutil_failed)] #[note] diff --git a/compiler/rustc_codegen_ssa/src/mir/mod.rs b/compiler/rustc_codegen_ssa/src/mir/mod.rs index 4e346e2b97c26..79378f7bea7db 100644 --- a/compiler/rustc_codegen_ssa/src/mir/mod.rs +++ b/compiler/rustc_codegen_ssa/src/mir/mod.rs @@ -1,4 +1,5 @@ use crate::base; +use crate::errors; use crate::traits::*; use rustc_index::bit_set::BitSet; use rustc_index::IndexVec; @@ -231,12 +232,9 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( if layout.size.bytes() >= MIN_DANGEROUS_SIZE { let size_str = || { let (size_quantity, size_unit) = human_readable_bytes(layout.size.bytes()); - format!( - "Dangerous stack allocation of size: {:.2} {} exceeds limits on most architectures", - size_quantity, size_unit - ) + format!("{:.2} {}", size_quantity, size_unit) }; - cx.tcx().dcx().fatal(size_str()); + cx.tcx().dcx().emit_warn(errors::DangerousStackAllocation { output: size_str() }); } if local == mir::RETURN_PLACE && fx.fn_abi.ret.is_indirect() { diff --git a/tests/ui/codegen/issue-83060-large-stack-size.rs b/tests/ui/codegen/issue-83060-large-stack-size.rs index c5e7ba1942e6d..304f436e366f7 100644 --- a/tests/ui/codegen/issue-83060-large-stack-size.rs +++ b/tests/ui/codegen/issue-83060-large-stack-size.rs @@ -1,4 +1,4 @@ -// build-fail +// build-pass fn func() { const CAP: usize = std::u32::MAX as usize; let mut x: [u8; CAP>>1] = [0; CAP>>1]; diff --git a/tests/ui/codegen/issue-83060-large-stack-size.stderr b/tests/ui/codegen/issue-83060-large-stack-size.stderr index 312a90a4914d1..287ccd9a9b7a8 100644 --- a/tests/ui/codegen/issue-83060-large-stack-size.stderr +++ b/tests/ui/codegen/issue-83060-large-stack-size.stderr @@ -1,4 +1,4 @@ -error: Dangerous stack allocation of size: 1 GiB exceeds limits on most architectures +warning: Dangerous stack allocation of size: 1 GiB exceeds most architecture limits -error: aborting due to 1 previous error +warning: 1 warning emitted