Skip to content

Mention alignment in handle_alloc_error - #166665

Open
clarfonthey wants to merge 1 commit into
rust-lang:mainfrom
clarfonthey:handle-alloc-error-align
Open

clarfonthey wants to merge 1 commit into
rust-lang:mainfrom
clarfonthey:handle-alloc-error-align

Conversation

@clarfonthey

Copy link
Copy Markdown
Contributor

cc @rust-lang/wg-allocators @folkertdev

Essentially, since malloc doesn't actually handle large alignments, it would be useful to just return an error for overaligned values, but this wouldn't be printed by the handler since currently we ignore the alignment. This changes that so it is printed, so that at least people can understand if failures are due to alignment.

@rustbot rustbot added A-allocators Area: Custom and system allocators S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 27, 2026
@rustbot

rustbot commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 38 candidates
  • Random selection from JohnTitor, Mark-Simulacrum, joboet

@rust-log-analyzer

This comment has been minimized.

@clarfonthey
clarfonthey force-pushed the handle-alloc-error-align branch from 1ceeb31 to 3cab7b2 Compare November 27, 2026 17:53
@rustbot

rustbot commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

miri is developed in its own repository. If the Miri part of this change can be broken out, consider making this change to rust-lang/miri instead. However, if Miri needs adjusting for rustc changes, just ignore this message.

cc @rust-lang/miri

@joboet

joboet commented Nov 28, 2026

Copy link
Copy Markdown
Member

Lovely! I don't think we guarantee anything about the panic messages, so I'll just unilaterally approve this.

@bors r+ rollup

@rust-bors

rust-bors Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 3cab7b2 has been approved by joboet

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 28, 2026
@bjorn3

bjorn3 commented Nov 28, 2026

Copy link
Copy Markdown
Member

This only changes the message for no_std builds. libstd has a separate implementation at

static PREV_ALLOC_FAILURE: AtomicBool = AtomicBool::new(false);
if PREV_ALLOC_FAILURE.swap(true, Ordering::Relaxed) {
// Don't try to print a backtrace if a previous alloc error happened. This likely means
// there is not enough memory to print a backtrace, although it could also mean that two
// threads concurrently run out of memory.
rtprintpanic!(
"memory allocation of {} bytes failed\nskipping backtrace printing to avoid potential recursion\n",
layout.size()
);
return;
} else {
rtprintpanic!("memory allocation of {} bytes failed\n", layout.size());
}

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 28, 2026
…gn, r=joboet

Mention alignment in handle_alloc_error

cc @rust-lang/wg-allocators @folkertdev

Essentially, since malloc doesn't actually handle large alignments, it would be useful to just return an error for overaligned values, but this wouldn't be printed by the handler since currently we ignore the alignment. This changes that so it is printed, so that at least people can understand if failures are due to alignment.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 28, 2026
…gn, r=joboet

Mention alignment in handle_alloc_error

cc @rust-lang/wg-allocators @folkertdev

Essentially, since malloc doesn't actually handle large alignments, it would be useful to just return an error for overaligned values, but this wouldn't be printed by the handler since currently we ignore the alignment. This changes that so it is printed, so that at least people can understand if failures are due to alignment.
rust-bors Bot pushed a commit that referenced this pull request Nov 28, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - #166232 (Fix considering `[u8; 0]` to have trivial ABI in layout)
 - #166663 (optimize `ArrayWindows::nth`)
 - #166693 (Make function signatures a separate type in `rustc_codegen_llvm`)
 - #166699 (rustc_serialize: Remove unnecessary lifetime from `FileEncoder`)
 - #166665 (Mention alignment in handle_alloc_error)
@joboet

joboet commented Nov 28, 2026

Copy link
Copy Markdown
Member

Please adjust that as well...
@bors r-

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 28, 2026
@rust-bors

rust-bors Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#166706), which was unapproved.

View changes since this unapproval

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-allocators Area: Custom and system allocators S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants