Skip to content

Commit 8573612

Browse files
committed
Treat all variants of -fsanitize=address as unsupported.
Signed-off-by: Julian Oppermann <[email protected]>
1 parent d44888c commit 8573612

File tree

2 files changed

+73
-40
lines changed

2 files changed

+73
-40
lines changed

sycl-jit/jit-compiler/lib/rtc/DeviceCompilation.cpp

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,6 @@ getDeviceLibraries(const ArgList &Args, DiagnosticsEngine &Diags) {
235235
{"libsycl-itt-user-wrappers", "internal"},
236236
{"libsycl-itt-compiler-wrappers", "internal"},
237237
{"libsycl-itt-stubs", "internal"}};
238-
const SYCLDeviceLibsList SYCLDeviceSanitizerLibs = {
239-
{"libsycl-sanitizer", "internal"}};
240238

241239
SmallVector<std::string, 8> LibraryList;
242240
StringRef LibSuffix = ".bc";
@@ -258,44 +256,6 @@ getDeviceLibraries(const ArgList &Args, DiagnosticsEngine &Diags) {
258256
AddLibraries(SYCLDeviceAnnotationLibs);
259257
}
260258

261-
if (Arg *A = Args.getLastArg(OPT_fsanitize_EQ, OPT_fno_sanitize_EQ)) {
262-
if (A->getOption().matches(OPT_fsanitize_EQ) &&
263-
A->getValues().size() == 1) {
264-
std::string SanitizeVal = A->getValue();
265-
if (SanitizeVal == "address") {
266-
AddLibraries(SYCLDeviceSanitizerLibs);
267-
}
268-
}
269-
} else {
270-
// User can pass -fsanitize=address to device compiler via
271-
// -Xsycl-target-frontend, sanitize device library must be
272-
// linked with user's device image if so.
273-
bool IsDeviceAsanEnabled = false;
274-
auto SyclFEArg = Args.getAllArgValues(OPT_Xsycl_frontend);
275-
IsDeviceAsanEnabled = (std::count(SyclFEArg.begin(), SyclFEArg.end(),
276-
"-fsanitize=address") > 0);
277-
if (!IsDeviceAsanEnabled) {
278-
auto SyclFEArgEq = Args.getAllArgValues(OPT_Xsycl_frontend_EQ);
279-
IsDeviceAsanEnabled = (std::count(SyclFEArgEq.begin(), SyclFEArgEq.end(),
280-
"-fsanitize=address") > 0);
281-
}
282-
283-
// User can also enable asan for SYCL device via -Xarch_device option.
284-
if (!IsDeviceAsanEnabled) {
285-
auto DeviceArchVals = Args.getAllArgValues(OPT_Xarch_device);
286-
for (auto DArchVal : DeviceArchVals) {
287-
if (DArchVal.find("-fsanitize=address") != std::string::npos) {
288-
IsDeviceAsanEnabled = true;
289-
break;
290-
}
291-
}
292-
}
293-
294-
if (IsDeviceAsanEnabled) {
295-
AddLibraries(SYCLDeviceSanitizerLibs);
296-
}
297-
}
298-
299259
return LibraryList;
300260
}
301261

@@ -357,5 +317,48 @@ jit_compiler::parseUserArgs(View<const char *> UserArgs) {
357317
"User option '%s' at index %d is missing an argument",
358318
UserArgsRef[MissingArgIndex], MissingArgIndex);
359319
}
320+
321+
// Check for unsupported options.
322+
// TODO: There are probably more, e.g. requesting non-SPIR-V targets.
323+
{
324+
// -fsanitize=address
325+
bool IsDeviceAsanEnabled = false;
326+
if (Arg *A = AL.getLastArg(OPT_fsanitize_EQ, OPT_fno_sanitize_EQ)) {
327+
if (A->getOption().matches(OPT_fsanitize_EQ) &&
328+
A->getValues().size() == 1) {
329+
std::string SanitizeVal = A->getValue();
330+
IsDeviceAsanEnabled = SanitizeVal == "address";
331+
}
332+
} else {
333+
// User can pass -fsanitize=address to device compiler via
334+
// -Xsycl-target-frontend.
335+
auto SyclFEArg = AL.getAllArgValues(OPT_Xsycl_frontend);
336+
IsDeviceAsanEnabled = (std::count(SyclFEArg.begin(), SyclFEArg.end(),
337+
"-fsanitize=address") > 0);
338+
if (!IsDeviceAsanEnabled) {
339+
auto SyclFEArgEq = AL.getAllArgValues(OPT_Xsycl_frontend_EQ);
340+
IsDeviceAsanEnabled =
341+
(std::count(SyclFEArgEq.begin(), SyclFEArgEq.end(),
342+
"-fsanitize=address") > 0);
343+
}
344+
345+
// User can also enable asan for SYCL device via -Xarch_device option.
346+
if (!IsDeviceAsanEnabled) {
347+
auto DeviceArchVals = AL.getAllArgValues(OPT_Xarch_device);
348+
for (auto DArchVal : DeviceArchVals) {
349+
if (DArchVal.find("-fsanitize=address") != std::string::npos) {
350+
IsDeviceAsanEnabled = true;
351+
break;
352+
}
353+
}
354+
}
355+
}
356+
357+
if (IsDeviceAsanEnabled) {
358+
return createStringError(
359+
"Device ASAN is not supported for runtime compilation");
360+
}
361+
}
362+
360363
return Expected<InputArgList>{std::move(AL)};
361364
}

sycl/test-e2e/KernelCompiler/kernel_compiler_sycl_jit.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,40 @@ void test_build_and_run() {
119119
test_1(q, k, 37 + 5); // ff_cp seeds 37. AddEm will add 5 more.
120120
}
121121

122+
void test_unsupported_options() {
123+
namespace syclex = sycl::ext::oneapi::experimental;
124+
using source_kb = sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source>;
125+
126+
sycl::queue q;
127+
sycl::context ctx = q.get_context();
128+
129+
source_kb kbSrc = syclex::create_kernel_bundle_from_source(
130+
ctx, syclex::source_language::sycl_jit, "");
131+
std::vector<sycl::device> devs = kbSrc.get_devices();
132+
133+
auto CheckUnsupported = [&](const std::vector<std::string> &flags) {
134+
try {
135+
syclex::build(kbSrc, devs,
136+
syclex::properties{syclex::build_options{flags}});
137+
assert(false && "Unsupported option not detected");
138+
} catch (sycl::exception &e) {
139+
assert(e.code() == sycl::errc::build);
140+
assert(std::string(e.what()).find("Parsing of user arguments failed") !=
141+
std::string::npos);
142+
}
143+
};
144+
145+
CheckUnsupported({"-fsanitize=address"});
146+
CheckUnsupported({"-Xsycl-target-frontend", "-fsanitize=address"});
147+
CheckUnsupported({"-Xsycl-target-frontend=spir64", "-fsanitize=address"});
148+
CheckUnsupported({"-Xarch_device", "-fsanitize=address"});
149+
}
150+
122151
int main() {
123152

124153
#ifdef SYCL_EXT_ONEAPI_KERNEL_COMPILER
125154
test_build_and_run();
155+
test_unsupported_options();
126156
#else
127157
static_assert(false, "Kernel Compiler feature test macro undefined");
128158
#endif

0 commit comments

Comments
 (0)