Skip to content

Commit 15fdc76

Browse files
committed
Re-land [openmp] Fix warnings when building on Windows with latest MSVC or Clang ToT (#77853)
The reverts 94f9609 and fixes it.
1 parent 6a7abea commit 15fdc76

File tree

8 files changed

+67
-38
lines changed

8 files changed

+67
-38
lines changed

openmp/cmake/HandleOpenMPOptions.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,12 @@ append_if(OPENMP_HAVE_WMAYBE_UNINITIALIZED_FLAG "-Wno-maybe-uninitialized" CMAKE
4141
append_if(OPENMP_HAVE_NO_SEMANTIC_INTERPOSITION "-fno-semantic-interposition" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
4242
append_if(OPENMP_HAVE_FUNCTION_SECTIONS "-ffunction-section" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
4343
append_if(OPENMP_HAVE_DATA_SECTIONS "-fdata-sections" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
44+
45+
if (MSVC)
46+
# Disable "warning C4201: nonstandard extension used: nameless struct/union"
47+
append("-wd4201" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
48+
49+
# Disable "warning C4190: '__kmpc_atomic_cmplx8_rd' has C-linkage specified, but returns
50+
# UDT '__kmp_cmplx64_t' which is incompatible with C"
51+
append("-wd4190" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
52+
endif()

openmp/runtime/src/kmp_affinity.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,12 @@ const char *__kmp_hw_get_catalog_string(kmp_hw_t type, bool plural) {
127127
return ((plural) ? KMP_I18N_STR(Threads) : KMP_I18N_STR(Thread));
128128
case KMP_HW_PROC_GROUP:
129129
return ((plural) ? KMP_I18N_STR(ProcGroups) : KMP_I18N_STR(ProcGroup));
130+
case KMP_HW_UNKNOWN:
131+
case KMP_HW_LAST:
132+
return KMP_I18N_STR(Unknown);
130133
}
131-
return KMP_I18N_STR(Unknown);
134+
KMP_ASSERT2(false, "Unhandled kmp_hw_t enumeration");
135+
KMP_BUILTIN_UNREACHABLE;
132136
}
133137

134138
const char *__kmp_hw_get_keyword(kmp_hw_t type, bool plural) {
@@ -157,13 +161,18 @@ const char *__kmp_hw_get_keyword(kmp_hw_t type, bool plural) {
157161
return ((plural) ? "threads" : "thread");
158162
case KMP_HW_PROC_GROUP:
159163
return ((plural) ? "proc_groups" : "proc_group");
164+
case KMP_HW_UNKNOWN:
165+
case KMP_HW_LAST:
166+
return ((plural) ? "unknowns" : "unknown");
160167
}
161-
return ((plural) ? "unknowns" : "unknown");
168+
KMP_ASSERT2(false, "Unhandled kmp_hw_t enumeration");
169+
KMP_BUILTIN_UNREACHABLE;
162170
}
163171

164172
const char *__kmp_hw_get_core_type_string(kmp_hw_core_type_t type) {
165173
switch (type) {
166174
case KMP_HW_CORE_TYPE_UNKNOWN:
175+
case KMP_HW_MAX_NUM_CORE_TYPES:
167176
return "unknown";
168177
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
169178
case KMP_HW_CORE_TYPE_ATOM:
@@ -172,7 +181,8 @@ const char *__kmp_hw_get_core_type_string(kmp_hw_core_type_t type) {
172181
return "Intel(R) Core(TM) processor";
173182
#endif
174183
}
175-
return "unknown";
184+
KMP_ASSERT2(false, "Unhandled kmp_hw_core_type_t enumeration");
185+
KMP_BUILTIN_UNREACHABLE;
176186
}
177187

178188
#if KMP_AFFINITY_SUPPORTED
@@ -1238,17 +1248,18 @@ bool kmp_topology_t::filter_hw_subset() {
12381248
struct core_type_indexer {
12391249
int operator()(const kmp_hw_thread_t &t) const {
12401250
switch (t.attrs.get_core_type()) {
1251+
case KMP_HW_CORE_TYPE_UNKNOWN:
1252+
case KMP_HW_MAX_NUM_CORE_TYPES:
1253+
return 0;
12411254
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
12421255
case KMP_HW_CORE_TYPE_ATOM:
12431256
return 1;
12441257
case KMP_HW_CORE_TYPE_CORE:
12451258
return 2;
12461259
#endif
1247-
case KMP_HW_CORE_TYPE_UNKNOWN:
1248-
return 0;
12491260
}
1250-
KMP_ASSERT(0);
1251-
return 0;
1261+
KMP_ASSERT2(false, "Unhandled kmp_hw_thread_t enumeration");
1262+
KMP_BUILTIN_UNREACHABLE;
12521263
}
12531264
};
12541265
struct core_eff_indexer {

openmp/runtime/src/kmp_barrier.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,11 +2403,11 @@ void __kmp_fork_barrier(int gtid, int tid) {
24032403
#if USE_ITT_BUILD
24042404
void *itt_sync_obj = NULL;
24052405
#endif /* USE_ITT_BUILD */
2406+
#ifdef KMP_DEBUG
24062407
if (team)
2407-
2408-
KA_TRACE(10, ("__kmp_fork_barrier: T#%d(%d:%d) has arrived\n", gtid,
2409-
(team != NULL) ? team->t.t_id : -1, tid));
2410-
2408+
KA_TRACE(10, ("__kmp_fork_barrier: T#%d(%d:%d) has arrived\n", gtid,
2409+
(team != NULL) ? team->t.t_id : -1, tid));
2410+
#endif
24112411
// th_team pointer only valid for primary thread here
24122412
if (KMP_MASTER_TID(tid)) {
24132413
#if USE_ITT_BUILD && USE_ITT_NOTIFY

openmp/runtime/src/kmp_io.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,6 @@ static HANDLE __kmp_stderr = NULL;
5050
static int __kmp_console_exists = FALSE;
5151
static kmp_str_buf_t __kmp_console_buf;
5252

53-
static int is_console(void) {
54-
char buffer[128];
55-
DWORD rc = 0;
56-
DWORD err = 0;
57-
// Try to get console title.
58-
SetLastError(0);
59-
// GetConsoleTitle does not reset last error in case of success or short
60-
// buffer, so we need to clear it explicitly.
61-
rc = GetConsoleTitle(buffer, sizeof(buffer));
62-
if (rc == 0) {
63-
// rc == 0 means getting console title failed. Let us find out why.
64-
err = GetLastError();
65-
// err == 0 means buffer too short (we suppose console exists).
66-
// In Window applications we usually have err == 6 (invalid handle).
67-
}
68-
return rc > 0 || err == 0;
69-
}
70-
7153
void __kmp_close_console(void) {
7254
/* wait until user presses return before closing window */
7355
/* TODO only close if a window was opened */
@@ -84,7 +66,6 @@ void __kmp_close_console(void) {
8466
static void __kmp_redirect_output(void) {
8567
__kmp_acquire_bootstrap_lock(&__kmp_console_lock);
8668

87-
(void)is_console;
8869
if (!__kmp_console_exists) {
8970
HANDLE ho;
9071
HANDLE he;

openmp/runtime/src/kmp_os.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ template <> struct traits_t<unsigned long long> {
306306
!KMP_MIC)
307307

308308
#if KMP_OS_WINDOWS
309+
// Don't include everything related to NT status code, we'll do that explicitly
310+
#define WIN32_NO_STATUS
309311
#include <windows.h>
310312

311313
static inline int KMP_GET_PAGE_SIZE(void) {
@@ -1297,4 +1299,18 @@ extern void *__kmp_lookup_symbol(const char *name, bool next = false);
12971299
#define KMP_DLSYM_NEXT(name) dlsym(RTLD_NEXT, name)
12981300
#endif
12991301

1302+
// MSVC doesn't have this, but clang/clang-cl does.
1303+
#ifndef __has_builtin
1304+
#define __has_builtin(x) 0
1305+
#endif
1306+
1307+
// Same as LLVM_BUILTIN_UNREACHABLE. States that it is UB to reach this point.
1308+
#if __has_builtin(__builtin_unreachable) || defined(__GNUC__)
1309+
#define KMP_BUILTIN_UNREACHABLE __builtin_unreachable()
1310+
#elif defined(_MSC_VER)
1311+
#define KMP_BUILTIN_UNREACHABLE __assume(false)
1312+
#else
1313+
#define KMP_BUILTIN_UNREACHABLE
1314+
#endif
1315+
13001316
#endif /* KMP_OS_H */

openmp/runtime/src/kmp_settings.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,10 @@ static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer, char const *name,
873873
case library_throughput: {
874874
value = "PASSIVE";
875875
} break;
876+
case library_none:
877+
case library_serial: {
878+
value = NULL;
879+
} break;
876880
}
877881
} else {
878882
switch (__kmp_library) {
@@ -885,6 +889,9 @@ static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer, char const *name,
885889
case library_throughput: {
886890
value = "throughput";
887891
} break;
892+
case library_none: {
893+
value = NULL;
894+
} break;
888895
}
889896
}
890897
if (value != NULL) {
@@ -2004,6 +2011,7 @@ static inline const char *
20042011
__kmp_hw_get_core_type_keyword(kmp_hw_core_type_t type) {
20052012
switch (type) {
20062013
case KMP_HW_CORE_TYPE_UNKNOWN:
2014+
case KMP_HW_MAX_NUM_CORE_TYPES:
20072015
return "unknown";
20082016
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
20092017
case KMP_HW_CORE_TYPE_ATOM:
@@ -2012,7 +2020,8 @@ __kmp_hw_get_core_type_keyword(kmp_hw_core_type_t type) {
20122020
return "intel_core";
20132021
#endif
20142022
}
2015-
return "unknown";
2023+
KMP_ASSERT2(false, "Unhandled kmp_hw_core_type_t enumeration");
2024+
KMP_BUILTIN_UNREACHABLE;
20162025
}
20172026

20182027
#if KMP_AFFINITY_SUPPORTED
@@ -4428,6 +4437,10 @@ static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
44284437
case kmp_sch_auto:
44294438
__kmp_str_buf_print(buffer, "%s,%d'\n", "auto", __kmp_chunk);
44304439
break;
4440+
default:
4441+
KMP_ASSERT2(false, "Unhandled sched_type enumeration");
4442+
KMP_BUILTIN_UNREACHABLE;
4443+
break;
44314444
}
44324445
} else {
44334446
switch (sched) {
@@ -4453,6 +4466,10 @@ static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
44534466
case kmp_sch_auto:
44544467
__kmp_str_buf_print(buffer, "%s'\n", "auto");
44554468
break;
4469+
default:
4470+
KMP_ASSERT2(false, "Unhandled sched_type enumeration");
4471+
KMP_BUILTIN_UNREACHABLE;
4472+
break;
44564473
}
44574474
}
44584475
} // __kmp_stg_print_omp_schedule

openmp/runtime/src/kmp_wait_release.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,15 +1038,9 @@ static inline void __kmp_null_resume_wrapper(kmp_info_t *thr) {
10381038
case flag_oncore:
10391039
__kmp_resume_oncore(gtid, RCAST(kmp_flag_oncore *, flag));
10401040
break;
1041-
#ifdef KMP_DEBUG
10421041
case flag_unset:
10431042
KF_TRACE(100, ("__kmp_null_resume_wrapper: flag type %d is unset\n", type));
10441043
break;
1045-
default:
1046-
KF_TRACE(100, ("__kmp_null_resume_wrapper: flag type %d does not match any "
1047-
"known flag type\n",
1048-
type));
1049-
#endif
10501044
}
10511045
}
10521046

openmp/runtime/src/z_Windows_NT_util.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
number of running threads in the system. */
2323

2424
#include <ntsecapi.h> // UNICODE_STRING
25+
#undef WIN32_NO_STATUS
2526
#include <ntstatus.h>
2627
#include <psapi.h>
2728
#ifdef _MSC_VER
@@ -1635,7 +1636,7 @@ int __kmp_get_load_balance(int max) {
16351636
// threads on all cores. So, we don't consider the running threads of this
16361637
// process.
16371638
if (pid != 0) {
1638-
for (int i = 0; i < num; ++i) {
1639+
for (ULONG i = 0; i < num; ++i) {
16391640
THREAD_STATE state = spi->Threads[i].State;
16401641
// Count threads that have Ready or Running state.
16411642
// !!! TODO: Why comment does not match the code???

0 commit comments

Comments
 (0)