Wrap MSVC-only warning pragmas in a macro.

There's a __pragma expression which allows this. Android builds us Windows with
MinGW for some reason, so we actually do have to tolerate non-MSVC-compatible
Windows compilers. (Clang for Windows is much more sensible than MinGW and
intentionally mimicks MSVC.)

MinGW doesn't understand MSVC's pragmas and warns a lot. #pragma warning is
safe to suppress, so wrap those to shush them. This also lets us do away with a
few ifdefs.

Change-Id: I1f5a8bec4940d4b2d947c4c1cc9341bc15ec4972
Reviewed-on: https://boringssl-review.googlesource.com/8236
Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
David Benjamin 2016-06-09 16:48:33 -04:00 committed by Adam Langley
parent 2e8ba2d25d
commit a353cdb671
28 changed files with 65 additions and 71 deletions

View File

@ -27,10 +27,10 @@
#include <unistd.h> #include <unistd.h>
#else #else
#include <io.h> #include <io.h>
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#endif #endif
#include <openssl/bio.h> #include <openssl/bio.h>

View File

@ -66,10 +66,10 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <unistd.h> #include <unistd.h>
#else #else
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#endif #endif
#include <openssl/buf.h> #include <openssl/buf.h>

View File

@ -63,9 +63,9 @@
#include <unistd.h> #include <unistd.h>
#else #else
#include <io.h> #include <io.h>
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <windows.h> #include <windows.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#endif #endif
#include <openssl/buf.h> #include <openssl/buf.h>

View File

@ -67,9 +67,9 @@ typedef unsigned short u_short;
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#else #else
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <winsock2.h> #include <winsock2.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
typedef int socklen_t; typedef int socklen_t;
#endif #endif

View File

@ -63,9 +63,9 @@
#if !defined(OPENSSL_WINDOWS) #if !defined(OPENSSL_WINDOWS)
#include <unistd.h> #include <unistd.h>
#else #else
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <winsock2.h> #include <winsock2.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#pragma comment(lib, "Ws2_32.lib") #pragma comment(lib, "Ws2_32.lib")
#endif #endif

View File

@ -26,10 +26,10 @@
#include <netdb.h> #include <netdb.h>
#include <unistd.h> #include <unistd.h>
#else #else
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#endif #endif
#include "internal.h" #include "internal.h"

View File

@ -126,9 +126,9 @@
#include <openssl/base.h> #include <openssl/base.h>
#if defined(OPENSSL_X86_64) && defined(_MSC_VER) #if defined(OPENSSL_X86_64) && defined(_MSC_VER)
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <intrin.h> #include <intrin.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#pragma intrinsic(__umulh, _umul128) #pragma intrinsic(__umulh, _umul128)
#endif #endif

View File

@ -67,9 +67,7 @@
#endif #endif
#if defined(_MSC_VER) OPENSSL_MSVC_PRAGMA(warning(disable: 4702)) /* Unreachable code. */
#pragma warning(disable: 4702) /* Unreachable code. */
#endif
typedef struct { typedef struct {
union { union {

View File

@ -69,10 +69,10 @@
#include <string.h> #include <string.h>
#if defined(OPENSSL_WINDOWS) #if defined(OPENSSL_WINDOWS)
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <immintrin.h> #include <immintrin.h>
#include <intrin.h> #include <intrin.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#endif #endif
#include "internal.h" #include "internal.h"

View File

@ -114,9 +114,9 @@
#include <string.h> #include <string.h>
#if defined(OPENSSL_WINDOWS) #if defined(OPENSSL_WINDOWS)
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <windows.h> #include <windows.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#endif #endif
#include <openssl/mem.h> #include <openssl/mem.h>

View File

@ -51,30 +51,27 @@
* ==================================================================== * ====================================================================
*/ */
#include <openssl/evp.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(_MSC_VER) OPENSSL_MSVC_PRAGMA(warning(push))
#pragma warning(push) OPENSSL_MSVC_PRAGMA(warning(disable: 4702))
#pragma warning(disable: 4702)
#endif
#include <map> #include <map>
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
#if defined(_MSC_VER) OPENSSL_MSVC_PRAGMA(warning(pop))
#pragma warning(pop)
#endif
#include <openssl/bytestring.h> #include <openssl/bytestring.h>
#include <openssl/crypto.h> #include <openssl/crypto.h>
#include <openssl/digest.h> #include <openssl/digest.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/evp.h>
#include "../test/file_test.h" #include "../test/file_test.h"
#include "../test/scoped_types.h" #include "../test/scoped_types.h"

View File

@ -123,9 +123,9 @@
#if defined(OPENSSL_NO_THREADS) #if defined(OPENSSL_NO_THREADS)
#elif defined(OPENSSL_WINDOWS) #elif defined(OPENSSL_WINDOWS)
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <windows.h> #include <windows.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#else #else
#include <pthread.h> #include <pthread.h>
#endif #endif

View File

@ -66,9 +66,9 @@
#include <string.h> #include <string.h>
#if defined(OPENSSL_WINDOWS) #if defined(OPENSSL_WINDOWS)
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <windows.h> #include <windows.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#else #else
#include <strings.h> #include <strings.h>
#endif #endif

View File

@ -121,9 +121,9 @@ extern "C" {
#endif #endif
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
#if _MSC_VER >= 1300 #if _MSC_VER >= 1300
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <intrin.h> #include <intrin.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#pragma intrinsic(_byteswap_uint64, _byteswap_ulong) #pragma intrinsic(_byteswap_uint64, _byteswap_ulong)
#define BSWAP8(x) _byteswap_uint64((uint64_t)(x)) #define BSWAP8(x) _byteswap_uint64((uint64_t)(x))
#define BSWAP4(x) _byteswap_ulong((uint32_t)(x)) #define BSWAP4(x) _byteswap_ulong((uint32_t)(x))

View File

@ -19,7 +19,7 @@
#include <limits.h> #include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <windows.h> #include <windows.h>
@ -30,7 +30,7 @@
#include <ntsecapi.h> #include <ntsecapi.h>
#undef SystemFunction036 #undef SystemFunction036
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#include "internal.h" #include "internal.h"

View File

@ -20,19 +20,15 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#if defined(_MSC_VER) OPENSSL_MSVC_PRAGMA(warning(push))
#pragma warning(push) OPENSSL_MSVC_PRAGMA(warning(disable: 4702))
#pragma warning(disable: 4702)
#endif
#include <string> #include <string>
#include <map> #include <map>
#include <set> #include <set>
#include <vector> #include <vector>
#if defined(_MSC_VER) OPENSSL_MSVC_PRAGMA(warning(pop))
#pragma warning(pop)
#endif
// File-based test framework. // File-based test framework.
// //

View File

@ -61,9 +61,9 @@
#if !defined(OPENSSL_WINDOWS) #if !defined(OPENSSL_WINDOWS)
#include <errno.h> #include <errno.h>
#else #else
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <windows.h> #include <windows.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#endif #endif
#include <openssl/mem.h> #include <openssl/mem.h>

View File

@ -21,9 +21,9 @@
#if defined(OPENSSL_WINDOWS) #if defined(OPENSSL_WINDOWS)
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <windows.h> #include <windows.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
typedef HANDLE thread_t; typedef HANDLE thread_t;

View File

@ -16,9 +16,9 @@
#if defined(OPENSSL_WINDOWS) && !defined(OPENSSL_NO_THREADS) #if defined(OPENSSL_WINDOWS) && !defined(OPENSSL_NO_THREADS)
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <windows.h> #include <windows.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

View File

@ -57,9 +57,9 @@
#include <openssl/cast.h> #include <openssl/cast.h>
#if defined(OPENSSL_WINDOWS) #if defined(OPENSSL_WINDOWS)
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <intrin.h> #include <intrin.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#endif #endif
#include "internal.h" #include "internal.h"

View File

@ -161,6 +161,13 @@ extern "C" {
#define OPENSSL_PRINTF_FORMAT_FUNC(string_index, first_to_check) #define OPENSSL_PRINTF_FORMAT_FUNC(string_index, first_to_check)
#endif #endif
/* OPENSSL_MSVC_PRAGMA emits a pragma on MSVC and nothing on other compilers. */
#if defined(_MSC_VER)
#define OPENSSL_MSVC_PRAGMA(arg) __pragma(arg)
#else
#define OPENSSL_MSVC_PRAGMA(arg)
#endif
/* CRYPTO_THREADID is a dummy value. */ /* CRYPTO_THREADID is a dummy value. */
typedef int CRYPTO_THREADID; typedef int CRYPTO_THREADID;

View File

@ -151,9 +151,9 @@
#if defined(OPENSSL_WINDOWS) #if defined(OPENSSL_WINDOWS)
/* Windows defines struct timeval in winsock2.h. */ /* Windows defines struct timeval in winsock2.h. */
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <winsock2.h> #include <winsock2.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#else #else
#include <sys/time.h> #include <sys/time.h>
#endif #endif

View File

@ -28,10 +28,10 @@
#include <unistd.h> #include <unistd.h>
#else #else
#include <io.h> #include <io.h>
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#pragma comment(lib, "Ws2_32.lib") #pragma comment(lib, "Ws2_32.lib")
#endif #endif

View File

@ -21,9 +21,9 @@
#include "../../crypto/test/scoped_types.h" #include "../../crypto/test/scoped_types.h"
#if defined(OPENSSL_WINDOWS) #if defined(OPENSSL_WINDOWS)
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <winsock2.h> #include <winsock2.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#else #else
#include <sys/time.h> #include <sys/time.h>
#endif #endif

View File

@ -31,9 +31,9 @@
#define O_BINARY 0 #define O_BINARY 0
#endif #endif
#else #else
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <windows.h> #include <windows.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#include <io.h> #include <io.h>
#define PATH_MAX MAX_PATH #define PATH_MAX MAX_PATH
typedef int ssize_t; typedef int ssize_t;

View File

@ -20,19 +20,15 @@
#include <string> #include <string>
#include <vector> #include <vector>
#if defined(_MSC_VER) OPENSSL_MSVC_PRAGMA(warning(push))
#pragma warning(push)
// MSVC issues warning C4702 for unreachable code in its xtree header when // MSVC issues warning C4702 for unreachable code in its xtree header when
// compiling with -D_HAS_EXCEPTIONS=0. See // compiling with -D_HAS_EXCEPTIONS=0. See
// https://connect.microsoft.com/VisualStudio/feedback/details/809962 // https://connect.microsoft.com/VisualStudio/feedback/details/809962
#pragma warning(disable: 4702) OPENSSL_MSVC_PRAGMA(warning(disable: 4702))
#endif
#include <map> #include <map>
#if defined(_MSC_VER) OPENSSL_MSVC_PRAGMA(warning(pop))
#pragma warning(pop)
#endif
#if defined(OPENSSL_WINDOWS) #if defined(OPENSSL_WINDOWS)
#define BORINGSSL_OPEN _open #define BORINGSSL_OPEN _open

View File

@ -30,9 +30,9 @@
#include <openssl/rsa.h> #include <openssl/rsa.h>
#if defined(OPENSSL_WINDOWS) #if defined(OPENSSL_WINDOWS)
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <windows.h> #include <windows.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
#elif defined(OPENSSL_APPLE) #elif defined(OPENSSL_APPLE)
#include <sys/time.h> #include <sys/time.h>
#endif #endif

View File

@ -33,10 +33,10 @@
#include <unistd.h> #include <unistd.h>
#else #else
#include <io.h> #include <io.h>
#pragma warning(push, 3) OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#pragma warning(pop) OPENSSL_MSVC_PRAGMA(warning(pop))
typedef int ssize_t; typedef int ssize_t;
#pragma comment(lib, "Ws2_32.lib") #pragma comment(lib, "Ws2_32.lib")