@@ -942,7 +942,24 @@ 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+ // ocloc -options args need to be comma separated, e.g. `-options
947+ // "-g,-cl-opt-disable"`. Otherwise, only the first arg is processed by
948+ // ocloc as an arg for -options, and the rest are processed as standalone
949+ // flags, possibly leading to errors.
950+ std::pair<StringRef, StringRef> OptionsArgs = OptC.split (" -options " );
951+ // Only add if not empty, an empty arg can lead to ocloc errors.
952+ if (!OptionsArgs.first .empty ())
953+ CmdArgs.push_back (OptionsArgs.first );
954+ if (!OptionsArgs.second .empty ()) {
955+ CmdArgs.push_back (" -options" );
956+ std::string Replace = OptionsArgs.second .str ();
957+ std::replace (Replace.begin (), Replace.end (), ' ' , ' ,' );
958+ CmdArgs.push_back (Args.MakeArgString (Replace));
959+ }
960+ } else {
961+ OptC.split (CmdArgs, " " , /* MaxSplit=*/ -1 , /* KeepEmpty=*/ false );
962+ }
946963 StringRef OptL =
947964 Args.getLastArgValue (OPT_sycl_backend_link_options_from_image_EQ);
948965 OptL.split (CmdArgs, " " , /* MaxSplit=*/ -1 , /* KeepEmpty=*/ false );
0 commit comments