@@ -42,7 +42,9 @@ use std::path::{Path, PathBuf};
42
42
use std:: str:: FromStr ;
43
43
use std:: { fmt, io} ;
44
44
45
- use rustc_abi:: { Endian , ExternAbi , Integer , Size , TargetDataLayout , TargetDataLayoutErrors } ;
45
+ use rustc_abi:: {
46
+ Align , Endian , ExternAbi , Integer , Size , TargetDataLayout , TargetDataLayoutErrors ,
47
+ } ;
46
48
use rustc_data_structures:: fx:: { FxHashSet , FxIndexSet } ;
47
49
use rustc_fs_util:: try_canonicalize;
48
50
use rustc_macros:: { Decodable , Encodable , HashStable_Generic } ;
@@ -3599,6 +3601,25 @@ impl Target {
3599
3601
_ => return None ,
3600
3602
} )
3601
3603
}
3604
+
3605
+ /// Returns whether this target is known to have unreliable alignment:
3606
+ /// native C code for the target fails to align some data to the degree
3607
+ /// required by the C standard. We can't *really* do anything about that
3608
+ /// since unsafe Rust code may assume alignment any time, but we can at least
3609
+ /// inhibit some optimizations, and we suppress the alignment checks that
3610
+ /// would detect this unsoundness.
3611
+ ///
3612
+ /// Every target that returns less than `Align::MAX` here is still has a soundness bug.
3613
+ pub fn max_reliable_alignment ( & self ) -> Align {
3614
+ // FIXME(#112480) MSVC on x86-32 is unsound and fails to properly align many types with
3615
+ // more-than-4-byte-alignment on the stack. This makes alignments larger than 4 generally
3616
+ // unreliable on 32bit Windows.
3617
+ if self . is_like_windows && self . arch == "x86" {
3618
+ Align :: from_bytes ( 4 ) . unwrap ( )
3619
+ } else {
3620
+ Align :: MAX
3621
+ }
3622
+ }
3602
3623
}
3603
3624
3604
3625
/// Either a target tuple string or a path to a JSON file.
0 commit comments