Skip to content

Commit 4a9f277

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 3cd6eae commit 4a9f277

File tree

24 files changed

+67
-56
lines changed

24 files changed

+67
-56
lines changed

cmake/helpers.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ 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

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/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/queue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2263,7 +2263,7 @@ ur_result_t ur_queue_handle_t_::createCommandList(
22632263
ZeStruct<ze_fence_desc_t> ZeFenceDesc;
22642264
ze_command_list_handle_t ZeCommandList;
22652265

2266-
uint32_t QueueGroupOrdinal;
2266+
uint32_t QueueGroupOrdinal = 0;
22672267
auto &QGroup = getQueueGroup(UseCopyEngine);
22682268
auto &ZeCommandQueue =
22692269
ForcedCmdQueue ? *ForcedCmdQueue : QGroup.getZeQueue(&QueueGroupOrdinal);

source/adapters/opencl/command_buffer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "command_buffer.hpp"
1212
#include "common.hpp"
13+
#include "logger/ur_logger.hpp"
1314

1415
namespace {
1516
ur_result_t
@@ -274,8 +275,7 @@ ur_result_t UR_APICALL urCommandBufferAppendMemBufferWriteExp(
274275
[[maybe_unused]] const ur_exp_command_buffer_sync_point_t
275276
*pSyncPointWaitList,
276277
[[maybe_unused]] ur_exp_command_buffer_sync_point_t *pSyncPoint) {
277-
278-
cl_adapter::die("Experimental Command-buffer feature is not "
278+
logger::warning("Experimental Command-buffer feature is not "
279279
"implemented for OpenCL adapter.");
280280
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
281281
}

source/adapters/opencl/event.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "common.hpp"
1212

13+
#include <limits>
1314
#include <mutex>
1415
#include <set>
1516
#include <unordered_map>
@@ -32,8 +33,7 @@ cl_event_info convertUREventInfoToCL(const ur_event_info_t PropName) {
3233
return CL_EVENT_REFERENCE_COUNT;
3334
break;
3435
default:
35-
return -1;
36-
break;
36+
return std::numeric_limits<cl_event_info>::max();
3737
}
3838
}
3939

@@ -51,7 +51,7 @@ convertURProfilingInfoToCL(const ur_profiling_info_t PropName) {
5151
case UR_PROFILING_INFO_COMMAND_END:
5252
return CL_PROFILING_COMMAND_END;
5353
default:
54-
return -1;
54+
return std::numeric_limits<cl_profiling_info>::max();
5555
}
5656
}
5757

source/adapters/opencl/memory.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//===----------------------------------------------------------------------===//
1010

1111
#include "common.hpp"
12+
#include <limits>
1213

1314
cl_image_format mapURImageFormatToCL(const ur_image_format_t *PImageFormat) {
1415
cl_image_format CLImageFormat;
@@ -59,7 +60,8 @@ cl_image_format mapURImageFormatToCL(const ur_image_format_t *PImageFormat) {
5960
CLImageFormat.image_channel_order = CL_sRGBA;
6061
break;
6162
default:
62-
CLImageFormat.image_channel_order = -1;
63+
CLImageFormat.image_channel_order =
64+
std::numeric_limits<cl_channel_order>::max();
6365
break;
6466
}
6567

@@ -110,7 +112,8 @@ cl_image_format mapURImageFormatToCL(const ur_image_format_t *PImageFormat) {
110112
CLImageFormat.image_channel_data_type = CL_FLOAT;
111113
break;
112114
default:
113-
CLImageFormat.image_channel_data_type = -1;
115+
CLImageFormat.image_channel_data_type =
116+
std::numeric_limits<cl_channel_type>::max();
114117
break;
115118
}
116119

@@ -139,7 +142,7 @@ cl_image_desc mapURImageDescToCL(const ur_image_desc_t *PImageDesc) {
139142
CLImageDesc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
140143
break;
141144
default:
142-
CLImageDesc.image_type = -1;
145+
CLImageDesc.image_type = std::numeric_limits<cl_mem_object_type>::max();
143146
break;
144147
}
145148

source/adapters/opencl/queue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
#include "common.hpp"
1010
#include "platform.hpp"
11+
#include <limits>
1112

1213
cl_command_queue_info mapURQueueInfoToCL(const ur_queue_info_t PropName) {
13-
1414
switch (PropName) {
1515
case UR_QUEUE_INFO_CONTEXT:
1616
return CL_QUEUE_CONTEXT;
@@ -25,7 +25,7 @@ cl_command_queue_info mapURQueueInfoToCL(const ur_queue_info_t PropName) {
2525
case UR_QUEUE_INFO_SIZE:
2626
return CL_QUEUE_SIZE;
2727
default:
28-
return -1;
28+
return std::numeric_limits<cl_command_queue_info>::max();
2929
}
3030
}
3131

source/adapters/opencl/usm_p2p.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,20 @@
88
//
99
//===----------------------------------------------------------------------===//
1010

11-
#include "common.hpp"
11+
#include "logger/ur_logger.hpp"
1212

1313
UR_APIEXPORT ur_result_t UR_APICALL
1414
urUsmP2PEnablePeerAccessExp([[maybe_unused]] ur_device_handle_t commandDevice,
1515
[[maybe_unused]] ur_device_handle_t peerDevice) {
16-
17-
cl_adapter::die(
16+
logger::warning(
1817
"Experimental P2P feature is not implemented for OpenCL adapter.");
1918
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
2019
}
2120

2221
UR_APIEXPORT ur_result_t UR_APICALL
2322
urUsmP2PDisablePeerAccessExp([[maybe_unused]] ur_device_handle_t commandDevice,
2423
[[maybe_unused]] ur_device_handle_t peerDevice) {
25-
26-
cl_adapter::die(
24+
logger::warning(
2725
"Experimental P2P feature is not implemented for OpenCL adapter.");
2826
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
2927
}
@@ -34,8 +32,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urUsmP2PPeerAccessGetInfoExp(
3432
[[maybe_unused]] ur_exp_peer_info_t propName,
3533
[[maybe_unused]] size_t propSize, [[maybe_unused]] void *pPropValue,
3634
[[maybe_unused]] size_t *pPropSizeRet) {
37-
38-
cl_adapter::die(
35+
logger::warning(
3936
"Experimental P2P feature is not implemented for OpenCL adapter.");
4037
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
4138
}

0 commit comments

Comments
 (0)