Skip to content

Commit

Permalink
Use Translatable Diagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
iSwapna committed Jan 13, 2024
1 parent eab5d6d commit 9fb4f4f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_ssa/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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)`
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_codegen_ssa/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_codegen_ssa/src/mir/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::base;
use crate::errors;
use crate::traits::*;
use rustc_index::bit_set::BitSet;
use rustc_index::IndexVec;
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/codegen/issue-83060-large-stack-size.rs
Original file line number Diff line number Diff line change
@@ -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];
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/codegen/issue-83060-large-stack-size.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9fb4f4f

Please sign in to comment.