]> git.lizzy.rs Git - rust.git/commitdiff
Reduce the maximum alignment to repr(align(1 << 29))
authorvarkor <github@varkor.com>
Tue, 1 May 2018 20:26:23 +0000 (21:26 +0100)
committervarkor <github@varkor.com>
Tue, 1 May 2018 21:02:05 +0000 (22:02 +0100)
This brings it into line with LLVM's maximum permitted alignment.

src/librustc_target/abi/mod.rs
src/libsyntax/attr.rs
src/test/compile-fail/repr-align.rs

index f73085196f4e6f3119a8b6a04705c3261bc6e801..fd1f779f9ecc06168ee635e11907d2b576ed2dda 100644 (file)
@@ -326,9 +326,9 @@ fn add_assign(&mut self, other: Size) {
 }
 
 /// Alignment of a type in bytes, both ABI-mandated and preferred.
-/// Each field is a power of two, giving the alignment a maximum value of
-/// 2<sup>(2<sup>8</sup> - 1)</sup>, which is limited by LLVM to a i32,
-/// with a maximum capacity of 2<sup>31</sup> - 1 or 2147483647.
+/// Each field is a power of two, giving the alignment a maximum value
+/// of 2<sup>(2<sup>8</sup> - 1)</sup>, which is limited by LLVM to a
+/// maximum capacity of 2<sup>29</sup> or 536870912.
 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
 pub struct Align {
     abi_pow2: u8,
@@ -356,7 +356,7 @@ pub fn from_bytes(abi: u64, pref: u64) -> Result<Align, String> {
             }
             if bytes != 1 {
                 Err(format!("`{}` is not a power of 2", align))
-            } else if pow > 30 {
+            } else if pow > 29 {
                 Err(format!("`{}` is too large", align))
             } else {
                 Ok(pow)
index f0557277267a519a5f10d5f2415a549e3e8e608f..13f8bb9a31831afbd3c31e9459dd318247b1bfb9 100644 (file)
@@ -1012,11 +1012,11 @@ pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr>
                     let parse_alignment = |node: &ast::LitKind| -> Result<u32, &'static str> {
                         if let ast::LitKind::Int(literal, ast::LitIntType::Unsuffixed) = node {
                             if literal.is_power_of_two() {
-                                // rustc::ty::layout::Align restricts align to <= 2147483647
-                                if *literal <= 2147483647 {
+                                // rustc::ty::layout::Align restricts align to <= 2^29
+                                if *literal <= 1 << 29 {
                                     Ok(*literal as u32)
                                 } else {
-                                    Err("larger than 2147483647")
+                                    Err("larger than 2^29")
                                 }
                             } else {
                                 Err("not a power of two")
index 7c8eb6a2de93aaf71d26e30076906020769cd9a6..9b0408de2a4fc8628fc4e9e8e78691debeedf08a 100644 (file)
 #[repr(align(15))] //~ ERROR: invalid `repr(align)` attribute: not a power of two
 struct B(i32);
 
-#[repr(align(4294967296))] //~ ERROR: invalid `repr(align)` attribute: larger than 2147483647
+#[repr(align(4294967296))] //~ ERROR: invalid `repr(align)` attribute: larger than 2^29
 struct C(i32);
 
+#[repr(align(536870912))] // ok: this is the largest accepted alignment
+struct D(i32);
+
 fn main() {}