[mlir] ODS: require DefaultValuedAttr to be const-buildable

ODS provides a mechanism for defalut-valued attributes based on a wrapper
TableGen class that is recognized by mlir-tblgen. Such attributes, if not set
on the operaiton, can be construted on-the-fly in their getter given a constant
value. In order for this construction to work, the attribute specificaiton in
ODS must set the constBuilderCall field correctly. This has not been verified,
which could lead to invalid C++ code being generated by mlir-tblgen.

Closes #53588.

Reviewed By: rriddle, mehdi_amini

Differential Revision: https://reviews.llvm.org/D119113
This commit is contained in:
Alex Zinenko 2022-02-07 10:27:07 +01:00
parent ec642ceebc
commit 3df6cadec4
1 changed files with 4 additions and 0 deletions

View File

@ -739,6 +739,10 @@ static void emitAttrGetterWithReturnType(FmtContext &fctx,
// Returns the default value if not set.
// TODO: this is inefficient, we are recreating the attribute for every
// call. This should be set instead.
if (!attr.isConstBuildable()) {
PrintFatalError("DefaultValuedAttr of type " + attr.getAttrDefName() +
" must have a constBuilder");
}
std::string defaultValue = std::string(
tgfmt(attr.getConstBuilderTemplate(), &fctx, attr.getDefaultValue()));
body << " if (!attr)\n return "