Skip to content

Commit afed75a

Browse files
committed
Lower alignment limit down to 2^31 - 1 (from LLVM)
1 parent a10213f commit afed75a

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/librustc/ty/layout.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ impl Size {
285285
}
286286

287287
/// Alignment of a type in bytes, both ABI-mandated and preferred.
288-
/// Each field is a power of two.
288+
/// Each field is a power of two, giving the alignment a maximum
289+
/// value of 2^(2^8 - 1), which is limited by LLVM to a i32, with
290+
/// a maximum capacity of 2^31 - 1 or 2147483647.
289291
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
290292
pub struct Align {
291293
abi: u8,
@@ -298,7 +300,7 @@ impl Align {
298300
}
299301

300302
pub fn from_bytes(abi: u64, pref: u64) -> Result<Align, String> {
301-
let pack = |align: u64| {
303+
let log2 = |align: u64| {
302304
// Treat an alignment of 0 bytes like 1-byte alignment.
303305
if align == 0 {
304306
return Ok(0);
@@ -318,8 +320,8 @@ impl Align {
318320
};
319321

320322
Ok(Align {
321-
abi: pack(abi)?,
322-
pref: pack(pref)?,
323+
abi: log2(abi)?,
324+
pref: log2(pref)?,
323325
})
324326
}
325327

src/libsyntax/attr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -974,11 +974,11 @@ pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr>
974974
let mut align_error = None;
975975
if let ast::LitKind::Int(align, ast::LitIntType::Unsuffixed) = value.node {
976976
if align.is_power_of_two() {
977-
// rustc::ty::layout::Align restricts align to <= 2147483648
978-
if align <= 2147483648 {
977+
// rustc::ty::layout::Align restricts align to <= 2147483647
978+
if align <= 2147483647 {
979979
acc.push(ReprAlign(align as u32));
980980
} else {
981-
align_error = Some("larger than 2147483648");
981+
align_error = Some("larger than 2147483647");
982982
}
983983
} else {
984984
align_error = Some("not a power of two");

src/test/compile-fail/repr-align.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct A(i32);
1717
#[repr(align(15))] //~ ERROR: invalid `repr(align)` attribute: not a power of two
1818
struct B(i32);
1919

20-
#[repr(align(4294967296))] //~ ERROR: invalid `repr(align)` attribute: larger than 2147483648
20+
#[repr(align(4294967296))] //~ ERROR: invalid `repr(align)` attribute: larger than 2147483647
2121
struct C(i32);
2222

2323
fn main() {}

0 commit comments

Comments
 (0)