Skip to content
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

Simplify CAMLalign and use C11 max_align_t #13139

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

MisterDA
Copy link
Contributor

@MisterDA MisterDA commented Apr 30, 2024

Some cleanups removing checks and workarounds for older compilers, assuming that the compiler supports C11 or C++11 out of the box. We may use _Alignas (since C11) or alignas (since C23) directly, and use the max_align_t type. Unfortunately, support for max_align_t is missing from the Windows C standard library.

In our public headers, we're using either:
- C23 where `alignas` is a keyword;
- C++11 or later where `alignas` is also available;
- C11/C17 where `_Alignas` is available.
For C++, MSVC defines `using max_align_t = double`. Take inspiration
from GCC and LLVM for the fallback implementation.

It's unlikely that we need to carry a fallback implementation for
other compilers. If so, the following could be used:

    #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L || \
        defined(__cplusplus)
    #define CAMLalignof(n) alignof(n)
    #else
    #define CAMLalignof(n) _Alignof(n)
    #endif

    typedef struct {
      long long ll CAMLalign(CAMLalignof(long long));
      long double ld CAMLalign(CAMLalignof(long double));
    } max_align_t;

https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/ginclude/stddef.h
https://github.com/llvm/llvm-project/blob/main/clang/lib/Headers/__stddef_max_align_t.h

https://en.cppreference.com/w/c/types/max_align_t
@MisterDA MisterDA force-pushed the alignas-simplify-CAMLalign branch from a49b31b to d226d67 Compare May 21, 2024 06:48
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.

None yet

3 participants