Skip to content

Commit 489466e

Browse files
authored
[SYCL][ABI-Break] ABI-neutralize the data member of Exception message (#13549)
Currently, the exception class contains the data member `MMsg `whose type is `shared_ptr<std::string>`. This may cause an ABI-incompatibility issue when the user code and SYCL lib are built with different C++11 ABI setting. To solve this issue, this PR changes the type of `MMsg` to `shared_ptr<detail::string>`. --------- Signed-off-by: Byoungro So <[email protected]>
1 parent f738ddb commit 489466e

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

sycl/include/sycl/exception.hpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#include <sycl/detail/defines_elementary.hpp> // for __SYCL2020_DEPRECATED
1717
#include <sycl/detail/export.hpp> // for __SYCL_EXPORT
1818
#include <sycl/detail/pi.h> // for pi_int32
19+
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
20+
#include <sycl/detail/string.hpp>
21+
#endif
1922

2023
#include <exception> // for exception
2124
#include <memory> // for allocator, shared_ptr, make...
@@ -106,7 +109,11 @@ class __SYCL_EXPORT exception : public virtual std::exception {
106109
private:
107110
// Exceptions must be noexcept copy constructible, so cannot use std::string
108111
// directly.
112+
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
113+
std::shared_ptr<detail::string> MMsg;
114+
#else
109115
std::shared_ptr<std::string> MMsg;
116+
#endif
110117
pi_int32 MPIErr = 0;
111118
std::shared_ptr<context> MContext;
112119
std::error_code MErrC = make_error_code(sycl::errc::invalid);
@@ -124,14 +131,20 @@ class __SYCL_EXPORT exception : public virtual std::exception {
124131
}
125132

126133
exception(const std::string &Msg)
127-
: MMsg(std::make_shared<std::string>(Msg)), MContext(nullptr) {}
128-
129-
// base constructor for all SYCL 2020 constructors
130-
// exception(context *ctxPtr, std::error_code Ec, const std::string
131-
// &what_arg);
132-
exception(std::error_code Ec, std::shared_ptr<context> SharedPtrCtx,
133-
const std::string &what_arg)
134-
: exception(Ec, SharedPtrCtx, what_arg.c_str()) {}
134+
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
135+
: MMsg(std::make_shared<detail::string>(Msg)), MContext(nullptr){}
136+
#else
137+
: MMsg(std::make_shared<std::string>(Msg)), MContext(nullptr) {
138+
}
139+
#endif
140+
141+
// base constructor for all SYCL 2020 constructors
142+
// exception(context *ctxPtr, std::error_code Ec, const std::string
143+
// &what_arg);
144+
exception(std::error_code Ec, std::shared_ptr<context> SharedPtrCtx,
145+
const std::string &what_arg)
146+
: exception(Ec, SharedPtrCtx, what_arg.c_str()) {
147+
}
135148
exception(std::error_code Ec, std::shared_ptr<context> SharedPtrCtx,
136149
const char *WhatArg);
137150
};

sycl/source/exception.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ exception::exception(context Ctx, int EV, const std::error_category &ECat)
5353
// protected base constructor for all SYCL 2020 constructors
5454
exception::exception(std::error_code EC, std::shared_ptr<context> SharedPtrCtx,
5555
const char *WhatArg)
56+
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
57+
: MMsg(std::make_shared<detail::string>(WhatArg)),
58+
#else
5659
: MMsg(std::make_shared<std::string>(WhatArg)),
60+
#endif
5761
MPIErr(PI_ERROR_INVALID_VALUE), MContext(SharedPtrCtx), MErrC(EC) {
5862
detail::GlobalHandler::instance().TraceEventXPTI(MMsg->c_str());
5963
}

0 commit comments

Comments
 (0)