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