Skip to content

Commit 10f3296

Browse files
authored
[openmp] Fix warnings when building on Windows with latest MSVC or Clang ToT (#77853)
There were quite a few compilation warnings when building openmp on Windows with the latest Visual Studios 2022 version 17.8.4. Some other warnings were visible with the latest Clang at tip. This commit fixes all of them.
1 parent 55f1229 commit 10f3296

File tree

8 files changed

+60
-34
lines changed

8 files changed

+60
-34
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: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#endif
2929
#include <ctype.h>
3030

31+
#include "llvm/Support/Compiler.h"
32+
3133
// The machine topology
3234
kmp_topology_t *__kmp_topology = nullptr;
3335
// KMP_HW_SUBSET environment variable
@@ -127,8 +129,12 @@ const char *__kmp_hw_get_catalog_string(kmp_hw_t type, bool plural) {
127129
return ((plural) ? KMP_I18N_STR(Threads) : KMP_I18N_STR(Thread));
128130
case KMP_HW_PROC_GROUP:
129131
return ((plural) ? KMP_I18N_STR(ProcGroups) : KMP_I18N_STR(ProcGroup));
132+
case KMP_HW_UNKNOWN:
133+
case KMP_HW_LAST:
134+
return KMP_I18N_STR(Unknown);
130135
}
131-
return KMP_I18N_STR(Unknown);
136+
KMP_ASSERT2(false, "Unhandled kmp_hw_t enumeration");
137+
LLVM_BUILTIN_UNREACHABLE;
132138
}
133139

134140
const char *__kmp_hw_get_keyword(kmp_hw_t type, bool plural) {
@@ -157,13 +163,18 @@ const char *__kmp_hw_get_keyword(kmp_hw_t type, bool plural) {
157163
return ((plural) ? "threads" : "thread");
158164
case KMP_HW_PROC_GROUP:
159165
return ((plural) ? "proc_groups" : "proc_group");
166+
case KMP_HW_UNKNOWN:
167+
case KMP_HW_LAST:
168+
return ((plural) ? "unknowns" : "unknown");
160169
}
161-
return ((plural) ? "unknowns" : "unknown");
170+
KMP_ASSERT2(false, "Unhandled kmp_hw_t enumeration");
171+
LLVM_BUILTIN_UNREACHABLE;
162172
}
163173

164174
const char *__kmp_hw_get_core_type_string(kmp_hw_core_type_t type) {
165175
switch (type) {
166176
case KMP_HW_CORE_TYPE_UNKNOWN:
177+
case KMP_HW_MAX_NUM_CORE_TYPES:
167178
return "unknown";
168179
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
169180
case KMP_HW_CORE_TYPE_ATOM:
@@ -172,7 +183,8 @@ const char *__kmp_hw_get_core_type_string(kmp_hw_core_type_t type) {
172183
return "Intel(R) Core(TM) processor";
173184
#endif
174185
}
175-
return "unknown";
186+
KMP_ASSERT2(false, "Unhandled kmp_hw_core_type_t enumeration");
187+
LLVM_BUILTIN_UNREACHABLE;
176188
}
177189

178190
#if KMP_AFFINITY_SUPPORTED
@@ -1238,17 +1250,18 @@ bool kmp_topology_t::filter_hw_subset() {
12381250
struct core_type_indexer {
12391251
int operator()(const kmp_hw_thread_t &t) const {
12401252
switch (t.attrs.get_core_type()) {
1253+
case KMP_HW_CORE_TYPE_UNKNOWN:
1254+
case KMP_HW_MAX_NUM_CORE_TYPES:
1255+
return 0;
12411256
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
12421257
case KMP_HW_CORE_TYPE_ATOM:
12431258
return 1;
12441259
case KMP_HW_CORE_TYPE_CORE:
12451260
return 2;
12461261
#endif
1247-
case KMP_HW_CORE_TYPE_UNKNOWN:
1248-
return 0;
12491262
}
1250-
KMP_ASSERT(0);
1251-
return 0;
1263+
KMP_ASSERT2(false, "Unhandled kmp_hw_thread_t enumeration");
1264+
LLVM_BUILTIN_UNREACHABLE;
12521265
}
12531266
};
12541267
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: 2 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) {

openmp/runtime/src/kmp_settings.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include "ompd-specific.h"
3030
#endif
3131

32+
#include "llvm/Support/Compiler.h"
33+
3234
static int __kmp_env_toPrint(char const *name, int flag);
3335

3436
bool __kmp_env_format = 0; // 0 - old format; 1 - new format
@@ -873,6 +875,10 @@ static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer, char const *name,
873875
case library_throughput: {
874876
value = "PASSIVE";
875877
} break;
878+
case library_none:
879+
case library_serial: {
880+
value = NULL;
881+
} break;
876882
}
877883
} else {
878884
switch (__kmp_library) {
@@ -885,6 +891,9 @@ static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer, char const *name,
885891
case library_throughput: {
886892
value = "throughput";
887893
} break;
894+
case library_none: {
895+
value = NULL;
896+
} break;
888897
}
889898
}
890899
if (value != NULL) {
@@ -2004,6 +2013,7 @@ static inline const char *
20042013
__kmp_hw_get_core_type_keyword(kmp_hw_core_type_t type) {
20052014
switch (type) {
20062015
case KMP_HW_CORE_TYPE_UNKNOWN:
2016+
case KMP_HW_MAX_NUM_CORE_TYPES:
20072017
return "unknown";
20082018
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
20092019
case KMP_HW_CORE_TYPE_ATOM:
@@ -2012,7 +2022,8 @@ __kmp_hw_get_core_type_keyword(kmp_hw_core_type_t type) {
20122022
return "intel_core";
20132023
#endif
20142024
}
2015-
return "unknown";
2025+
KMP_ASSERT2(false, "Unhandled kmp_hw_core_type_t enumeration");
2026+
LLVM_BUILTIN_UNREACHABLE;
20162027
}
20172028

20182029
#if KMP_AFFINITY_SUPPORTED
@@ -4428,6 +4439,10 @@ static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
44284439
case kmp_sch_auto:
44294440
__kmp_str_buf_print(buffer, "%s,%d'\n", "auto", __kmp_chunk);
44304441
break;
4442+
default:
4443+
KMP_ASSERT2(false, "Unhandled sched_type enumeration");
4444+
LLVM_BUILTIN_UNREACHABLE;
4445+
break;
44314446
}
44324447
} else {
44334448
switch (sched) {
@@ -4453,6 +4468,10 @@ static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
44534468
case kmp_sch_auto:
44544469
__kmp_str_buf_print(buffer, "%s'\n", "auto");
44554470
break;
4471+
default:
4472+
KMP_ASSERT2(false, "Unhandled sched_type enumeration");
4473+
LLVM_BUILTIN_UNREACHABLE;
4474+
break;
44564475
}
44574476
}
44584477
} // __kmp_stg_print_omp_schedule

openmp/runtime/src/kmp_wait_release.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "ompt-specific.h"
2121
#endif
2222

23+
#include "llvm/Support/Compiler.h"
24+
2325
/*!
2426
@defgroup WAIT_RELEASE Wait/Release operations
2527
@@ -1038,15 +1040,14 @@ static inline void __kmp_null_resume_wrapper(kmp_info_t *thr) {
10381040
case flag_oncore:
10391041
__kmp_resume_oncore(gtid, RCAST(kmp_flag_oncore *, flag));
10401042
break;
1041-
#ifdef KMP_DEBUG
10421043
case flag_unset:
10431044
KF_TRACE(100, ("__kmp_null_resume_wrapper: flag type %d is unset\n", type));
10441045
break;
10451046
default:
10461047
KF_TRACE(100, ("__kmp_null_resume_wrapper: flag type %d does not match any "
10471048
"known flag type\n",
10481049
type));
1049-
#endif
1050+
LLVM_BUILTIN_UNREACHABLE;
10501051
}
10511052
}
10521053

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)