-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-allocatorsArea: Custom and system allocatorsArea: Custom and system allocatorsC-bugCategory: This is a bug.Category: This is a bug.
Description
The following code:
#![feature(allocator_api, alloc_system)]
extern crate alloc_system;
use std::heap::{Alloc, Layout};
use alloc_system::System;
pub fn main() {
unsafe {
let x = System.alloc(Layout::from_size_align(8, 16).unwrap()).unwrap();
let y = System.alloc(Layout::from_size_align(8, 16).unwrap()).unwrap();
println!("{:?} {:?}", (x as usize) % 16, (y as usize) % 16);
}
}
prints 8 0
on my machine and on the playground. That's a bug; since I requested alignment 16 for both pointers, it should only ever print 0 0
.
This is probably caused by the MIN_ALIGN
optimization in alloc_system
. This optimization is currently mostly useless, but it also seems to be wrong. I do not know what the actual alignment guarantees are; maybe the values are wrong or maybe the guarantee only holds for size >= align
.
Metadata
Metadata
Assignees
Labels
A-allocatorsArea: Custom and system allocatorsArea: Custom and system allocatorsC-bugCategory: This is a bug.Category: This is a bug.