Skip to content

BUG: use _Alignof rather than offsetof() on most compilers#23031

Merged
charris merged 1 commit intonumpy:maintenance/1.24.xfrom
charris:backport-23016
Jan 18, 2023
Merged

BUG: use _Alignof rather than offsetof() on most compilers#23031
charris merged 1 commit intonumpy:maintenance/1.24.xfrom
charris:backport-23016

Conversation

@charris
Copy link
Copy Markdown
Member

@charris charris commented Jan 17, 2023

Backport of #23016.

WG14 N2350 made very clear that it is an UB having type definitions within "offsetof" [1]. This patch enhances the implementation of macro _ALIGN to use builtin "_Alignof" to avoid undefined behavior on when using std=c11 or newer

clang 16+ has started to flag this [2]

Fixes build when using -std >= gnu11 and using clang16+

Older compilers gcc < 4.9 or clang < 8 has buggy _Alignof even though it may support C11, exclude those compilers too

[1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm [2] https://reviews.llvm.org/D133574

Signed-off-by: Khem Raj raj.khem@gmail.com

  • Apply suggestions from code review

Signed-off-by: Khem Raj raj.khem@gmail.com
Co-authored-by: Sebastian Berg sebastian@sipsolutions.net

…#23016)

WG14 N2350 made very clear that it is an UB having type definitions
within "offsetof" [1]. This patch enhances the implementation of macro
_ALIGN to use builtin "_Alignof" to avoid undefined behavior on
when using std=c11 or newer

clang 16+ has started to flag this [2]

Fixes build when using -std >= gnu11 and using clang16+

Older compilers gcc < 4.9 or clang < 8 has buggy _Alignof even though it
may support C11, exclude those compilers too

[1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm
[2] https://reviews.llvm.org/D133574

Signed-off-by: Khem Raj <raj.khem@gmail.com>

* Apply suggestions from code review

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
@charris charris added 00 - Bug 08 - Backport Used to tag backport PRs labels Jan 17, 2023
@charris charris added this to the 1.24.2 release milestone Jan 17, 2023
@charris charris merged commit e8f62ea into numpy:maintenance/1.24.x Jan 18, 2023
@charris charris deleted the backport-23016 branch January 18, 2023 00:24
@charris charris changed the title BUG: use _Alignof rather than offsetof() on most compilers BUG: use _Alignof rather than offsetof() on most compilers Feb 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

00 - Bug 08 - Backport Used to tag backport PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants