Fix standalone Windows release-mode builds.

`cmake -GNinja .. -DCMAKE_BUILD_TYPE=Release` fails without this
patch, when building using MSVC 2013.

MSVC will detect (in release builds only, it seems) that functions that
call abort will never return, and then warn that any code after a call
to one of them is unreachable. Since we treat warnings as errors when
building, this breaks the build. While this is usually desirable, it
isn't desirable in this case.

Change-Id: Ie5f24b1beb60fd2b33582a2ceef4c378ad0678fb
Reviewed-on: https://boringssl-review.googlesource.com/3960
Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
Brian Smith 2015-03-16 19:27:05 -10:00 committed by Adam Langley
parent 655764a22a
commit 1a9bc44127
2 changed files with 24 additions and 2 deletions

View File

@ -283,7 +283,8 @@ void aesni_ctr32_encrypt_blocks(const uint8_t *in, uint8_t *out, size_t blocks,
#endif #endif
static int aes_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key, static int aes_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
const uint8_t *iv, int enc) { const uint8_t *iv, int enc)
OPENSSL_SUPPRESS_UNREACHABLE_CODE_WARNINGS {
int ret, mode; int ret, mode;
EVP_AES_KEY *dat = (EVP_AES_KEY *)ctx->cipher_data; EVP_AES_KEY *dat = (EVP_AES_KEY *)ctx->cipher_data;
@ -404,7 +405,8 @@ static char aesni_capable(void);
static ctr128_f aes_ctr_set_key(AES_KEY *aes_key, GCM128_CONTEXT *gcm_ctx, static ctr128_f aes_ctr_set_key(AES_KEY *aes_key, GCM128_CONTEXT *gcm_ctx,
block128_f *out_block, const uint8_t *key, block128_f *out_block, const uint8_t *key,
size_t key_len) { size_t key_len)
OPENSSL_SUPPRESS_UNREACHABLE_CODE_WARNINGS {
if (aesni_capable()) { if (aesni_capable()) {
aesni_set_encrypt_key(key, key_len * 8, aes_key); aesni_set_encrypt_key(key, key_len * 8, aes_key);
if (gcm_ctx != NULL) { if (gcm_ctx != NULL) {

View File

@ -120,6 +120,26 @@ extern "C" {
#endif #endif
/* MSVC will sometimes correctly detect unreachable code and issue a warning,
* which breaks the build since we treat errors as warnings, in some rare cases
* where we want to allow the dead code to continue to exist. In these
* situations, annotate the function containing the unreachable code with
* OPENSSL_SUPPRESS_UNREACHABLE_CODE_WARNINGS after its parameters:
*
* void f() OPENSSL_SUPPRESS_UNREACHABLE_CODE_WARNINGS {
* ...
* }
*
* Note that MSVC's reachability analysis seems to operate on a whole-function
* basis, so the annotation must be placed on the entire function, not just a
* block within the function. */
#if defined(_MSC_VER)
#define OPENSSL_SUPPRESS_UNREACHABLE_CODE_WARNINGS \
__pragma(warning(suppress:4702))
#else
#define OPENSSL_SUPPRESS_UNREACHABLE_CODE_WARNINGS
#endif
/* st_CRYPTO_EX_DATA_IMPL contains an ex_data implementation. See the comments /* st_CRYPTO_EX_DATA_IMPL contains an ex_data implementation. See the comments
* in ex_data.h for details of the behaviour of each of the functions. */ * in ex_data.h for details of the behaviour of each of the functions. */
struct st_CRYPTO_EX_DATA_IMPL { struct st_CRYPTO_EX_DATA_IMPL {