From 41eb890f77090ea22e5403dd256fb4a622b79928 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Sun, 12 Jun 2022 10:53:56 -0400 Subject: [PATCH] Rearrange the C11 vs MSVC check. Starting version 2019 16.8 (released November 2020), MSVC actually implements parts of C11, though disabled by default. You have to pass /std:c11, and then alignas, alignof, and noreturn all work. When built that way, better to use the real ones, so check for __STDC_VERSION__ first. It would be nice to mandate that so we can remove the polyfill, but for now just opportunistically use it when we can. Sadly, even in this mode, they still don't implement C11 atomics, so the refcounting implementation will still be slow. Change-Id: I28dab4a339c368f7d8f8da5aa7aee1cb344803d3 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/53006 Reviewed-by: Adam Langley Commit-Queue: David Benjamin --- crypto/internal.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crypto/internal.h b/crypto/internal.h index 2e94399c2..63e6a662f 100644 --- a/crypto/internal.h +++ b/crypto/internal.h @@ -126,7 +126,9 @@ #endif #if !defined(__cplusplus) -#if defined(_MSC_VER) && !defined(__clang__) +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +#include +#elif defined(_MSC_VER) && !defined(__clang__) #define alignas(x) __declspec(align(x)) #define alignof __alignof #else @@ -135,11 +137,13 @@ // compilers have long implemented C11 and made it default. The most likely // cause of pre-C11 modes is stale -std=c99 or -std=gnu99 flags in build // configuration. Such flags can be removed. -#if __STDC_VERSION__ < 201112L +// +// TODO(davidben): In MSVC 2019 16.8 or higher (_MSC_VER >= 1928), +// |__STDC_VERSION__| will be 201112 when passed /std:c11 and unset otherwise. +// C11 alignas and alignof are only implemented in C11 mode. Can we mandate C11 +// mode for those versions? #error "BoringSSL must be built in C11 mode or higher." #endif -#include -#endif #endif #if defined(OPENSSL_THREADS) && \