@@ -1398,16 +1398,25 @@ getIntegerPairAttribute(const Function &F, StringRef Name,
13981398SmallVector<unsigned > getIntegerVecAttribute (const Function &F, StringRef Name,
13991399 unsigned Size,
14001400 unsigned DefaultVal) {
1401+ std::optional<SmallVector<unsigned >> R =
1402+ getIntegerVecAttribute (F, Name, Size);
1403+ return R.has_value () ? *R : SmallVector<unsigned >(Size, DefaultVal);
1404+ }
1405+
1406+ std::optional<SmallVector<unsigned >>
1407+ getIntegerVecAttribute (const Function &F, StringRef Name, unsigned Size) {
14011408 assert (Size > 2 );
1402- SmallVector< unsigned > Default (Size, DefaultVal );
1409+ LLVMContext &Ctx = F. getContext ( );
14031410
14041411 Attribute A = F.getFnAttribute (Name);
1405- if (!A.isStringAttribute ())
1406- return Default;
1407-
1408- SmallVector<unsigned > Vals (Size, DefaultVal);
1412+ if (!A.isValid ())
1413+ return std::nullopt ;
1414+ if (!A.isStringAttribute ()) {
1415+ Ctx.emitError (Name + " is not a string attribute" );
1416+ return std::nullopt ;
1417+ }
14091418
1410- LLVMContext &Ctx = F. getContext ( );
1419+ SmallVector< unsigned > Vals (Size );
14111420
14121421 StringRef S = A.getValueAsString ();
14131422 unsigned i = 0 ;
@@ -1417,7 +1426,7 @@ SmallVector<unsigned> getIntegerVecAttribute(const Function &F, StringRef Name,
14171426 if (Strs.first .trim ().getAsInteger (0 , IntVal)) {
14181427 Ctx.emitError (" can't parse integer attribute " + Strs.first + " in " +
14191428 Name);
1420- return Default ;
1429+ return std:: nullopt ;
14211430 }
14221431 Vals[i] = IntVal;
14231432 S = Strs.second ;
@@ -1427,7 +1436,7 @@ SmallVector<unsigned> getIntegerVecAttribute(const Function &F, StringRef Name,
14271436 Ctx.emitError (" attribute " + Name +
14281437 " has incorrect number of integers; expected " +
14291438 llvm::utostr (Size));
1430- return Default ;
1439+ return std:: nullopt ;
14311440 }
14321441 return Vals;
14331442}
0 commit comments