Move FunctionOp arg attr verify to model verify

This commit is contained in:
Lauri Vasama
2026-03-27 15:55:08 +02:00
parent f75a122400
commit de0e59b188
2 changed files with 27 additions and 23 deletions
-23
View File
@@ -462,29 +462,6 @@ mlir::LogicalResult FunctionOp::verify() {
return mlir::success();
});
for (uint64_t Index = 0; Index < getArgCount(); ++Index) {
uint64_t RegAttributeCount = 0;
uint64_t StackAttributeCount = 0;
mlir::clift::AttrDictView View = getArgAttrs(Index);
if (auto CAs = View.getOfType<mlir::ArrayAttr>("clift.c_attributes")) {
for (mlir::Attribute CAttribute : CAs) {
auto AttrName = mlir::cast<mlir::clift::CAttributeAttr>(CAttribute)
.getName()
.getName();
if (AttrName == "_REG")
++RegAttributeCount;
else if (AttrName == "_STACK")
++StackAttributeCount;
}
}
revng_assert(RegAttributeCount <= 1 and StackAttributeCount <= 1);
if (RegAttributeCount + StackAttributeCount > 1)
return emitOpError() << "An argument is not allowed to specify *both* "
" `_REG` and `_STACK` attributes.";
}
return mlir::failure(Result.wasInterrupted());
}
+27
View File
@@ -205,6 +205,33 @@ private:
"definition: '"
<< Op.getHandle() << "'";
for (unsigned Index = 0; Index < Op.getArgCount(); ++Index) {
bool IsStack = false;
bool IsRegister = false;
mlir::clift::AttrDictView View = Op.getArgAttrs(Index);
if (auto CAs = View.getOfType<mlir::ArrayAttr>("clift.c_attributes")) {
for (mlir::Attribute CAttribute : CAs) {
auto AttrName = mlir::cast<clift::CAttributeAttr>(CAttribute)
.getName()
.getName();
if (AttrName == "_STACK" and std::exchange(IsStack, true))
return getCurrentOp()->emitError() << "Function argument contains "
"duplicate _STACK attribute.";
if (AttrName == "_REG" and std::exchange(IsRegister, true))
return getCurrentOp()->emitError() << "Function argument contains "
"duplicate _REG attribute.";
if (IsStack and IsRegister)
return getCurrentOp()->emitError() << "Function argument contains "
"both _STACK and _REG "
"attributes.";
}
}
}
return mlir::success();
}