@@ -76,7 +76,7 @@ static ur_program_handle_t
7676createBinaryProgram (const ContextImplPtr Context,
7777 const std::vector<device> &Devices,
7878 const uint8_t **Binaries, size_t *Lengths,
79- const std::vector<ur_program_metadata_t > Metadata) {
79+ const std::vector<ur_program_metadata_t > & Metadata) {
8080 const AdapterPtr &Adapter = Context->getAdapter ();
8181 ur_program_handle_t Program;
8282 std::vector<ur_device_handle_t > DeviceHandles;
@@ -230,7 +230,7 @@ ProgramManager::createURProgram(const RTDeviceBinaryImage &Img,
230230 " SPIR-V online compilation is not supported in this context" );
231231
232232 // Get program metadata from properties
233- auto ProgMetadata = Img.getProgramMetadataUR ();
233+ const auto & ProgMetadata = Img.getProgramMetadataUR ();
234234
235235 // Load the image
236236 const ContextImplPtr Ctx = getSyclObjImpl (Context);
@@ -990,7 +990,15 @@ ur_program_handle_t ProgramManager::getBuiltURProgram(
990990 // emplace all subsets of the current set of devices into the cache.
991991 // Set of all devices is not included in the loop as it was already added
992992 // into the cache.
993- for (int Mask = 1 ; Mask < (1 << URDevicesSet.size ()) - 1 ; ++Mask) {
993+ int Mask = 1 ;
994+ if (URDevicesSet.size () > sizeof (Mask) * 8 - 1 ) {
995+ // Protection for the algorithm below. Although overflow is very unlikely
996+ // to be reached.
997+ throw sycl::exception (
998+ make_error_code (errc::runtime),
999+ " Unable to cache built program for more than 31 devices" );
1000+ }
1001+ for (; Mask < (1 << URDevicesSet.size ()) - 1 ; ++Mask) {
9941002 std::set<ur_device_handle_t > Subset;
9951003 int Index = 0 ;
9961004 for (auto It = URDevicesSet.begin (); It != URDevicesSet.end ();
@@ -1124,7 +1132,7 @@ ProgramManager::getUrProgramFromUrKernel(ur_kernel_handle_t Kernel,
11241132
11251133std::string
11261134ProgramManager::getProgramBuildLog (const ur_program_handle_t &Program,
1127- const ContextImplPtr Context) {
1135+ const ContextImplPtr & Context) {
11281136 size_t URDevicesSize = 0 ;
11291137 const AdapterPtr &Adapter = Context->getAdapter ();
11301138 Adapter->call <UrApiKind::urProgramGetInfo>(Program, UR_PROGRAM_INFO_DEVICES,
0 commit comments