-
Notifications
You must be signed in to change notification settings - Fork 151
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
Fix alignment of test structs #260
Conversation
If you ever put an template <class T>
struct alignas(std::is_arithmetic<T>::value ? sizeof(T) : alignof(T)) AlignedBase {};
template <class T>
struct S : AlignedBase<T>
{
// ...
}; |
True, but this is test code and it already makes assumptions about the required alignment. AFAICT plugging in a Inheriting from |
I guess the test won't work anyway if arbitrary types are plugged in, since it assigns index values to the T members. So setting the alignment to be correct in a generic way is maybe not the primary goal for this test. Since the problem is understood, in the interest of moving forward I would agree with Jonas's fix even as temporary solution, unless you really prefer Matthias the AlignedBase fallback for non-arithmetic types. |
I'll elaborate:
Forcing a higher alignment effectively reduces test coverage, which is why I don't like the proposed PR as is. Jonas' proposal to use a
I don't understand what you're trying to say here. FWIW, the structured gather & scatter take a base pointer, data member pointer, and index vector. The implementation uses the member pointer to offset the base pointer and scales the index vector so that the indexes are not relative to the struct array anymore but to individual elements of type |
Instead of Edit: Nope, doesn't work with Apple's clang... |
Clang complains for subscript.cpp: error: requested alignment is less than minimum alignment of 8 for type 'S<float>' The reason is that the struct also contains a double that requires alignment of at least 8 bytes on x86_64 and the programm is thus ill-formed. Remedy by taking alignof(double) into account. Other approaches explored: 1) Adding multiple alignas, the compiler should use the "strictest (largest) non-zero expression". However GCC (including the latest version 10.2.0) always applies the last attribute and older versions of Clang (tested: 5.0.2 as in Xcode 9.4.1) also error out. 2) Using std::max to get the maximum. GCC complains that the result is not an integer constant.
Your last solution looks good. It's still unfortunate that a type from the data members must be repeated. But this is test code... |
Clang complains for subscript.cpp:
The reason is that the struct also contains a double that requires
alignment of at least 8 bytes on x86_64 and the program is thus
ill-formed. Remedy by taking
alignof(double)
into account.Other approaches explored:
alignas
, the compiler should use the "strictest(largest) non-zero expression". However GCC (including the latest
version 10.2.0) always applies the last attribute and older versions
of Clang (tested: 5.0.2 as in Xcode 9.4.1) also error out.
std::max
to get the maximum. GCC complains that the resultis not an integer constant.