@@ -1285,7 +1285,7 @@ class VKDevice : public offloadtest::Device {
12851285 return llvm::Error::success ();
12861286 }
12871287
1288- static void
1288+ static llvm::Error
12891289 parseSpecializationConstant (const SpecializationConstant &SpecConst,
12901290 VkSpecializationMapEntry &Entry,
12911291 llvm::SmallVector<char > &SpecData) {
@@ -1295,7 +1295,11 @@ class VKDevice : public offloadtest::Device {
12951295 case DataFormat::Float32: {
12961296 float Value = 0 .0f ;
12971297 double Tmp = 0.0 ;
1298- llvm::StringRef (SpecConst.Value ).getAsDouble (Tmp);
1298+ if (llvm::StringRef (SpecConst.Value ).getAsDouble (Tmp))
1299+ return llvm::createStringError (
1300+ std::errc::invalid_argument,
1301+ " Invalid float value for specialization constant '%s'" ,
1302+ SpecConst.Value .c_str ());
12991303 Value = static_cast <float >(Tmp);
13001304 Entry.size = sizeof (float );
13011305 SpecData.resize (SpecData.size () + sizeof (float ));
@@ -1304,47 +1308,71 @@ class VKDevice : public offloadtest::Device {
13041308 }
13051309 case DataFormat::Float64: {
13061310 double Value = 0.0 ;
1307- llvm::StringRef (SpecConst.Value ).getAsDouble (Value);
1311+ if (llvm::StringRef (SpecConst.Value ).getAsDouble (Value))
1312+ return llvm::createStringError (
1313+ std::errc::invalid_argument,
1314+ " Invalid double value for specialization constant '%s'" ,
1315+ SpecConst.Value .c_str ());
13081316 Entry.size = sizeof (double );
13091317 SpecData.resize (SpecData.size () + sizeof (double ));
13101318 memcpy (SpecData.data () + Entry.offset , &Value, sizeof (double ));
13111319 break ;
13121320 }
13131321 case DataFormat::Int16: {
13141322 int16_t Value = 0 ;
1315- llvm::StringRef (SpecConst.Value ).getAsInteger (0 , Value);
1323+ if (llvm::StringRef (SpecConst.Value ).getAsInteger (0 , Value))
1324+ return llvm::createStringError (
1325+ std::errc::invalid_argument,
1326+ " Invalid int16 value for specialization constant '%s'" ,
1327+ SpecConst.Value .c_str ());
13161328 Entry.size = sizeof (int16_t );
13171329 SpecData.resize (SpecData.size () + sizeof (int16_t ));
13181330 memcpy (SpecData.data () + Entry.offset , &Value, sizeof (int16_t ));
13191331 break ;
13201332 }
13211333 case DataFormat::UInt16: {
13221334 uint16_t Value = 0 ;
1323- llvm::StringRef (SpecConst.Value ).getAsInteger (0 , Value);
1335+ if (llvm::StringRef (SpecConst.Value ).getAsInteger (0 , Value))
1336+ return llvm::createStringError (
1337+ std::errc::invalid_argument,
1338+ " Invalid uint16 value for specialization constant '%s'" ,
1339+ SpecConst.Value .c_str ());
13241340 Entry.size = sizeof (uint16_t );
13251341 SpecData.resize (SpecData.size () + sizeof (uint16_t ));
13261342 memcpy (SpecData.data () + Entry.offset , &Value, sizeof (uint16_t ));
13271343 break ;
13281344 }
13291345 case DataFormat::Int32: {
13301346 int32_t Value = 0 ;
1331- llvm::StringRef (SpecConst.Value ).getAsInteger (0 , Value);
1347+ if (llvm::StringRef (SpecConst.Value ).getAsInteger (0 , Value))
1348+ return llvm::createStringError (
1349+ std::errc::invalid_argument,
1350+ " Invalid int32 value for specialization constant '%s'" ,
1351+ SpecConst.Value .c_str ());
13321352 Entry.size = sizeof (int32_t );
13331353 SpecData.resize (SpecData.size () + sizeof (int32_t ));
13341354 memcpy (SpecData.data () + Entry.offset , &Value, sizeof (int32_t ));
13351355 break ;
13361356 }
13371357 case DataFormat::UInt32: {
13381358 uint32_t Value = 0 ;
1339- llvm::StringRef (SpecConst.Value ).getAsInteger (0 , Value);
1359+ if (llvm::StringRef (SpecConst.Value ).getAsInteger (0 , Value))
1360+ return llvm::createStringError (
1361+ std::errc::invalid_argument,
1362+ " Invalid uint32 value for specialization constant '%s'" ,
1363+ SpecConst.Value .c_str ());
13401364 Entry.size = sizeof (uint32_t );
13411365 SpecData.resize (SpecData.size () + sizeof (uint32_t ));
13421366 memcpy (SpecData.data () + Entry.offset , &Value, sizeof (uint32_t ));
13431367 break ;
13441368 }
13451369 case DataFormat::Bool: {
13461370 bool Value = false ;
1347- llvm::StringRef (SpecConst.Value ).getAsInteger (0 , Value);
1371+ if (llvm::StringRef (SpecConst.Value ).getAsInteger (0 , Value))
1372+ return llvm::createStringError (
1373+ std::errc::invalid_argument,
1374+ " Invalid bool value for specialization constant '%s'" ,
1375+ SpecConst.Value .c_str ());
13481376 Entry.size = sizeof (bool );
13491377 SpecData.resize (SpecData.size () + sizeof (bool ));
13501378 memcpy (SpecData.data () + Entry.offset , &Value, sizeof (bool ));
@@ -1353,6 +1381,7 @@ class VKDevice : public offloadtest::Device {
13531381 default :
13541382 llvm_unreachable (" Unsupported specialization constant type" );
13551383 }
1384+ return llvm::Error::success ();
13561385 }
13571386
13581387 llvm::Error createPipeline (Pipeline &P, InvocationState &IS) {
@@ -1380,7 +1409,9 @@ class VKDevice : public offloadtest::Device {
13801409 if (!Shader.SpecializationConstants .empty ()) {
13811410 for (const auto &SpecConst : Shader.SpecializationConstants ) {
13821411 VkSpecializationMapEntry Entry;
1383- parseSpecializationConstant (SpecConst, Entry, SpecData);
1412+ if (auto Err =
1413+ parseSpecializationConstant (SpecConst, Entry, SpecData))
1414+ return Err;
13841415 SpecEntries.push_back (Entry);
13851416 }
13861417
0 commit comments