Skip to content

Commit c10603b

Browse files
authored
[SYCL][clang-linker-wrapper] Fix argument passing to ocloc. (#20270)
ocloc `-options` args need to be comma separated, e.g. `-options -g,-cl-opt-disable`. Otherwise, only the first arg is processed by ocloc as an arg for `-options`, and the rest are processed as standalone flags, possibly leading to errors. Another possibility would be `-options "-g -cl-opt-disable"`, but quotes might cause escaping issues.
1 parent 91653ad commit c10603b

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,29 @@ static void addBackendOptions(const ArgList &Args,
942942
SmallVector<StringRef, 8> &CmdArgs, bool IsCPU) {
943943
StringRef OptC =
944944
Args.getLastArgValue(OPT_sycl_backend_compile_options_from_image_EQ);
945-
OptC.split(CmdArgs, " ", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
945+
if (IsCPU) {
946+
OptC.split(CmdArgs, " ", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
947+
} else {
948+
// ocloc -options args need to be comma separated, e.g. `-options
949+
// "-g,-cl-opt-disable"`. Otherwise, only the first arg is processed by
950+
// ocloc as an arg for -options, and the rest are processed as standalone
951+
// flags, possibly leading to errors.
952+
// split function here returns a pair with everything before the separator
953+
// ("-options") in the first member of the pair, and everything after the
954+
// separator in the second part of the pair. The separator is not included
955+
// in any of them.
956+
auto [BeforeOptions, AfterOptions] = OptC.split("-options ");
957+
// Only add if not empty, an empty arg can lead to ocloc errors.
958+
if (!BeforeOptions.empty())
959+
CmdArgs.push_back(BeforeOptions);
960+
if (!AfterOptions.empty()) {
961+
// Separator not included by the split function, so explicitly added here.
962+
CmdArgs.push_back("-options");
963+
std::string Replace = AfterOptions.str();
964+
std::replace(Replace.begin(), Replace.end(), ' ', ',');
965+
CmdArgs.push_back(Args.MakeArgString(Replace));
966+
}
967+
}
946968
StringRef OptL =
947969
Args.getLastArgValue(OPT_sycl_backend_link_options_from_image_EQ);
948970
OptL.split(CmdArgs, " ", /*MaxSplit=*/-1, /*KeepEmpty=*/false);

0 commit comments

Comments
 (0)