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>
#else
#include <io.h>
#pragma warning(push, 3)
OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <winsock2.h>
#include <ws2tcpip.h>
#pragma warning(pop)
OPENSSL_MSVC_PRAGMA(warning(pop))
#endif
#include <openssl/bio.h>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -161,6 +161,13 @@ extern "C" {
#define OPENSSL_PRINTF_FORMAT_FUNC(string_index, first_to_check)
#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. */
typedef int CRYPTO_THREADID;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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