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 <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
diff --git a/crypto/internal.h b/crypto/internal.h
index 2e94399..63e6a66 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 <stdalign.h>
+#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 <stdalign.h>
-#endif
 #endif
 
 #if defined(OPENSSL_THREADS) && \