diff --git a/projects/clr/rocclr/platform/program.cpp b/projects/clr/rocclr/platform/program.cpp index 3e57c99bc5..4d9649c4a7 100644 --- a/projects/clr/rocclr/platform/program.cpp +++ b/projects/clr/rocclr/platform/program.cpp @@ -229,6 +229,22 @@ device::Program* Program::getDeviceProgram(const Device& device) const { Monitor Program::buildLock_("OCL build program", true); +static bool adjustOptionsOnIgnoreEnv(std::string &cppstr) { + // if there is a -ignore-env, adjust options. + bool optionChangable = true; + if (cppstr.size() > 0) { + // Set the options to be the string after -ignore-env + const char ignore_env[] = "-ignore-env"; + size_t pos = cppstr.find(ignore_env); + if (pos != std::string::npos) { + cppstr = cppstr.substr(pos + sizeof(ignore_env)); + optionChangable = false; + } + remove_g_option(cppstr); + } + return optionChangable; +} + int32_t Program::compile(const std::vector& devices, size_t numHeaders, const std::vector& headerPrograms, const char** headerIncludeNames, const char* options, @@ -243,17 +259,7 @@ int32_t Program::compile(const std::vector& devices, size_t numHeaders, // Process build options. std::string cppstr(options ? options : ""); - - // if there is a -ignore-env, adjust options. - if (cppstr.size() > 0) { - // Set the options to be the string after -ignore-env - size_t pos = cppstr.find("-ignore-env"); - if (pos != std::string::npos) { - cppstr = cppstr.substr(pos + sizeof("-ignore-env")); - optionChangable = false; - } - remove_g_option(cppstr); - } + optionChangable &= adjustOptionsOnIgnoreEnv(cppstr); std::vector headers(numHeaders); for (size_t i = 0; i < numHeaders; ++i) { @@ -330,17 +336,7 @@ int32_t Program::link(const std::vector& devices, size_t numInputs, // Process build options. std::string cppstr(options ? options : ""); - - // if there is a -ignore-env, adjust options. - if (cppstr.size() > 0) { - // Set the options to be the string after -ignore-env - size_t pos = cppstr.find("-ignore-env"); - if (pos != std::string::npos) { - cppstr = cppstr.substr(pos + sizeof("-ignore-env")); - optionChangable = false; - } - remove_g_option(cppstr); - } + optionChangable &= adjustOptionsOnIgnoreEnv(cppstr); // Link the program programs associated with the given devices. for (const auto& it : devices) { @@ -515,17 +511,7 @@ int32_t Program::build(const std::vector& devices, const char* options, // Process build options. std::string cppstr(options ? options : ""); - - // if there is a -ignore-env, adjust options. - if (cppstr.size() > 0) { - // Set the options to be the string after -ignore-env - size_t pos = cppstr.find("-ignore-env"); - if (pos != std::string::npos) { - cppstr = cppstr.substr(pos + sizeof("-ignore-env")); - optionChangable = false; - } - remove_g_option(cppstr); - } + optionChangable &= adjustOptionsOnIgnoreEnv(cppstr); // Build the program programs associated with the given devices. for (const auto& it : devices) {