@@ -34,6 +34,7 @@ use rustc_session::lint::builtin::{
34
34
use rustc_session:: parse:: feature_err;
35
35
use rustc_span:: symbol:: { Symbol , kw, sym} ;
36
36
use rustc_span:: { BytePos , DUMMY_SP , Span } ;
37
+ use rustc_target:: abi:: Size ;
37
38
use rustc_target:: spec:: abi:: Abi ;
38
39
use rustc_trait_selection:: error_reporting:: InferCtxtErrorExt ;
39
40
use rustc_trait_selection:: infer:: { TyCtxtInferExt , ValuePairs } ;
@@ -1785,7 +1786,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1785
1786
| Target :: Union
1786
1787
| Target :: Enum
1787
1788
| Target :: Fn
1788
- | Target :: Method ( _) => continue ,
1789
+ | Target :: Method ( _) => { }
1789
1790
_ => {
1790
1791
self . dcx ( ) . emit_err (
1791
1792
errors:: AttrApplication :: StructEnumFunctionMethodUnion {
@@ -1795,6 +1796,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1795
1796
) ;
1796
1797
}
1797
1798
}
1799
+
1800
+ self . check_align_value ( hint) ;
1798
1801
}
1799
1802
sym:: packed => {
1800
1803
if target != Target :: Struct && target != Target :: Union {
@@ -1892,6 +1895,45 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1892
1895
}
1893
1896
}
1894
1897
1898
+ fn check_align_value ( & self , item : & MetaItemInner ) {
1899
+ match item. singleton_lit_list ( ) {
1900
+ Some ( (
1901
+ _,
1902
+ MetaItemLit {
1903
+ kind : ast:: LitKind :: Int ( literal, ast:: LitIntType :: Unsuffixed ) , ..
1904
+ } ,
1905
+ ) ) => {
1906
+ let val = literal. get ( ) as u64 ;
1907
+ if val > 2_u64 . pow ( 29 ) {
1908
+ // for values greater than 2^29, a different error will be emitted, make sure that happens
1909
+ self . dcx ( ) . span_delayed_bug (
1910
+ item. span ( ) ,
1911
+ "alignment greater than 2^29 should be errored on elsewhere" ,
1912
+ ) ;
1913
+ } else {
1914
+ // only do this check when <= 2^29 to prevent duplicate errors:
1915
+ // alignment greater than 2^29 not supported
1916
+ // alignment is too large for the current target
1917
+
1918
+ let max =
1919
+ Size :: from_bits ( self . tcx . sess . target . pointer_width ) . signed_int_max ( ) as u64 ;
1920
+ if val > max {
1921
+ self . dcx ( ) . emit_err ( errors:: InvalidReprAlignForTarget {
1922
+ span : item. span ( ) ,
1923
+ size : max,
1924
+ } ) ;
1925
+ }
1926
+ }
1927
+ }
1928
+
1929
+ // if the attribute is malformed, singleton_lit_list may not be of the expected type or may be None
1930
+ // but an error will have already been emitted, so this code should just skip such attributes
1931
+ Some ( ( _, _) ) | None => {
1932
+ self . dcx ( ) . span_delayed_bug ( item. span ( ) , "malformed repr(align(N))" ) ;
1933
+ }
1934
+ }
1935
+ }
1936
+
1895
1937
fn check_used ( & self , attrs : & [ Attribute ] , target : Target , target_span : Span ) {
1896
1938
let mut used_linker_span = None ;
1897
1939
let mut used_compiler_span = None ;
0 commit comments