[openmp] Silence warnings when building the LLVM release with MSVC

GitOrigin-RevId: 64874e5ab5fd102344d43ac9465537a44130bf19
diff --git a/runtime/src/kmp.h b/runtime/src/kmp.h
index c287a31..25fdb2f 100644
--- a/runtime/src/kmp.h
+++ b/runtime/src/kmp.h
@@ -502,6 +502,11 @@
 }
 
 /* Type to keep runtime schedule set via OMP_SCHEDULE or omp_set_schedule() */
+#if KMP_COMPILER_MSVC
+#pragma warning(push)
+// warning C4201: nonstandard extension used: nameless struct/union
+#pragma warning(disable : 4201)
+#endif
 typedef union kmp_r_sched {
   struct {
     enum sched_type r_sched_type;
@@ -509,6 +514,9 @@
   };
   kmp_int64 sched;
 } kmp_r_sched_t;
+#if KMP_COMPILER_MSVC
+#pragma warning(pop)
+#endif
 
 extern enum sched_type __kmp_sch_map[]; // map OMP 3.0 schedule types with our
 // internal schedule types
@@ -602,6 +610,8 @@
 #pragma warning(push)
 #pragma warning(disable : 271 310)
 #endif
+// Don't include everything related to NT status code, we'll do that explicitely
+#define WIN32_NO_STATUS
 #include <windows.h>
 #if KMP_MSVC_COMPAT
 #pragma warning(pop)
@@ -1897,12 +1907,20 @@
   // Because of parm1-4 are used together, performance seems to be better
   // if they are on the same cache line (not measured though).
 
+#if KMP_COMPILER_MSVC
+#pragma warning(push)
+// warning C4201: nonstandard extension used: nameless struct/union
+#pragma warning(disable : 4201)
+#endif
   struct KMP_ALIGN(32) {
     kmp_int32 parm1;
     kmp_int32 parm2;
     kmp_int32 parm3;
     kmp_int32 parm4;
   };
+#if KMP_COMPILER_MSVC
+#pragma warning(pop)
+#endif
 
 #if KMP_WEIGHTED_ITERATIONS_SUPPORTED
   kmp_uint32 pchunks;
@@ -1936,12 +1954,20 @@
   //    b) all parm1-4 are in the same cache line.
   // Because of parm1-4 are used together, performance seems to be better
   // if they are in the same line (not measured though).
+#if KMP_COMPILER_MSVC
+#pragma warning(push)
+// warning C4201: nonstandard extension used: nameless struct/union
+#pragma warning(disable : 4201)
+#endif
   struct KMP_ALIGN(32) {
     kmp_int64 parm1;
     kmp_int64 parm2;
     kmp_int64 parm3;
     kmp_int64 parm4;
   };
+#if KMP_COMPILER_MSVC
+#pragma warning(pop)
+#endif
 
 #if KMP_WEIGHTED_ITERATIONS_SUPPORTED
   kmp_uint64 pchunks;
@@ -2223,6 +2249,11 @@
 
 typedef union kmp_barrier_union kmp_balign_t;
 
+#if KMP_COMPILER_MSVC
+#pragma warning(push)
+// warning C4201: nonstandard extension used: nameless struct/union
+#pragma warning(disable : 4201)
+#endif
 /* Team barrier needs only non-volatile arrived counter */
 union KMP_ALIGN_CACHE kmp_barrier_team_union {
   double b_align; /* use worst case alignment */
@@ -2239,6 +2270,9 @@
 #endif
   };
 };
+#if KMP_COMPILER_MSVC
+#pragma warning(pop)
+#endif
 
 typedef union kmp_barrier_team_union kmp_balign_team_t;
 
diff --git a/runtime/src/kmp_affinity.cpp b/runtime/src/kmp_affinity.cpp
index 7009730..673b9f5 100644
--- a/runtime/src/kmp_affinity.cpp
+++ b/runtime/src/kmp_affinity.cpp
@@ -127,8 +127,9 @@
     return ((plural) ? KMP_I18N_STR(Threads) : KMP_I18N_STR(Thread));
   case KMP_HW_PROC_GROUP:
     return ((plural) ? KMP_I18N_STR(ProcGroups) : KMP_I18N_STR(ProcGroup));
+  default:
+    return KMP_I18N_STR(Unknown);
   }
-  return KMP_I18N_STR(Unknown);
 }
 
 const char *__kmp_hw_get_keyword(kmp_hw_t type, bool plural) {
@@ -157,8 +158,9 @@
     return ((plural) ? "threads" : "thread");
   case KMP_HW_PROC_GROUP:
     return ((plural) ? "proc_groups" : "proc_group");
+  default:
+    return ((plural) ? "unknowns" : "unknown");
   }
-  return ((plural) ? "unknowns" : "unknown");
 }
 
 const char *__kmp_hw_get_core_type_string(kmp_hw_core_type_t type) {
@@ -171,8 +173,9 @@
   case KMP_HW_CORE_TYPE_CORE:
     return "Intel(R) Core(TM) processor";
 #endif
+  default:
+    return "unknown";
   }
-  return "unknown";
 }
 
 #if KMP_AFFINITY_SUPPORTED
@@ -1246,9 +1249,10 @@
 #endif
       case KMP_HW_CORE_TYPE_UNKNOWN:
         return 0;
+      default:
+        KMP_ASSERT(0);
+        return 0;
       }
-      KMP_ASSERT(0);
-      return 0;
     }
   };
   struct core_eff_indexer {
diff --git a/runtime/src/kmp_atomic.h b/runtime/src/kmp_atomic.h
index 4fc51ee..1cf1701 100644
--- a/runtime/src/kmp_atomic.h
+++ b/runtime/src/kmp_atomic.h
@@ -1029,6 +1029,14 @@
 kmp_cmplx32 __kmpc_atomic_cmplx4_rd(ident_t *id_ref, int gtid,
                                     kmp_cmplx32 *loc);
 #endif
+
+#if KMP_COMPILER_MSVC
+#pragma warning(push)
+// warning C4190: '__kmpc_atomic_cmplx8_rd' has C-linkage specified, but returns
+// UDT '__kmp_cmplx64_t' which is incompatible with C
+#pragma warning(disable : 4190)
+#endif
+
 kmp_cmplx64 __kmpc_atomic_cmplx8_rd(ident_t *id_ref, int gtid,
                                     kmp_cmplx64 *loc);
 kmp_cmplx80 __kmpc_atomic_cmplx10_rd(ident_t *id_ref, int gtid,
@@ -1589,6 +1597,10 @@
 #endif
 #endif
 
+#if KMP_COMPILER_MSVC
+#pragma warning(pop)
+#endif
+
 // Capture routines for mixed types (RHS=float16)
 #if KMP_HAVE_QUAD
 
diff --git a/runtime/src/kmp_barrier.cpp b/runtime/src/kmp_barrier.cpp
index 281b8e9..c58eb27 100644
--- a/runtime/src/kmp_barrier.cpp
+++ b/runtime/src/kmp_barrier.cpp
@@ -2405,9 +2405,10 @@
 #endif /* USE_ITT_BUILD */
   if (team)
 
-  KA_TRACE(10, ("__kmp_fork_barrier: T#%d(%d:%d) has arrived\n", gtid,
-                (team != NULL) ? team->t.t_id : -1, tid));
-
+#ifdef KMP_DEBUG
+    KA_TRACE(10, ("__kmp_fork_barrier: T#%d(%d:%d) has arrived\n", gtid,
+                  (team != NULL) ? team->t.t_id : -1, tid));
+#endif
   // th_team pointer only valid for primary thread here
   if (KMP_MASTER_TID(tid)) {
 #if USE_ITT_BUILD && USE_ITT_NOTIFY
diff --git a/runtime/src/kmp_dispatch.h b/runtime/src/kmp_dispatch.h
index cf19eb5..340fe57 100644
--- a/runtime/src/kmp_dispatch.h
+++ b/runtime/src/kmp_dispatch.h
@@ -81,6 +81,11 @@
 
   /* parm[1-4] are used in different ways by different scheduling algorithms */
 
+#if KMP_COMPILER_MSVC
+#pragma warning(push)
+// warning C4201: nonstandard extension used: nameless struct/union
+#pragma warning(disable : 4201)
+#endif
   // KMP_ALIGN(32) ensures ( if the KMP_ALIGN macro is turned on )
   //    a) parm3 is properly aligned and
   //    b) all parm1-4 are in the same cache line.
@@ -92,6 +97,9 @@
     T parm3;
     T parm4;
   };
+#if KMP_COMPILER_MSVC
+#pragma warning(pop)
+#endif
 
 #if KMP_WEIGHTED_ITERATIONS_SUPPORTED
   UT pchunks; // total number of chunks for processes with p-core
diff --git a/runtime/src/kmp_io.cpp b/runtime/src/kmp_io.cpp
index 578e6e6..421bfe7 100644
--- a/runtime/src/kmp_io.cpp
+++ b/runtime/src/kmp_io.cpp
@@ -50,6 +50,7 @@
 static int __kmp_console_exists = FALSE;
 static kmp_str_buf_t __kmp_console_buf;
 
+#if 0
 static int is_console(void) {
   char buffer[128];
   DWORD rc = 0;
@@ -67,6 +68,7 @@
   }
   return rc > 0 || err == 0;
 }
+#endif
 
 void __kmp_close_console(void) {
   /* wait until user presses return before closing window */
@@ -84,7 +86,6 @@
 static void __kmp_redirect_output(void) {
   __kmp_acquire_bootstrap_lock(&__kmp_console_lock);
 
-  (void)is_console;
   if (!__kmp_console_exists) {
     HANDLE ho;
     HANDLE he;
diff --git a/runtime/src/kmp_settings.cpp b/runtime/src/kmp_settings.cpp
index 30a4c05..6ee9a89 100644
--- a/runtime/src/kmp_settings.cpp
+++ b/runtime/src/kmp_settings.cpp
@@ -873,6 +873,10 @@
     case library_throughput: {
       value = "PASSIVE";
     } break;
+    case library_none:
+    case library_serial: {
+      value = NULL;
+    } break;
     }
   } else {
     switch (__kmp_library) {
@@ -885,6 +889,9 @@
     case library_throughput: {
       value = "throughput";
     } break;
+    case library_none: {
+      value = NULL;
+    } break;
     }
   }
   if (value != NULL) {
@@ -2003,16 +2010,15 @@
 static inline const char *
 __kmp_hw_get_core_type_keyword(kmp_hw_core_type_t type) {
   switch (type) {
-  case KMP_HW_CORE_TYPE_UNKNOWN:
-    return "unknown";
 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
   case KMP_HW_CORE_TYPE_ATOM:
     return "intel_atom";
   case KMP_HW_CORE_TYPE_CORE:
     return "intel_core";
 #endif
+  default:
+    return "unknown";
   }
-  return "unknown";
 }
 
 #if KMP_AFFINITY_SUPPORTED
@@ -4428,6 +4434,8 @@
     case kmp_sch_auto:
       __kmp_str_buf_print(buffer, "%s,%d'\n", "auto", __kmp_chunk);
       break;
+    default:
+      break;
     }
   } else {
     switch (sched) {
@@ -4453,6 +4461,8 @@
     case kmp_sch_auto:
       __kmp_str_buf_print(buffer, "%s'\n", "auto");
       break;
+    default:
+      break;
     }
   }
 } // __kmp_stg_print_omp_schedule
diff --git a/runtime/src/kmp_wait_release.h b/runtime/src/kmp_wait_release.h
index 3fcae56..36a28e6 100644
--- a/runtime/src/kmp_wait_release.h
+++ b/runtime/src/kmp_wait_release.h
@@ -1038,7 +1038,6 @@
   case flag_oncore:
     __kmp_resume_oncore(gtid, RCAST(kmp_flag_oncore *, flag));
     break;
-#ifdef KMP_DEBUG
   case flag_unset:
     KF_TRACE(100, ("__kmp_null_resume_wrapper: flag type %d is unset\n", type));
     break;
@@ -1046,7 +1045,6 @@
     KF_TRACE(100, ("__kmp_null_resume_wrapper: flag type %d does not match any "
                    "known flag type\n",
                    type));
-#endif
   }
 }
 
diff --git a/runtime/src/z_Windows_NT_util.cpp b/runtime/src/z_Windows_NT_util.cpp
index 9e264ab..d75b48b 100644
--- a/runtime/src/z_Windows_NT_util.cpp
+++ b/runtime/src/z_Windows_NT_util.cpp
@@ -22,6 +22,7 @@
    number of running threads in the system. */
 
 #include <ntsecapi.h> // UNICODE_STRING
+#undef WIN32_NO_STATUS
 #include <ntstatus.h>
 #include <psapi.h>
 #ifdef _MSC_VER
@@ -1635,7 +1636,7 @@
     // threads on all cores. So, we don't consider the running threads of this
     // process.
     if (pid != 0) {
-      for (int i = 0; i < num; ++i) {
+      for (ULONG i = 0; i < num; ++i) {
         THREAD_STATE state = spi->Threads[i].State;
         // Count threads that have Ready or Running state.
         // !!! TODO: Why comment does not match the code???