Skip to content

Fix the implementation of max_align_t in lang/Align.h.#1180

Closed
brianpl wants to merge 2 commits into
facebook:masterfrom
brianpl:master
Closed

Fix the implementation of max_align_t in lang/Align.h.#1180
brianpl wants to merge 2 commits into
facebook:masterfrom
brianpl:master

Conversation

@brianpl

@brianpl brianpl commented Jul 1, 2019

Copy link
Copy Markdown

Folly's Align.h header overwrites max_align_t, which is usually taken from stdlib. This is to correct an error in legacy implementations of max_align_t, by logically reconstructing the maximum alignment value in a constexpr.

max_align_t depends on the function folly::details::max_align_, which is supposed to implement a recursive max value function using templates. However, the expression

!(a < max_align_(e, es...)) ? a : max_align_(e, es...)

does not recursively compute the maximum value over e and es...

This implementation actually selects the first value of e and es... that is followed by a lower value.

The correct implementation is provided in this pull request.

This error prevents folly from compiling on newer versions of clang, targeting x86, because CachelinePadded.h statically checks max_align_t in an assertion, and then fails, because it thinks that AtomicStruct<LifoSemHead, atomic> is over-aligned.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@brianpl brianpl changed the title Fix the implementation of a recursive max value function, max_align_t, in lang/Align.h. Jul 1, 2019
@facebook-github-bot

Copy link
Copy Markdown
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@yfeldblum yfeldblum left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yikes! Thanks for the PR.

Comment thread folly/lang/Align.h Outdated

@facebook-github-bot facebook-github-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@yfeldblum has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@yfeldblum

Copy link
Copy Markdown
Contributor

Thanks!

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@yfeldblum merged this pull request in 72c08f7.

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

4 participants