From a10213f297be8e231f55fd6db843674a8f512140 Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Thu, 6 Jul 2017 18:00:46 -0400 Subject: Raised alignment limit from 2^15 to 2^31 --- src/libsyntax/attr.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index f0fc849c0c5..45c106f2a7f 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -974,11 +974,11 @@ pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec let mut align_error = None; if let ast::LitKind::Int(align, ast::LitIntType::Unsuffixed) = value.node { if align.is_power_of_two() { - // rustc::ty::layout::Align restricts align to <= 32768 - if align <= 32768 { - acc.push(ReprAlign(align as u16)); + // rustc::ty::layout::Align restricts align to <= 2147483648 + if align <= 2147483648 { + acc.push(ReprAlign(align as u32)); } else { - align_error = Some("larger than 32768"); + align_error = Some("larger than 2147483648"); } } else { align_error = Some("not a power of two"); @@ -1027,7 +1027,7 @@ pub enum ReprAttr { ReprExtern, ReprPacked, ReprSimd, - ReprAlign(u16), + ReprAlign(u32), } #[derive(Eq, Hash, PartialEq, Debug, RustcEncodable, RustcDecodable, Copy, Clone)] -- cgit 1.4.1-3-g733a5 From afed75a2d9b7e049dc26be7af3cb72297274d343 Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Sat, 8 Jul 2017 10:28:20 -0400 Subject: Lower alignment limit down to 2^31 - 1 (from LLVM) --- src/librustc/ty/layout.rs | 10 ++++++---- src/libsyntax/attr.rs | 6 +++--- src/test/compile-fail/repr-align.rs | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src/libsyntax') diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 90468d92a50..6fb26f0dd6d 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -285,7 +285,9 @@ impl Size { } /// Alignment of a type in bytes, both ABI-mandated and preferred. -/// Each field is a power of two. +/// Each field is a power of two, giving the alignment a maximum +/// value of 2^(2^8 - 1), which is limited by LLVM to a i32, with +/// a maximum capacity of 2^31 - 1 or 2147483647. #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub struct Align { abi: u8, @@ -298,7 +300,7 @@ impl Align { } pub fn from_bytes(abi: u64, pref: u64) -> Result { - let pack = |align: u64| { + let log2 = |align: u64| { // Treat an alignment of 0 bytes like 1-byte alignment. if align == 0 { return Ok(0); @@ -318,8 +320,8 @@ impl Align { }; Ok(Align { - abi: pack(abi)?, - pref: pack(pref)?, + abi: log2(abi)?, + pref: log2(pref)?, }) } diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 45c106f2a7f..a247fe7f8a5 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -974,11 +974,11 @@ pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec let mut align_error = None; if let ast::LitKind::Int(align, ast::LitIntType::Unsuffixed) = value.node { if align.is_power_of_two() { - // rustc::ty::layout::Align restricts align to <= 2147483648 - if align <= 2147483648 { + // rustc::ty::layout::Align restricts align to <= 2147483647 + if align <= 2147483647 { acc.push(ReprAlign(align as u32)); } else { - align_error = Some("larger than 2147483648"); + align_error = Some("larger than 2147483647"); } } else { align_error = Some("not a power of two"); diff --git a/src/test/compile-fail/repr-align.rs b/src/test/compile-fail/repr-align.rs index 433abe943f5..bc9cf065e5a 100644 --- a/src/test/compile-fail/repr-align.rs +++ b/src/test/compile-fail/repr-align.rs @@ -17,7 +17,7 @@ struct A(i32); #[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 2147483648 +#[repr(align(4294967296))] //~ ERROR: invalid `repr(align)` attribute: larger than 2147483647 struct C(i32); fn main() {} -- cgit 1.4.1-3-g733a5