@@ -1563,23 +1563,33 @@ static void convertFunctionKernelAttributes(LLVMFuncOp func,
15631563 }
15641564}
15651565
1566- static void convertParameterAttr (llvm::AttrBuilder &attrBuilder,
1567- llvm::Attribute::AttrKind llvmKind,
1568- NamedAttribute namedAttr,
1569- ModuleTranslation &moduleTranslation) {
1570- llvm::TypeSwitch<Attribute>(namedAttr.getValue ())
1566+ static LogicalResult convertParameterAttr (llvm::AttrBuilder &attrBuilder,
1567+ llvm::Attribute::AttrKind llvmKind,
1568+ NamedAttribute namedAttr,
1569+ ModuleTranslation &moduleTranslation,
1570+ Location loc) {
1571+ return llvm::TypeSwitch<Attribute, LogicalResult>(namedAttr.getValue ())
15711572 .Case <TypeAttr>([&](auto typeAttr) {
15721573 attrBuilder.addTypeAttr (
15731574 llvmKind, moduleTranslation.convertType (typeAttr.getValue ()));
1575+ return success ();
15741576 })
15751577 .Case <IntegerAttr>([&](auto intAttr) {
15761578 attrBuilder.addRawIntAttr (llvmKind, intAttr.getInt ());
1579+ return success ();
1580+ })
1581+ .Case <UnitAttr>([&](auto ) {
1582+ attrBuilder.addAttribute (llvmKind);
1583+ return success ();
15771584 })
1578- .Case <UnitAttr>([&](auto ) { attrBuilder.addAttribute (llvmKind); })
15791585 .Case <LLVM::ConstantRangeAttr>([&](auto rangeAttr) {
15801586 attrBuilder.addConstantRangeAttr (
15811587 llvmKind,
15821588 llvm::ConstantRange (rangeAttr.getLower (), rangeAttr.getUpper ()));
1589+ return success ();
1590+ })
1591+ .Default ([loc](auto ) {
1592+ return emitError (loc, " unsupported parameter attribute type" );
15831593 });
15841594}
15851595
@@ -1588,12 +1598,15 @@ ModuleTranslation::convertParameterAttrs(LLVMFuncOp func, int argIdx,
15881598 DictionaryAttr paramAttrs) {
15891599 llvm::AttrBuilder attrBuilder (llvmModule->getContext ());
15901600 auto attrNameToKindMapping = getAttrNameToKindMapping ();
1601+ Location loc = func.getLoc ();
15911602
15921603 for (auto namedAttr : paramAttrs) {
15931604 auto it = attrNameToKindMapping.find (namedAttr.getName ());
15941605 if (it != attrNameToKindMapping.end ()) {
15951606 llvm::Attribute::AttrKind llvmKind = it->second ;
1596- convertParameterAttr (attrBuilder, llvmKind, namedAttr, *this );
1607+ if (failed (convertParameterAttr (attrBuilder, llvmKind, namedAttr, *this ,
1608+ loc)))
1609+ return failure ();
15971610 } else if (namedAttr.getNameDialect ()) {
15981611 if (failed (iface.convertParameterAttr (func, argIdx, namedAttr, *this )))
15991612 return failure ();
@@ -1604,15 +1617,19 @@ ModuleTranslation::convertParameterAttrs(LLVMFuncOp func, int argIdx,
16041617}
16051618
16061619FailureOr<llvm::AttrBuilder>
1607- ModuleTranslation::convertParameterAttrs (DictionaryAttr paramAttrs) {
1620+ ModuleTranslation::convertParameterAttrs (CallOpInterface callOp,
1621+ DictionaryAttr paramAttrs) {
16081622 llvm::AttrBuilder attrBuilder (llvmModule->getContext ());
1623+ Location loc = callOp.getLoc ();
16091624 auto attrNameToKindMapping = getAttrNameToKindMapping ();
16101625
16111626 for (auto namedAttr : paramAttrs) {
16121627 auto it = attrNameToKindMapping.find (namedAttr.getName ());
16131628 if (it != attrNameToKindMapping.end ()) {
16141629 llvm::Attribute::AttrKind llvmKind = it->second ;
1615- convertParameterAttr (attrBuilder, llvmKind, namedAttr, *this );
1630+ if (failed (convertParameterAttr (attrBuilder, llvmKind, namedAttr, *this ,
1631+ loc)))
1632+ return failure ();
16161633 }
16171634 }
16181635
0 commit comments