-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug Report: Incorrect Optimization on Global.allocate{_zeroed}
+core::mem::forget
Loop
#119
Comments
This is an allowed optimization for However if you call your allocator directly without going through |
The docs here state: https://doc.rust-lang.org/beta/std/alloc/trait.GlobalAlloc.html#safety
I think removing unnecessary heap allocations is an important enough optimization to put these kind of restrictions on |
Thanks for your explanation! But when I define the |
Thanks for your advice! I will try the |
However, I am still confused by the optimizer behavior. When I mark my allocator with |
Recently, I tried to write a unit-test about memory allocation & deallocation for my embedded system, with usage of
Global.allocate_zeroed
(in factGlobal.allocate
also reproduces this bug) and#[global_allocator]
. When I wanted to test the behavior of memory-exhaustion, I found that rustc seems to "optimized" my loop into dead-loop. Details are as follows.I tried this code (as a sample that can reproduce the bug) in current nightly:
I expected to see this happen:
main
function reaches its end (not dead loop)Instead, this happened:
main
function never returnsI used
RUSTFLAGS='--emit=llvm-ir'
to check its LLVM-IR, which seemed to show that the allocating-loop was optimized wrongly into a dead-loop.The text was updated successfully, but these errors were encountered: