Skip to content

Commit a20c57d

Browse files
authored
[SYCL] Add Noexcept to clang SPIR-V builtin declaration (#17435)
This fixes following error when SYCL header declares a SPIR-V builtin with noexcept specifier and the builtin is also declared in clang/lib/Sema/SPIRVBuiltins.td: "exception specification in declaration does not match previous declaration" For instance, __spirv_ControlBarrier declaration in clang/test/CodeGenSYCL/Inputs/sycl.hpp has the build error.
1 parent 0a1665a commit a20c57d

File tree

5 files changed

+43
-29
lines changed

5 files changed

+43
-29
lines changed

clang/lib/Sema/SemaLookup.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ static void GetProgModelBuiltinFctOverloads(
786786
FunctionProtoType::ExtProtoInfo PI(
787787
Context.getDefaultCallingConvention(false, false, true));
788788
PI.Variadic = IsVariadic;
789+
PI.ExceptionSpec = FunctionProtoType::ExceptionSpecInfo{EST_BasicNoexcept};
789790

790791
// Do not attempt to create any FunctionTypes if there are no return types,
791792
// which happens when a type belongs to a disabled extension.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fdeclare-spirv-builtins -fsyntax-only %s -verify
2+
// expected-no-diagnostics
3+
4+
void acos(float val) {
5+
static_assert(noexcept(__spirv_ocl_acos(val)));
6+
}
7+
8+
void isnan(float a) {
9+
static_assert(noexcept(__spirv_IsNan(a)));
10+
}

clang/test/CodeGenSYCL/Inputs/sycl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extern "C" int printf(const char* fmt, ...);
1919

2020
#ifdef __SYCL_DEVICE_ONLY__
2121
__attribute__((convergent)) extern __attribute__((sycl_device)) void
22-
__spirv_ControlBarrier(int, int, int);
22+
__spirv_ControlBarrier(int, int, int) noexcept;
2323
#endif
2424

2525
// Dummy runtime classes to model SYCL API.

libdevice/include/sanitizer_defs.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ extern SYCL_EXTERNAL int
4242
__spirv_ocl_printf(const __SYCL_CONSTANT__ char *Format, ...);
4343

4444
extern SYCL_EXTERNAL __SYCL_GLOBAL__ void *
45-
__spirv_GenericCastToPtrExplicit_ToGlobal(void *, int);
45+
__spirv_GenericCastToPtrExplicit_ToGlobal(void *, int) noexcept;
4646
extern SYCL_EXTERNAL __SYCL_LOCAL__ void *
47-
__spirv_GenericCastToPtrExplicit_ToLocal(void *, int);
47+
__spirv_GenericCastToPtrExplicit_ToLocal(void *, int) noexcept;
4848
extern SYCL_EXTERNAL __SYCL_PRIVATE__ void *
49-
__spirv_GenericCastToPtrExplicit_ToPrivate(void *, int);
49+
__spirv_GenericCastToPtrExplicit_ToPrivate(void *, int) noexcept;
5050

5151
extern SYCL_EXTERNAL __attribute__((convergent)) void
52-
__spirv_ControlBarrier(int32_t Execution, int32_t Memory, int32_t Semantics);
52+
__spirv_ControlBarrier(int32_t Execution, int32_t Memory,
53+
int32_t Semantics) noexcept;
5354

5455
extern "C" SYCL_EXTERNAL void __devicelib_exit();
5556

libdevice/nativecpu_utils.cpp

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,19 @@ using __nativecpu_state = native_cpu::state;
3434
#define OCL_PRIVATE __attribute__((opencl_private))
3535

3636
DEVICE_EXTERN_C void __mux_work_group_barrier(int32_t id, int32_t scope,
37-
int32_t semantics);
37+
int32_t semantics) noexcept;
3838
__SYCL_CONVERGENT__ DEVICE_EXTERNAL void
39-
__spirv_ControlBarrier(int32_t Execution, int32_t Memory, int32_t Semantics) {
39+
__spirv_ControlBarrier(int32_t Execution, int32_t Memory,
40+
int32_t Semantics) noexcept {
4041
if (__spv::Scope::Flag::Workgroup == Execution)
4142
// todo: check id and args; use mux constants
4243
__mux_work_group_barrier(0, Execution, Semantics);
4344
}
4445

45-
DEVICE_EXTERN_C void __mux_mem_barrier(int32_t scope, int32_t semantics);
46+
DEVICE_EXTERN_C void __mux_mem_barrier(int32_t scope,
47+
int32_t semantics) noexcept;
4648
__SYCL_CONVERGENT__ DEVICE_EXTERNAL void
47-
__spirv_MemoryBarrier(int32_t Memory, int32_t Semantics) {
49+
__spirv_MemoryBarrier(int32_t Memory, int32_t Semantics) noexcept {
4850
__mux_mem_barrier(Memory, Semantics);
4951
}
5052

@@ -54,7 +56,7 @@ __spirv_MemoryBarrier(int32_t Memory, int32_t Semantics) {
5456

5557
#define DefGenericCastToPtrExplImpl(sfx, asp, cv)\
5658
DEVICE_EXTERNAL cv asp void *\
57-
__spirv_GenericCastToPtrExplicit_##sfx(cv void *p ,int) {\
59+
__spirv_GenericCastToPtrExplicit_##sfx(cv void *p ,int) noexcept {\
5860
return (cv asp void *)p;\
5961
}
6062

@@ -100,9 +102,9 @@ DefSubgroupBlockINTEL(uint32_t) DefSubgroupBlockINTEL(uint64_t)
100102
DefSubgroupBlockINTEL(uint8_t) DefSubgroupBlockINTEL(uint16_t)
101103

102104
#define DefineGOp1(spir_sfx, name)\
103-
DEVICE_EXTERN_C bool __mux_sub_group_##name##_i1(bool);\
104-
DEVICE_EXTERN_C bool __mux_work_group_##name##_i1(uint32_t id, bool val);\
105-
DEVICE_EXTERNAL bool __spirv_Group ## spir_sfx(unsigned g, bool val) {\
105+
DEVICE_EXTERN_C bool __mux_sub_group_##name##_i1(bool) noexcept;\
106+
DEVICE_EXTERN_C bool __mux_work_group_##name##_i1(uint32_t id, bool val) noexcept;\
107+
DEVICE_EXTERNAL bool __spirv_Group ## spir_sfx(unsigned g, bool val) noexcept {\
106108
if (__spv::Scope::Flag::Subgroup == g)\
107109
return __mux_sub_group_##name##_i1(val);\
108110
else if (__spv::Scope::Flag::Workgroup == g)\
@@ -115,16 +117,16 @@ DefineGOp1(All, all)
115117

116118

117119
#define DefineGOp(Type, MuxType, spir_sfx, mux_sfx) \
118-
DEVICE_EXTERN_C MuxType __mux_sub_group_scan_inclusive_##mux_sfx(MuxType); \
119-
DEVICE_EXTERN_C MuxType __mux_sub_group_scan_exclusive_##mux_sfx(MuxType); \
120-
DEVICE_EXTERN_C MuxType __mux_sub_group_reduce_##mux_sfx(MuxType); \
120+
DEVICE_EXTERN_C MuxType __mux_sub_group_scan_inclusive_##mux_sfx(MuxType) noexcept; \
121+
DEVICE_EXTERN_C MuxType __mux_sub_group_scan_exclusive_##mux_sfx(MuxType) noexcept; \
122+
DEVICE_EXTERN_C MuxType __mux_sub_group_reduce_##mux_sfx(MuxType) noexcept; \
121123
DEVICE_EXTERN_C MuxType __mux_work_group_scan_exclusive_##mux_sfx(uint32_t, \
122-
MuxType); \
124+
MuxType) noexcept; \
123125
DEVICE_EXTERN_C MuxType __mux_work_group_scan_inclusive_##mux_sfx(uint32_t, \
124-
MuxType); \
125-
DEVICE_EXTERN_C MuxType __mux_work_group_reduce_##mux_sfx(uint32_t, MuxType);\
126+
MuxType) noexcept; \
127+
DEVICE_EXTERN_C MuxType __mux_work_group_reduce_##mux_sfx(uint32_t, MuxType) noexcept;\
126128
DEVICE_EXTERNAL Type __spirv_Group##spir_sfx(uint32_t g, uint32_t id, \
127-
Type v) { \
129+
Type v) noexcept { \
128130
if (__spv::Scope::Flag::Subgroup == g) { \
129131
if (static_cast<unsigned>(__spv::GroupOperation::InclusiveScan) == id) \
130132
return __mux_sub_group_scan_inclusive_##mux_sfx(v); \
@@ -196,29 +198,29 @@ DefineLogicalGroupOp(bool, bool, i1)
196198

197199
#define DefineBroadcastMuxType(Type, Sfx, MuxType, IDType) \
198200
DEVICE_EXTERN_C MuxType __mux_work_group_broadcast_##Sfx( \
199-
int32_t id, MuxType val, uint64_t lidx, uint64_t lidy, uint64_t lidz); \
201+
int32_t id, MuxType val, uint64_t lidx, uint64_t lidy, uint64_t lidz) noexcept; \
200202
DEVICE_EXTERN_C MuxType __mux_sub_group_broadcast_##Sfx(MuxType val, \
201-
int32_t sg_lid);
203+
int32_t sg_lid) noexcept;
202204

203205
#define DefineBroadCastImpl(Type, Sfx, MuxType, IDType) \
204206
DEVICE_EXTERNAL Type __spirv_GroupBroadcast(uint32_t g, Type v, \
205-
IDType l) { \
207+
IDType l) noexcept { \
206208
if (__spv::Scope::Flag::Subgroup == g) \
207209
return __mux_sub_group_broadcast_##Sfx(v, l); \
208210
else \
209211
return __mux_work_group_broadcast_##Sfx(0, v, l, 0, 0); \
210212
} \
211213
\
212214
DEVICE_EXTERNAL Type __spirv_GroupBroadcast(uint32_t g, Type v, \
213-
sycl::vec<IDType, 2>::vector_t l) { \
215+
sycl::vec<IDType, 2>::vector_t l) noexcept{ \
214216
if (__spv::Scope::Flag::Subgroup == g) \
215217
return __mux_sub_group_broadcast_##Sfx(v, l[0]); \
216218
else \
217219
return __mux_work_group_broadcast_##Sfx(0, v, l[0], l[1], 0); \
218220
} \
219221
\
220222
DEVICE_EXTERNAL Type __spirv_GroupBroadcast(uint32_t g, Type v, \
221-
sycl::vec<IDType, 3>::vector_t l) { \
223+
sycl::vec<IDType, 3>::vector_t l) noexcept{ \
222224
if (__spv::Scope::Flag::Subgroup == g) \
223225
return __mux_sub_group_broadcast_##Sfx(v, l[0]); \
224226
else \
@@ -241,7 +243,7 @@ DefineBroadCast(int64_t, i64, int64_t)
241243

242244
#define DefShuffleINTEL(Type, Sfx, MuxType) \
243245
DEVICE_EXTERN_C MuxType __mux_sub_group_shuffle_##Sfx(MuxType val, \
244-
int32_t lid); \
246+
int32_t lid) noexcept; \
245247
template <> \
246248
DEVICE_EXTERNAL Type __spirv_SubgroupShuffleINTEL<Type>( \
247249
Type val, unsigned id) noexcept { \
@@ -250,7 +252,7 @@ DefineBroadCast(int64_t, i64, int64_t)
250252

251253
#define DefShuffleUpINTEL(Type, Sfx, MuxType) \
252254
DEVICE_EXTERN_C MuxType __mux_sub_group_shuffle_up_##Sfx( \
253-
MuxType prev, MuxType curr, int32_t delta); \
255+
MuxType prev, MuxType curr, int32_t delta) noexcept; \
254256
template <> \
255257
DEVICE_EXTERNAL Type __spirv_SubgroupShuffleUpINTEL<Type>( \
256258
Type prev, Type curr, unsigned delta) noexcept { \
@@ -260,7 +262,7 @@ DefineBroadCast(int64_t, i64, int64_t)
260262

261263
#define DefShuffleDownINTEL(Type, Sfx, MuxType) \
262264
DEVICE_EXTERN_C MuxType __mux_sub_group_shuffle_down_##Sfx( \
263-
MuxType curr, MuxType next, int32_t delta); \
265+
MuxType curr, MuxType next, int32_t delta) noexcept; \
264266
template <> \
265267
DEVICE_EXTERNAL Type __spirv_SubgroupShuffleDownINTEL<Type>( \
266268
Type curr, Type next, unsigned delta) noexcept { \
@@ -298,7 +300,7 @@ DefShuffleINTEL_All(_Float16, f16, _Float16)
298300
// Vector versions of shuffle are generated by the FixABIBuiltinsSYCLNativeCPU pass
299301

300302
#define Define2ArgForward(Type, Name, Callee)\
301-
DEVICE_EXTERNAL Type Name(Type a, Type b) { return Callee(a,b);}
303+
DEVICE_EXTERNAL Type Name(Type a, Type b) noexcept { return Callee(a,b);}
302304

303305
Define2ArgForward(uint64_t, __spirv_ocl_u_min, std::min)
304306

0 commit comments

Comments
 (0)