From 4d6d422867a9bbcf290e16467400f2953fb90512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Mon, 29 Jun 2020 18:52:41 +0200 Subject: [PATCH 1/3] Use the alignas C++ keyword when compiling in C++ See #9714. --- runtime/caml/misc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/caml/misc.h b/runtime/caml/misc.h index 81798a014..4d9ac010a 100644 --- a/runtime/caml/misc.h +++ b/runtime/caml/misc.h @@ -96,6 +96,8 @@ CAMLdeprecated_typedef(addr, char *); /* we need to be able to compute the exact offset of each member. */ #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L #define CAMLalign(n) _Alignas(n) +#elif defined(__cplusplus) && (__cplusplus >= 201103L || _MSC_VER >= 1900) +#define CAMLalign(n) alignas(n) #elif defined(SUPPORTS_ALIGNED_ATTRIBUTE) #define CAMLalign(n) __attribute__((aligned(n))) #elif _MSC_VER >= 1500 From cba42a3ba38505773086f0b467a661a53206cc6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Mon, 29 Jun 2020 17:38:18 +0200 Subject: [PATCH 2/3] Add a terminator to the domain_state On a 32-bits architecture, if the last member of the caml_domain_state is a pointer, it will be 4-bytes long, and the struct will end after a 4 bytes boundary, failing the assertion. As @xavierleroy [put it][1]: > we don't care about the total size of the struct, but we care that > the members before `end_of_domain_state` are spaced by 8. [1]: https://github.com/ocaml/ocaml/issues/9714#issuecomment-650516382 See #9714. --- runtime/caml/domain_state.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/caml/domain_state.h b/runtime/caml/domain_state.h index 4427f21db..ee4613d60 100644 --- a/runtime/caml/domain_state.h +++ b/runtime/caml/domain_state.h @@ -33,6 +33,7 @@ typedef struct { #endif #include "domain_state.tbl" #undef DOMAIN_STATE + CAMLalign(8) char end_of_domain_state; } caml_domain_state; enum { @@ -45,9 +46,8 @@ enum { /* Check that the structure was laid out without padding, since the runtime assumes this in computing offsets */ CAML_STATIC_ASSERT( - sizeof(caml_domain_state) == - (Domain_state_num_fields - ) * 8); + offsetof(caml_domain_state, end_of_domain_state) == + Domain_state_num_fields * 8); CAMLextern caml_domain_state* Caml_state; #ifdef CAML_NAME_SPACE From cb3af257214ac74bb08b2792e02018528e36a574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Thu, 2 Jul 2020 09:35:15 +0200 Subject: [PATCH 3/3] Changes --- Changes | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Changes b/Changes index df495d372..3da187dec 100644 --- a/Changes +++ b/Changes @@ -257,6 +257,12 @@ Working version (Xavier Leroy, Sadiq Jaffer, Gabriel Scherer, review by Xavier Leroy and Jacques-Henri Jourdan) +- #9714, #9724: Use the C++ alignas keyword when compiling in C++. + Fixes a bug with MSVC C++ 2015/2017. Add a terminator to the + `caml_domain_state` structure to better ensure that members are + correctly spaced. + (Antonin Décimo, review by David Allsopp and Xavier Leroy) + OCaml 4.11 ----------