@@ -942,7 +942,29 @@ static void addBackendOptions(const ArgList &Args,
942
942
SmallVector<StringRef, 8 > &CmdArgs, bool IsCPU) {
943
943
StringRef OptC =
944
944
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
+ }
946
968
StringRef OptL =
947
969
Args.getLastArgValue (OPT_sycl_backend_link_options_from_image_EQ);
948
970
OptL.split (CmdArgs, " " , /* MaxSplit=*/ -1 , /* KeepEmpty=*/ false );
0 commit comments