Skip to content

Commit d4e51db

Browse files
[SYCL] Fix various runtime compilation warnings (#2980)
* [SYCL] Fix various runtime compilation warnings - implicit conversion of string to bool - unused variables - default label in switch which covers all enumeration items - unannotated fall-through in switch Co-authored-by: Vyacheslav N Klochkov <[email protected]>
1 parent b83a1a8 commit d4e51db

File tree

13 files changed

+70
-37
lines changed

13 files changed

+70
-37
lines changed

sycl/include/CL/sycl/detail/defines_elementary.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
#define __has_builtin(x) 0
2323
#endif // __has_builtin
2424

25+
#ifndef __SYCL_ALWAYS_INLINE
2526
#if __has_attribute(always_inline)
2627
#define __SYCL_ALWAYS_INLINE __attribute__((always_inline))
2728
#else
2829
#define __SYCL_ALWAYS_INLINE
2930
#endif
31+
#endif // __SYCL_ALWAYS_INLINE
3032

3133
#ifndef SYCL_EXTERNAL
3234
#define SYCL_EXTERNAL
@@ -36,15 +38,42 @@
3638
#define __SYCL_ID_QUERIES_FIT_IN_INT__ 0
3739
#endif
3840

41+
#ifndef __SYCL_DEPRECATED
3942
#ifdef _WIN32
4043
#define __SYCL_DEPRECATED(message) __declspec(deprecated(message))
4144
#else
4245
#define __SYCL_DEPRECATED(message) __attribute__((deprecated(message)))
4346
#endif
47+
#endif // __SYCL_DEPRECATED
4448

49+
#ifndef __SYCL_INLINE_CONSTEXPR
4550
// inline constexpr is a C++17 feature
4651
#if __cplusplus >= 201703L
4752
#define __SYCL_INLINE_CONSTEXPR inline constexpr
4853
#else
4954
#define __SYCL_INLINE_CONSTEXPR static constexpr
5055
#endif
56+
#endif // __SYCL_INLINE_CONSTEXPR
57+
58+
#ifndef __SYCL_HAS_CPP_ATTRIBUTE
59+
#if defined(__cplusplus) && defined(__has_cpp_attribute)
60+
#define __SYCL_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
61+
#else
62+
#define __SYCL_HAS_CPP_ATTRIBUTE(x) 0
63+
#endif
64+
#endif
65+
66+
#ifndef __SYCL_FALLTHROUGH
67+
#if defined(__cplusplus) && __cplusplus > 201402L && \
68+
__SYCL_HAS_CPP_ATTRIBUTE(fallthrough)
69+
#define __SYCL_FALLTHROUGH [[fallthrough]]
70+
#elif __SYCL_HAS_CPP_ATTRIBUTE(gnu::fallthrough)
71+
#define __SYCL_FALLTHROUGH [[gnu::fallthrough]]
72+
#elif __has_attribute(fallthrough)
73+
#define __SYCL_FALLTHROUGH __attribute__((fallthrough))
74+
#elif __SYCL_HAS_CPP_ATTRIBUTE(clang::fallthrough)
75+
#define __SYCL_FALLTHROUGH [[clang::fallthrough]]
76+
#else
77+
#define __SYCL_FALLTHROUGH
78+
#endif
79+
#endif // __SYCL_FALLTHROUGH

sycl/include/CL/sycl/types.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,9 @@ detail::enable_if_t<is_float_to_int<T, R>::value, R> convertImpl(T Value) {
296296
// Round toward negative infinity.
297297
case rounding_mode::rtn:
298298
return std::floor(Value);
299-
default:
300-
assert(!"Unsupported rounding mode!");
301-
return static_cast<R>(Value);
302299
};
300+
assert(false && "Unsupported rounding mode!");
301+
return static_cast<R>(Value);
303302
}
304303
#else
305304

sycl/source/detail/builtins_math.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,12 +609,15 @@ MAKE_1V_2P(modf, s::cl_half, s::cl_half, s::cl_half)
609609

610610
// nan
611611
__SYCL_EXPORT s::cl_float nan(s::cl_uint nancode) __NOEXC {
612+
(void)nancode;
612613
return d::quiet_NaN<s::cl_float>();
613614
}
614615
__SYCL_EXPORT s::cl_double nan(s::cl_ulong nancode) __NOEXC {
616+
(void)nancode;
615617
return d::quiet_NaN<s::cl_double>();
616618
}
617619
__SYCL_EXPORT s::cl_half nan(s::cl_ushort nancode) __NOEXC {
620+
(void)nancode;
618621
return s::cl_half(d::quiet_NaN<s::cl_float>());
619622
}
620623
MAKE_1V(nan, s::cl_float, s::cl_uint)

sycl/source/detail/image_impl.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ uint8_t getImageNumberChannels(image_channel_order Order) {
6262
case image_channel_order::abgr:
6363
return 4;
6464
}
65-
assert(!"Unhandled image channel order");
65+
assert(false && "Unhandled image channel order");
6666
return 0;
6767
}
6868

@@ -95,8 +95,6 @@ uint8_t getImageElementSize(uint8_t NumChannels, image_channel_type Type) {
9595
case image_channel_type::unorm_int_101010:
9696
Retval = 4;
9797
break;
98-
default:
99-
assert(!"Unhandled image channel type");
10098
}
10199
// OpenCL states that "The number of bits per element determined by the
102100
// image_channel_type and image_channel_order must be a power of two"
@@ -135,11 +133,9 @@ RT::PiMemImageChannelOrder convertChannelOrder(image_channel_order Order) {
135133
return PI_IMAGE_CHANNEL_ORDER_LUMINANCE;
136134
case image_channel_order::abgr:
137135
return PI_IMAGE_CHANNEL_ORDER_ABGR;
138-
default: {
139-
assert(!"Unhandled image_channel_order");
140-
return static_cast<RT::PiMemImageChannelOrder>(0);
141-
}
142136
}
137+
assert(false && "Unhandled image_channel_order");
138+
return static_cast<RT::PiMemImageChannelOrder>(0);
143139
}
144140

145141
image_channel_order convertChannelOrder(RT::PiMemImageChannelOrder Order) {
@@ -172,11 +168,9 @@ image_channel_order convertChannelOrder(RT::PiMemImageChannelOrder Order) {
172168
return image_channel_order::luminance;
173169
case PI_IMAGE_CHANNEL_ORDER_ABGR:
174170
return image_channel_order::abgr;
175-
default: {
176-
assert(!"Unhandled image_channel_order");
177-
return static_cast<image_channel_order>(0);
178-
}
179171
}
172+
assert(false && "Unhandled image_channel_order");
173+
return static_cast<image_channel_order>(0);
180174
}
181175

182176
RT::PiMemImageChannelType convertChannelType(image_channel_type Type) {
@@ -211,11 +205,9 @@ RT::PiMemImageChannelType convertChannelType(image_channel_type Type) {
211205
return PI_IMAGE_CHANNEL_TYPE_HALF_FLOAT;
212206
case image_channel_type::fp32:
213207
return PI_IMAGE_CHANNEL_TYPE_FLOAT;
214-
default: {
215-
assert(!"Unhandled image_channel_order");
216-
return static_cast<RT::PiMemImageChannelType>(0);
217-
}
218208
}
209+
assert(false && "Unhandled image_channel_order");
210+
return static_cast<RT::PiMemImageChannelType>(0);
219211
}
220212

221213
image_channel_type convertChannelType(RT::PiMemImageChannelType Type) {
@@ -250,11 +242,9 @@ image_channel_type convertChannelType(RT::PiMemImageChannelType Type) {
250242
return image_channel_type::fp16;
251243
case PI_IMAGE_CHANNEL_TYPE_FLOAT:
252244
return image_channel_type::fp32;
253-
default: {
254-
assert(!"Unhandled image_channel_order");
255-
return static_cast<image_channel_type>(0);
256-
}
257245
}
246+
assert(false && "Unhandled image_channel_order");
247+
return static_cast<image_channel_type>(0);
258248
}
259249

260250
template <typename T>
@@ -294,10 +284,10 @@ image_impl<Dimensions>::image_impl(
294284
switch (Dimensions) {
295285
case 3:
296286
getImageInfo(Context, PI_IMAGE_INFO_DEPTH, MRange[2], Mem);
297-
// fall through
287+
__SYCL_FALLTHROUGH;
298288
case 2:
299289
getImageInfo(Context, PI_IMAGE_INFO_HEIGHT, MRange[1], Mem);
300-
// fall through
290+
__SYCL_FALLTHROUGH;
301291
case 1:
302292
getImageInfo(Context, PI_IMAGE_INFO_WIDTH, MRange[0], Mem);
303293
}
@@ -407,6 +397,7 @@ bool image_impl<Dimensions>::checkImageDesc(const RT::PiMemImageDesc &Desc,
407397
template <int Dimensions>
408398
bool image_impl<Dimensions>::checkImageFormat(
409399
const RT::PiMemImageFormat &Format, ContextImplPtr Context) {
400+
(void)Context;
410401
if (checkAny(Format.image_channel_order, PI_IMAGE_CHANNEL_ORDER_INTENSITY,
411402
PI_IMAGE_CHANNEL_ORDER_LUMINANCE) &&
412403
!checkAny(

sycl/source/detail/memory_manager.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ void MemoryManager::release(ContextImplPtr TargetContext, SYCLMemObjI *MemObj,
4747

4848
void MemoryManager::releaseImageBuffer(ContextImplPtr TargetContext,
4949
void *ImageBuf) {
50+
(void)TargetContext;
51+
(void)ImageBuf;
5052
// TODO remove when ABI breaking changes are allowed.
5153
throw runtime_error("Deprecated release operation", PI_INVALID_OPERATION);
5254
}
@@ -83,6 +85,9 @@ void *MemoryManager::allocate(ContextImplPtr TargetContext, SYCLMemObjI *MemObj,
8385

8486
void *MemoryManager::wrapIntoImageBuffer(ContextImplPtr TargetContext,
8587
void *MemBuf, SYCLMemObjI *MemObj) {
88+
(void)TargetContext;
89+
(void)MemBuf;
90+
(void)MemObj;
8691
// TODO remove when ABI breaking changes are allowed.
8792
throw runtime_error("Deprecated allocation operation", PI_INVALID_OPERATION);
8893
}
@@ -279,6 +284,7 @@ void copyH2D(SYCLMemObjI *SYCLMemObj, char *SrcMem, QueueImplPtr,
279284
sycl::range<3> DstAccessRange, sycl::id<3> DstOffset,
280285
unsigned int DstElemSize, std::vector<RT::PiEvent> DepEvents,
281286
RT::PiEvent &OutEvent) {
287+
(void)SrcAccessRange;
282288
assert(SYCLMemObj && "The SYCLMemObj is nullptr");
283289

284290
const RT::PiQueue Queue = TgtQueue->getHandleRef();
@@ -350,6 +356,7 @@ void copyD2H(SYCLMemObjI *SYCLMemObj, RT::PiMem SrcMem, QueueImplPtr SrcQueue,
350356
sycl::range<3> DstAccessRange, sycl::id<3> DstOffset,
351357
unsigned int DstElemSize, std::vector<RT::PiEvent> DepEvents,
352358
RT::PiEvent &OutEvent) {
359+
(void)DstAccessRange;
353360
assert(SYCLMemObj && "The SYCLMemObj is nullptr");
354361

355362
const RT::PiQueue Queue = SrcQueue->getHandleRef();

sycl/source/detail/pi.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,9 @@ std::string platformInfoToString(pi_platform_info info) {
142142
return "PI_PLATFORM_INFO_VENDOR";
143143
case PI_PLATFORM_INFO_EXTENSIONS:
144144
return "PI_PLATFORM_INFO_EXTENSIONS";
145-
default:
146-
die("Unknown pi_platform_info value passed to "
147-
"cl::sycl::detail::pi::platformInfoToString");
148145
}
146+
die("Unknown pi_platform_info value passed to "
147+
"cl::sycl::detail::pi::platformInfoToString");
149148
}
150149

151150
std::string memFlagToString(pi_mem_flags Flag) {

sycl/source/detail/program_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ void program_impl::build(const string_class &Options) {
381381
check_device_feature_support<info::device::is_compiler_available>(MDevices);
382382
vector_class<RT::PiDevice> Devices(get_pi_devices());
383383
const detail::plugin &Plugin = getPlugin();
384-
ProgramManager::getInstance().flushSpecConstants(*this, get_pi_devices()[0]);
384+
ProgramManager::getInstance().flushSpecConstants(*this);
385385
RT::PiResult Err = Plugin.call_nocheck<PiApiKind::piProgramBuild>(
386386
MProgram, Devices.size(), Devices.data(), Options.c_str(), nullptr,
387387
nullptr);

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,7 @@ RT::PiProgram ProgramManager::getBuiltPIProgram(OSModuleHandle M,
376376
const detail::plugin &Plugin = ContextImpl->getPlugin();
377377
RT::PiProgram NativePrg = createPIProgram(Img, Context, Device);
378378
if (Prg)
379-
flushSpecConstants(*Prg, getSyclObjImpl(Device)->getHandleRef(),
380-
NativePrg, &Img);
379+
flushSpecConstants(*Prg, NativePrg, &Img);
381380
ProgramPtr ProgramManaged(
382381
NativePrg, Plugin.getPiPlugin().PiFunctionTable.piProgramRelease);
383382

@@ -1011,7 +1010,6 @@ void ProgramManager::dumpImage(const RTDeviceBinaryImage &Img,
10111010
}
10121011

10131012
void ProgramManager::flushSpecConstants(const program_impl &Prg,
1014-
RT::PiDevice Device,
10151013
RT::PiProgram NativePrg,
10161014
const RTDeviceBinaryImage *Img) {
10171015
if (DbgProgMgr > 2) {
@@ -1122,5 +1120,6 @@ extern "C" void __sycl_register_lib(pi_device_binaries desc) {
11221120

11231121
// Executed as a part of current module's (.exe, .dll) static initialization
11241122
extern "C" void __sycl_unregister_lib(pi_device_binaries desc) {
1123+
(void)desc;
11251124
// TODO implement the function
11261125
}

sycl/source/detail/program_manager/program_manager.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,13 @@ class ProgramManager {
107107
/// \param Prg the program object to get spec constant settings from.
108108
/// Passing program_impl by raw reference is OK, since it is not
109109
/// captured anywhere once the function returns.
110-
/// \param Device the device assosiated with the native program
111110
/// \param NativePrg the native program, target for spec constant setting; if
112111
/// not null then overrides the native program in Prg
113112
/// \param Img A source of the information about which constants need
114113
/// setting and symboling->integer spec constnant ID mapping. If not
115114
/// null, overrides native program->binary image binding maintained by
116115
/// the program manager.
117-
void flushSpecConstants(const program_impl &Prg, pi::PiDevice Device,
116+
void flushSpecConstants(const program_impl &Prg,
118117
pi::PiProgram NativePrg = nullptr,
119118
const RTDeviceBinaryImage *Img = nullptr);
120119
uint32_t getDeviceLibReqMask(const RTDeviceBinaryImage &Img);

sycl/source/detail/scheduler/graph_builder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ Command *Scheduler::GraphBuilder::insertMemoryMove(MemObjRecord *Record,
339339
AllocaCmdSrc =
340340
static_cast<AllocaSubBufCommand *>(AllocaCmdSrc)->getParentAlloca();
341341
else if (AllocaCmdSrc->getSYCLMemObj() != Req->MSYCLMemObj)
342-
assert(!"Inappropriate alloca command.");
342+
assert(false && "Inappropriate alloca command.");
343343
}
344344

345345
Command *NewCmd = nullptr;
@@ -728,6 +728,7 @@ void Scheduler::GraphBuilder::markModifiedIfWrite(MemObjRecord *Record,
728728
case access::mode::discard_read_write:
729729
case access::mode::atomic:
730730
Record->MMemModified = true;
731+
break;
731732
case access::mode::read:
732733
break;
733734
}

sycl/source/detail/stream_impl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace detail {
1919
stream_impl::stream_impl(size_t BufferSize, size_t MaxStatementSize,
2020
handler &CGH)
2121
: BufferSize_(BufferSize), MaxStatementSize_(MaxStatementSize) {
22+
(void)CGH;
2223
// We need to store stream buffers in the scheduler because they need to be
2324
// alive after submitting the kernel. They cannot be stored in the stream
2425
// object because it causes loop dependency between objects and results in

sycl/source/handler.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ event handler::finalize() {
103103
throw runtime_error("Command group submitted without a kernel or a "
104104
"explicit memory operation.",
105105
PI_INVALID_OPERATION);
106-
default:
107-
throw runtime_error("Unhandled type of command group",
108-
PI_INVALID_OPERATION);
109106
}
110107

111108
detail::EventImplPtr Event = detail::Scheduler::getInstance().addCG(

sycl/source/spirv_ops.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@
1818
__SYCL_EXPORT void __spirv_GroupWaitEvents(__spv::Scope Execution,
1919
uint32_t NumEvents,
2020
__ocl_event_t *WaitEvents) noexcept {
21+
(void)Execution;
22+
(void)NumEvents;
23+
(void)WaitEvents;
2124
}
2225

2326
__SYCL_EXPORT void __spirv_ControlBarrier(__spv::Scope Execution,
2427
__spv::Scope Memory,
2528
uint32_t Semantics) noexcept {
29+
(void)Execution;
30+
(void)Memory;
31+
(void)Semantics;
2632
std::cerr << "Barrier is not supported on the host device yet.\n";
2733
abort();
2834
}
@@ -33,6 +39,8 @@ __SYCL_EXPORT void __spirv_MemoryBarrier(__spv::Scope Memory,
3339
// separation to global and local there.
3440
// 2. The 'Semantics' parameter is ignored because there is no need
3541
// to distinguish the classes of memory (workgroup/cross-workgroup/etc).
42+
(void)Memory;
43+
(void)Semantics;
3644
atomic_thread_fence(std::memory_order_seq_cst);
3745
}
3846

0 commit comments

Comments
 (0)