Skip to content

Commit c759789

Browse files
[SYCL][ABI-Break] Remove sycl::exception error code member workaround (#6578)
To avoid ABI break, sycl::exception would embed the error code into the error string. With the ABI-break window open, this commit promotes the embedded error code to a member of sycl::exception. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent a111937 commit c759789

File tree

2 files changed

+4
-33
lines changed

2 files changed

+4
-33
lines changed

sycl/include/sycl/exception.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class __SYCL_EXPORT exception : public std::exception {
102102
std::shared_ptr<std::string> MMsg;
103103
pi_int32 MPIErr;
104104
std::shared_ptr<context> MContext;
105+
std::error_code MErrC = make_error_code(sycl::errc::invalid);
105106

106107
protected:
107108
// these two constructors are no longer used. Kept for ABI compatability.

sycl/source/exception.cpp

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
namespace sycl {
1616
__SYCL_INLINE_VER_NAMESPACE(_V1) {
1717

18-
namespace { // anonymous
19-
constexpr char ReservedForErrorcode[] =
20-
"01234567812345678"; // 17 (string terminator plus error code)
21-
std::error_code SYCL121ProxyErrorcode = make_error_code(sycl::errc::invalid);
22-
} // namespace
23-
2418
exception::exception(std::error_code EC, const char *Msg)
2519
: exception(EC, nullptr, Msg) {}
2620

@@ -65,35 +59,11 @@ exception::exception(context Ctx, int EV, const std::error_category &ECat)
6559
// protected base constructor for all SYCL 2020 constructors
6660
exception::exception(std::error_code EC, std::shared_ptr<context> SharedPtrCtx,
6761
const std::string &WhatArg)
68-
: MMsg(std::make_shared<std::string>(WhatArg + ReservedForErrorcode)),
69-
MPIErr(PI_ERROR_INVALID_VALUE), MContext(SharedPtrCtx) {
70-
// For compatibility with previous implementation, we are "hiding" the
71-
// std::error_code in the MMsg string, behind the null string terminator
72-
const int StringTermPoint = MMsg->length() - strlen(ReservedForErrorcode);
73-
char *ReservedPtr = &(*MMsg)[StringTermPoint];
74-
ReservedPtr[0] = '\0';
75-
ReservedPtr++;
76-
// insert error code
77-
std::error_code *ECPtr = reinterpret_cast<std::error_code *>(ReservedPtr);
78-
memcpy(ECPtr, &EC, sizeof(std::error_code));
79-
}
62+
: MMsg(std::make_shared<std::string>(WhatArg)),
63+
MPIErr(PI_ERROR_INVALID_VALUE), MContext(SharedPtrCtx), MErrC(EC) {}
8064

8165
const std::error_code &exception::code() const noexcept {
82-
const char *WhatStr = MMsg->c_str();
83-
// advance to inner string-terminator
84-
int StringTermPoint = MMsg->length() - strlen(ReservedForErrorcode);
85-
if (StringTermPoint >= 0) {
86-
const char *ReservedPtr = &WhatStr[StringTermPoint];
87-
// check for string terminator, which denotes a SYCL 2020 exception
88-
if (ReservedPtr[0] == '\0') {
89-
ReservedPtr++;
90-
const std::error_code *ECPtr =
91-
reinterpret_cast<const std::error_code *>(ReservedPtr);
92-
return *ECPtr;
93-
}
94-
}
95-
// else the exception originates from some SYCL 1.2.1 source
96-
return SYCL121ProxyErrorcode;
66+
return MErrC;
9767
}
9868

9969
const std::error_category &exception::category() const noexcept {

0 commit comments

Comments
 (0)