Reduce the maximum alignment to repr(align(1 << 29))
This brings it into line with LLVM's maximum permitted alignment.
This commit is contained in:
parent
c1607f80b3
commit
cd2f5f7d97
3 changed files with 11 additions and 8 deletions
|
@ -326,9 +326,9 @@ impl AddAssign for Size {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Alignment of a type in bytes, both ABI-mandated and preferred.
|
/// 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
|
/// Each field is a power of two, giving the alignment a maximum value
|
||||||
/// 2<sup>(2<sup>8</sup> - 1)</sup>, which is limited by LLVM to a i32,
|
/// of 2<sup>(2<sup>8</sup> - 1)</sup>, which is limited by LLVM to a
|
||||||
/// with a maximum capacity of 2<sup>31</sup> - 1 or 2147483647.
|
/// maximum capacity of 2<sup>29</sup> or 536870912.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Align {
|
pub struct Align {
|
||||||
abi_pow2: u8,
|
abi_pow2: u8,
|
||||||
|
@ -356,7 +356,7 @@ impl Align {
|
||||||
}
|
}
|
||||||
if bytes != 1 {
|
if bytes != 1 {
|
||||||
Err(format!("`{}` is not a power of 2", align))
|
Err(format!("`{}` is not a power of 2", align))
|
||||||
} else if pow > 30 {
|
} else if pow > 29 {
|
||||||
Err(format!("`{}` is too large", align))
|
Err(format!("`{}` is too large", align))
|
||||||
} else {
|
} else {
|
||||||
Ok(pow)
|
Ok(pow)
|
||||||
|
|
|
@ -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> {
|
let parse_alignment = |node: &ast::LitKind| -> Result<u32, &'static str> {
|
||||||
if let ast::LitKind::Int(literal, ast::LitIntType::Unsuffixed) = node {
|
if let ast::LitKind::Int(literal, ast::LitIntType::Unsuffixed) = node {
|
||||||
if literal.is_power_of_two() {
|
if literal.is_power_of_two() {
|
||||||
// rustc::ty::layout::Align restricts align to <= 2147483647
|
// rustc::ty::layout::Align restricts align to <= 2^29
|
||||||
if *literal <= 2147483647 {
|
if *literal <= 1 << 29 {
|
||||||
Ok(*literal as u32)
|
Ok(*literal as u32)
|
||||||
} else {
|
} else {
|
||||||
Err("larger than 2147483647")
|
Err("larger than 2^29")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err("not a power of two")
|
Err("not a power of two")
|
||||||
|
|
|
@ -15,7 +15,10 @@ struct A(i32);
|
||||||
#[repr(align(15))] //~ ERROR: invalid `repr(align)` attribute: not a power of two
|
#[repr(align(15))] //~ ERROR: invalid `repr(align)` attribute: not a power of two
|
||||||
struct B(i32);
|
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);
|
struct C(i32);
|
||||||
|
|
||||||
|
#[repr(align(536870912))] // ok: this is the largest accepted alignment
|
||||||
|
struct D(i32);
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue