Skip to content

support aligned allocation calls with alignments < pointer size #246

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

Closed
wants to merge 1 commit into from
Closed

support aligned allocation calls with alignments < pointer size #246

wants to merge 1 commit into from

Conversation

christoph-cullmann
Copy link

See issue #245

needed for e.g. code bases like LLVM


// if the passed alignment is too small, correct it upwards to the minimal internal required alignment
// fixes issues in user code calling aligned variants for types with small alignment requirements below pointer alignment
alignment = alignment < sizeof(void*) ? sizeof(void*) : alignment;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be below the if()s below which check that we were fed with a non-0 power-of-two first, before alignment is changed. Those requirements are sane.

Copy link

@adamdmoss adamdmoss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See review request for minor change.

@christoph-cullmann
Copy link
Author

I updated the commit with your proposed change.
Makes sense, the consistency checks can be done first.

daanx added a commit that referenced this pull request May 18, 2020
@daanx
Copy link
Collaborator

daanx commented May 18, 2020

Thanks for sending a PR! We should fix this -- however, I think just weakening the assertion is enough. With the check

 if (mi_unlikely(alignment==0 || !_mi_is_power_of_two(alignment))) return NULL;

we already check for powers-of-two which should satisfy the requirements. There is no need to round up the alignment itself I think since any allocation will do that automatically (as all blocks are at least void* aligned.

@christoph-cullmann
Copy link
Author

The assertions got relaxed, that did solve this issue, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants