Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.3k
gh-127545: Replace _Py_ALIGN_AS(V) by _Py_ALIGNED_DEF(N, T)#135209
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
392f6c5
e0156b0
512fe58
851cc3a
80801db
6d7c805
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
This is a common façade for the various `_Alignas` alternatives,which behave in interesting ways.The standard `alignas` errors if it would decrease the alignment;to prevent that it can be used again with the defined variable'stype.The standard `alignas` can't be used on a `struct` definition,the workaround is to use it on one of the `struct`'s members.MSVC `declspec(aligned)` only takes integer literals.MSVC `declspec(aligned)` had a bug when applied to a combinedstruct+member definition.The workaround is to separate the struct definition.Do that for `PyASCIIObject.state`.
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -24,44 +24,67 @@ | ||
#endif | ||
// _Py_ALIGNED_DEF(N, T): Define a variable/member with increased alignment | ||
// | ||
// `N`: the desired minimum alignment, an integer literal | ||
encukou marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
// `T`: the type of the defined variable | ||
// (or a type with at least the defined variable's alignment) | ||
// | ||
// May not be used on a struct definition. | ||
// | ||
// Standards/compiler support for `alignas` alternatives: | ||
// - `alignas` is a keyword in C23 and C++11. | ||
// - `_Alignas` is a keyword in C11 | ||
// - GCC & clang has __attribute__((aligned)) | ||
// (use that for older standards in pedantic mode) | ||
// - MSVC has __declspec(align) | ||
// - `_Alignas` is common C compiler extension | ||
// Older compilers may name`alignas` differently; to allow compilation on such | ||
// unsupported platforms, we don't redefine_Py_ALIGNED_DEF if it's already | ||
// defined. Note that defining it wrong (including defining it to nothing) will | ||
// cause ABI incompatibilities. | ||
// | ||
// Behavior of `alignas` alternatives: | ||
// - `alignas` & `_Alignas`: | ||
// - Can be used multiple times; the greatest alignment applies. | ||
// - It is an *error* if the combined effect of all `alignas` modifiers would | ||
// decrease the alignment. | ||
// - Takes types or numbers. | ||
// - May not be used on a struct definition, unless also defining a variable. | ||
// - Can't be used on a whole struct, only on members. | ||
encukou marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
// - `__declspec(align)`: | ||
// - Has no effect if it would decrease alignment. | ||
// - Only takes an integer literal. | ||
// - May be used on struct or variable definitions. | ||
// - ` __attribute__((aligned))`: | ||
// - Has no effect if it would decrease alignment. | ||
// - Takes types or numbers | ||
// - May be used on struct or variable definitions. | ||
// However, when defining both the struct and the variable at once, | ||
// `declspec(aligned)` causes compiler warning 5274 and possible ABI | ||
// incompatibility. | ||
encukou marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
#ifndef _Py_ALIGNED_DEF | ||
# ifdef __cplusplus | ||
# if __cplusplus >= 201103L | ||
# define _Py_ALIGNED_DEF(N, T) alignas(N) alignas(T) T | ||
# elif defined(__GNUC__) || defined(__clang__) | ||
# define _Py_ALIGNED_DEF(N, T) __attribute__((aligned(N))) T | ||
# elif defined(_MSC_VER) | ||
# define _Py_ALIGNED_DEF(N, T) __declspec(align(N)) T | ||
# else | ||
# define _Py_ALIGNED_DEF(N, T) alignas(N) alignas(T) T | ||
# endif | ||
# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L | ||
# define _Py_ALIGNED_DEF(N, T) alignas(N) alignas(T) T | ||
# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L | ||
# define _Py_ALIGNED_DEF(N, T) _Alignas(N) _Alignas(T) T | ||
# elif (defined(__GNUC__) || defined(__clang__)) | ||
# define _Py_ALIGNED_DEF(N, T) __attribute__((aligned(N))) T | ||
# elif defined(_MSC_VER) | ||
# define _Py_ALIGNED_DEF(N, T) __declspec(align(N)) T | ||
# else | ||
# define _Py_ALIGNED_DEF(N, T) _Alignas(N) _Alignas(T) T | ||
# endif | ||
#endif | ||
/* Minimum value between x and y */ | ||
Uh oh!
There was an error while loading.Please reload this page.