Skip to content

Commit 732253f

Browse files
Rollup merge of rust-lang#142179 - folkertdev:min-global-align-parse, r=workingjubilee
store `target.min_global_align` as an `Align` Parse the alignment properly when the target is defined/parsed, and error out on invalid alignment values. That means this work doesn't need to happen for every global in each backend.
2 parents 620a4f3 + 3f2666c commit 732253f

File tree

3 files changed

+2
-17
lines changed

3 files changed

+2
-17
lines changed

messages.ftl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ codegen_gcc_unknown_ctarget_feature_prefix =
22
unknown feature specified for `-Ctarget-feature`: `{$feature}`
33
.note = features must begin with a `+` to enable or `-` to disable it
44
5-
codegen_gcc_invalid_minimum_alignment =
6-
invalid minimum global alignment: {$err}
7-
85
codegen_gcc_forbidden_ctarget_feature =
96
target feature `{$feature}` cannot be toggled with `-Ctarget-feature`: {$reason}
107

src/consts.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc_span::def_id::DefId;
1818

1919
use crate::base;
2020
use crate::context::CodegenCx;
21-
use crate::errors::InvalidMinimumAlignment;
2221
use crate::type_of::LayoutGccExt;
2322

2423
fn set_global_alignment<'gcc, 'tcx>(
@@ -29,13 +28,8 @@ fn set_global_alignment<'gcc, 'tcx>(
2928
// The target may require greater alignment for globals than the type does.
3029
// Note: GCC and Clang also allow `__attribute__((aligned))` on variables,
3130
// which can force it to be smaller. Rust doesn't support this yet.
32-
if let Some(min) = cx.sess().target.min_global_align {
33-
match Align::from_bits(min) {
34-
Ok(min) => align = align.max(min),
35-
Err(err) => {
36-
cx.sess().dcx().emit_err(InvalidMinimumAlignment { err: err.to_string() });
37-
}
38-
}
31+
if let Some(min_global) = cx.sess().target.min_global_align {
32+
align = Ord::max(align, min_global);
3933
}
4034
gv.set_alignment(align.bytes() as i32);
4135
}

src/errors.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ pub(crate) struct UnwindingInlineAsm {
4747
pub span: Span,
4848
}
4949

50-
#[derive(Diagnostic)]
51-
#[diag(codegen_gcc_invalid_minimum_alignment)]
52-
pub(crate) struct InvalidMinimumAlignment {
53-
pub err: String,
54-
}
55-
5650
#[derive(Diagnostic)]
5751
#[diag(codegen_gcc_copy_bitcode)]
5852
pub(crate) struct CopyBitcode {

0 commit comments

Comments
 (0)