Skip to content

Commit 1c9da05

Browse files
committed
Raise MSVC warning level from /W3 to /W4
This patch increases the warning level when using the MSVC compiler from `/W3` to `/W4` and fixes the issues found. Four warnings introduced by `/W4` are disabled, all related to variable name shadowing, as they overly prescriptive to valid code.
1 parent 1f13d2c commit 1c9da05

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+130
-96
lines changed

cmake/helpers.cmake

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,25 @@ function(add_ur_target_compile_options name)
8282
elseif(MSVC)
8383
target_compile_options(${name} PRIVATE
8484
$<$<CXX_COMPILER_ID:MSVC>:/MP> # clang-cl.exe does not support /MP
85-
/W3
85+
/W4
86+
/wd4456 # Disable: declaration of 'identifier' hides previous local declaration
87+
/wd4457 # Disable: declaration of 'identifier' hides function parameter
88+
/wd4458 # Disable: declaration of 'identifier' hides class member
89+
/wd4459 # Disable: declaration of 'identifier' hides global declaration
8690
/MD$<$<CONFIG:Debug>:d>
8791
/GS
8892
/DWIN32_LEAN_AND_MEAN
8993
/DNOMINMAX
9094
)
9195

92-
if(UR_DEVELOPER_MODE)
96+
target_compile_definitions(${name} PRIVATE
9397
# _CRT_SECURE_NO_WARNINGS used mainly because of getenv
94-
# C4267: The compiler detected a conversion from size_t to a smaller type.
98+
_CRT_SECURE_NO_WARNINGS
99+
)
100+
101+
if(UR_DEVELOPER_MODE)
95102
target_compile_options(${name} PRIVATE
96-
/WX /GS /D_CRT_SECURE_NO_WARNINGS /wd4267
103+
/WX /GS
97104
)
98105
endif()
99106
endif()

examples/collector/collector.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@
2525
#include <string_view>
2626

2727
#include "ur_api.h"
28+
29+
#ifdef _MSC_VER
30+
#pragma warning(disable : 4245)
31+
#endif
2832
#include "xpti/xpti_trace_framework.h"
33+
#ifdef _MSC_VER
34+
#pragma warning(default : 4245)
35+
#endif
2936

3037
constexpr uint16_t TRACE_FN_BEGIN =
3138
static_cast<uint16_t>(xpti::trace_point_type_t::function_with_args_begin);

include/ur_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ typedef struct ur_physical_mem_handle_t_ *ur_physical_mem_handle_t;
422422
///////////////////////////////////////////////////////////////////////////////
423423
#ifndef UR_BIT
424424
/// @brief Generic macro for enumerator bit masks
425-
#define UR_BIT(_i) (1 << _i)
425+
#define UR_BIT(_i) (1U << _i)
426426
#endif // UR_BIT
427427

428428
///////////////////////////////////////////////////////////////////////////////

scripts/core/common.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ name: "$x_physical_mem_handle_t"
134134
type: macro
135135
desc: "Generic macro for enumerator bit masks"
136136
name: "$X_BIT( _i )"
137-
value: "( 1 << _i )"
137+
value: "( 1U << _i )"
138138
--- #--------------------------------------------------------------------------
139139
type: enum
140140
desc: "Defines Return/Error codes"

source/adapters/level_zero/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ if (NOT DEFINED LEVEL_ZERO_LIBRARY OR NOT DEFINED LEVEL_ZERO_INCLUDE_DIR)
6565

6666
target_compile_options(ze_loader PRIVATE
6767
$<$<IN_LIST:$<CXX_COMPILER_ID>,GNU;Clang;Intel;IntelLLVM>:-Wno-error>
68-
$<$<CXX_COMPILER_ID:MSVC>:/WX- /UUNICODE>
68+
$<$<CXX_COMPILER_ID:MSVC>:/UUNICODE>
6969
)
7070

7171
set(LEVEL_ZERO_LIBRARY ze_loader)
@@ -163,8 +163,9 @@ if(UR_BUILD_ADAPTER_L0)
163163
endif()
164164

165165
# TODO: fix level_zero adapter conversion warnings
166+
# C4267: The compiler detected a conversion from size_t to a smaller type.
166167
target_compile_options(ur_adapter_level_zero PRIVATE
167-
$<$<CXX_COMPILER_ID:MSVC>:/wd4805 /wd4244>
168+
$<$<CXX_COMPILER_ID:MSVC>:/wd4805 /wd4244 /wd4267>
168169
)
169170

170171
set_target_properties(ur_adapter_level_zero PROPERTIES
@@ -256,7 +257,7 @@ if(UR_BUILD_ADAPTER_L0_V2)
256257

257258
# TODO: fix level_zero adapter conversion warnings
258259
target_compile_options(ur_adapter_level_zero_v2 PRIVATE
259-
$<$<CXX_COMPILER_ID:MSVC>:/wd4805 /wd4244>
260+
$<$<CXX_COMPILER_ID:MSVC>:/wd4805 /wd4244 /wd4100 /wd4267>
260261
)
261262

262263
set_target_properties(ur_adapter_level_zero_v2 PROPERTIES

source/adapters/level_zero/adapter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,5 @@ ur_result_t urAdapterGetInfo(ur_adapter_handle_t, ur_adapter_info_t PropName,
450450
default:
451451
return UR_RESULT_ERROR_INVALID_ENUMERATION;
452452
}
453-
454-
return UR_RESULT_SUCCESS;
455453
}
456454
} // namespace ur::level_zero

source/adapters/level_zero/context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ ur_result_t ur_context_handle_t_::getAvailableCommandList(
756756
// queue's map to hold the fence and other associated command
757757
// list information.
758758
auto &QGroup = Queue->getQueueGroup(UseCopyEngine);
759-
uint32_t QueueGroupOrdinal;
759+
uint32_t QueueGroupOrdinal = 0;
760760
auto &ZeCommandQueue = ForcedCmdQueue
761761
? *ForcedCmdQueue
762762
: QGroup.getZeQueue(&QueueGroupOrdinal);

source/adapters/level_zero/device.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ ur_result_t urDeviceGet(
155155
}
156156
}
157157

158-
uint32_t ZeDeviceCount = MatchedDevices.size();
158+
uint32_t ZeDeviceCount = static_cast<uint32_t>(MatchedDevices.size());
159159

160160
auto N = (std::min)(ZeDeviceCount, NumEntries);
161161
if (Devices)
@@ -318,9 +318,10 @@ ur_result_t urDeviceGetInfo(
318318
Device->QueueGroup[ur_device_handle_t_::queue_group_info_t::Compute]
319319
.ZeIndex >= 0;
320320
if (RepresentsCSlice)
321-
MaxComputeUnits /= Device->RootDevice->SubDevices.size();
321+
MaxComputeUnits /=
322+
static_cast<uint32_t>(Device->RootDevice->SubDevices.size());
322323

323-
return ReturnValue(uint32_t{MaxComputeUnits});
324+
return ReturnValue(MaxComputeUnits);
324325
}
325326
case UR_DEVICE_INFO_MAX_WORK_ITEM_DIMENSIONS:
326327
// Level Zero spec defines only three dimensions
@@ -422,7 +423,8 @@ ur_result_t urDeviceGetInfo(
422423
return Res;
423424
}
424425

425-
uint32_t ZeSubDeviceCount = Device->SubDevices.size();
426+
uint32_t ZeSubDeviceCount =
427+
static_cast<uint32_t>(Device->SubDevices.size());
426428
if (pSize && ZeSubDeviceCount < 2) {
427429
*pSize = 0;
428430
return UR_RESULT_SUCCESS;
@@ -1151,8 +1153,6 @@ ur_result_t urDeviceGetInfo(
11511153
logger::toHex(ParamName));
11521154
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
11531155
}
1154-
1155-
return UR_RESULT_SUCCESS;
11561156
}
11571157

11581158
bool CopyEngineRequested(const ur_device_handle_t &Device) {
@@ -1200,7 +1200,7 @@ ur_result_t urDevicePartition(
12001200
return Res;
12011201
}
12021202

1203-
auto EffectiveNumDevices = [&]() -> decltype(Device->SubDevices.size()) {
1203+
auto EffectiveNumDevices = [&]() -> uint32_t {
12041204
if (Device->SubDevices.size() == 0)
12051205
return 0;
12061206

@@ -1223,7 +1223,7 @@ ur_result_t urDevicePartition(
12231223
}
12241224
}
12251225

1226-
return Device->SubDevices.size();
1226+
return static_cast<uint32_t>(Device->SubDevices.size());
12271227
}();
12281228

12291229
// TODO: Consider support for partitioning to <= total sub-devices.

source/adapters/level_zero/event.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,6 @@ ur_result_t urEventGetInfo(
494494
PropName, logger::toHex(PropName));
495495
return UR_RESULT_ERROR_INVALID_VALUE;
496496
}
497-
498-
return UR_RESULT_SUCCESS;
499497
}
500498

501499
ur_result_t urEventGetProfilingInfo(

source/adapters/level_zero/platform.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ ur_result_t urPlatformGetInfo(
9999
logger::debug("urPlatformGetInfo: unrecognized ParamName");
100100
return UR_RESULT_ERROR_INVALID_VALUE;
101101
}
102-
103-
return UR_RESULT_SUCCESS;
104102
}
105103

106104
ur_result_t urPlatformGetApiVersion(

0 commit comments

Comments
 (0)