@@ -36,13 +36,18 @@ use rustc_session::lint::builtin::{
36
36
} ;
37
37
use rustc_session:: parse:: feature_err;
38
38
use rustc_span:: { BytePos , DUMMY_SP , Span , Symbol , edition, sym} ;
39
+ use rustc_target:: spec:: BinaryFormat ;
39
40
use rustc_trait_selection:: error_reporting:: InferCtxtErrorExt ;
40
41
use rustc_trait_selection:: infer:: { TyCtxtInferExt , ValuePairs } ;
41
42
use rustc_trait_selection:: traits:: ObligationCtxt ;
42
43
use tracing:: debug;
43
44
44
45
use crate :: { errors, fluent_generated as fluent} ;
45
46
47
+ // Max alignment supported for PE-COFF binary format.
48
+ // See https://learn.microsoft.com/en-us/cpp/cpp/align-cpp?view=msvc-170
49
+ const COFF_MAX_ALIGN_BYTES : usize = 0x2000 ;
50
+
46
51
#[ derive( LintDiagnostic ) ]
47
52
#[ diag( passes_diagnostic_diagnostic_on_unimplemented_only_for_traits) ]
48
53
struct DiagnosticOnUnimplementedOnlyForTraits ;
@@ -2132,6 +2137,12 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
2132
2137
}
2133
2138
2134
2139
fn check_align_value ( & self , align : Align , span : Span ) {
2140
+ if self . tcx . sess . target . binary_format == BinaryFormat :: Coff {
2141
+ if align. bytes ( ) > COFF_MAX_ALIGN_BYTES {
2142
+ self . dcx ( ) . emit_err ( errors:: InvalidReprAlignForCoff { span } ) ;
2143
+ }
2144
+ }
2145
+
2135
2146
if align. bytes ( ) > 2_u64 . pow ( 29 ) {
2136
2147
// for values greater than 2^29, a different error will be emitted, make sure that happens
2137
2148
self . dcx ( ) . span_delayed_bug (
0 commit comments