Cleaning up MSVC warnings and syncing with bazel warnings.
diff --git a/build_tools/bazel/iree.bazelrc b/build_tools/bazel/iree.bazelrc
index b90be65..58d2b91 100644
--- a/build_tools/bazel/iree.bazelrc
+++ b/build_tools/bazel/iree.bazelrc
@@ -296,11 +296,6 @@
 
 # And some more explicit disables. For some reason the `/w` on external doesn't
 # work for these, maybe they come from headers?
-build:_msvc_base --copt=/wd4244 # possible loss of data
-build:_msvc_base --copt=/wd4624 # destructor was implicitly defined as deleted
-build:_msvc_base --copt=/wd4005 # macro redefinition
-build:_msvc_base --copt=/wd4267 # initializing: possible loss of data
-build:_msvc_base --copt=/wd4141 # inline used more than once
 # new warning with the standards-compliant preprocessor. winbase itself is not standards-compliant
 build:_msvc_base --per_file_copt=mkl_dnn@/wd4551 # missing argument list
 build:_msvc_base --per_file_copt=mkl_dnn@/wd4068 # unknown pragma
@@ -314,12 +309,6 @@
 build:_msvc_base --copt=/arch:AVX
 # Host and target are the same in windows so don't waste time building both.
 build:_msvc_base --distinct_host_configuration=false
-# Avoids incompatible versions of winsock and other badness.
-build:_msvc_base --copt=/DWIN32_LEAN_AND_MEAN
-# Why are min/max macros? No one knows.
-build:_msvc_base --copt=/DNOMINMAX
-# Yay for security warnings. Boo for non-standard.
-build:_msvc_base --copt=/D_CRT_SECURE_NO_WARNINGS
 # TensorFlow requires the "monolithic" build mode for now on Windows.
 build:_msvc_base --define framework_shared_object=false
 
diff --git a/build_tools/cmake/iree_copts.cmake b/build_tools/cmake/iree_copts.cmake
index 388282f..ec1f394 100644
--- a/build_tools/cmake/iree_copts.cmake
+++ b/build_tools/cmake/iree_copts.cmake
@@ -185,6 +185,24 @@
     # https://docs.microsoft.com/en-us/cpp/c-runtime-library/math-constants
     "/D_USE_MATH_DEFINES"
 
+    # Disable the "deprecation" warnings about CRT functions like strcpy.
+    # Though the secure versions *are* better, they aren't portable and as such
+    # just make cross-platform code annoying. One solution is to reimplement
+    # them in a portable fashion and use those - and that's what we try to do
+    # in certain places where we can get away with it. Other uses, like getenv,
+    # are fine as these are not intended for use in core runtime code that needs
+    # to be secure (friends don't let friends ship entire compiler stacks
+    # embedded inside security sensitive applications anyway :).
+    # https://docs.microsoft.com/en-us/cpp/c-runtime-library/security-features-in-the-crt
+    "/D_CRT_SECURE_NO_WARNINGS"
+
+    # With the above said about the "deprecated" functions; this useful flag
+    # will at least try to use them when possible without any change to user
+    # code. Note however because the new versions use templates they won't be
+    # activated in C code; that's fine.
+    # https://docs.microsoft.com/en-us/cpp/c-runtime-library/secure-template-overloads
+    "/D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES"
+
     # Configure exception handling for standard C++ behavior.
     # - /EHs enables C++ catch-style exceptions
     # - /EHc breaks unwinding across extern C boundaries, dramatically reducing
@@ -204,7 +222,18 @@
     # https://docs.microsoft.com/en-us/cpp/build/reference/bigobj-increase-number-of-sections-in-dot-obj-file
     "/bigobj"
 
-    "/wd4624"
+    # "nonstandard extension used : zero-sized array in struct/union"
+    # This happens with unsized or zero-length arrays at the end of structs,
+    # which is completely valid in C where we do it and get this warning. Shut
+    # it up and rely on the better warnings from clang to catch if we try to
+    # use it where it really matters (on a class that has copy/move ctors, etc).
+    # https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-levels-2-and-4-c4200
+    "/wd4200"
+
+    # Misc tweaks to better match clang/gcc behavior:
+    "/wd4065"  # switch statement contains 'default' but no 'case' labels
+    "/wd4146"  # operator applied to unsigned type, result still unsigned
+
     "/wd4141"  # duplicate inline attributes
     "/wd4005"  # macro redefinition
     "/wd4267"
diff --git a/iree/modules/check/iree-check-module-main.cc b/iree/modules/check/iree-check-module-main.cc
index 7e3687f..d72cda7 100644
--- a/iree/modules/check/iree-check-module-main.cc
+++ b/iree/modules/check/iree-check-module-main.cc
@@ -35,7 +35,7 @@
 #if defined(IREE_PLATFORM_WINDOWS)
 #include <fcntl.h>
 #include <io.h>
-#define IREE_FORCE_BINARY_STDIN() setmode(_fileno(stdin), O_BINARY)
+#define IREE_FORCE_BINARY_STDIN() _setmode(_fileno(stdin), O_BINARY)
 #else
 #define IREE_FORCE_BINARY_STDIN()
 #endif  // IREE_PLATFORM_WINDOWS