Skip to content

Commit 6a0b9b3

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 1d1808a commit 6a0b9b3

File tree

29 files changed

+97
-59
lines changed

29 files changed

+97
-59
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

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: 2 additions & 2 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)
@@ -256,7 +256,7 @@ if(UR_BUILD_ADAPTER_L0_V2)
256256

257257
# TODO: fix level_zero adapter conversion warnings
258258
target_compile_options(ur_adapter_level_zero_v2 PRIVATE
259-
$<$<CXX_COMPILER_ID:MSVC>:/wd4805 /wd4244>
259+
$<$<CXX_COMPILER_ID:MSVC>:/wd4805 /wd4244 /wd4100>
260260
)
261261

262262
set_target_properties(ur_adapter_level_zero_v2 PROPERTIES

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,4 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t,
9898
default:
9999
return UR_RESULT_ERROR_INVALID_ENUMERATION;
100100
}
101-
102-
return UR_RESULT_SUCCESS;
103101
}

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

0 commit comments

Comments
 (0)