forked from OSchip/llvm-project
[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:
parent
ec642ceebc
commit
3df6cadec4
|
@ -739,6 +739,10 @@ static void emitAttrGetterWithReturnType(FmtContext &fctx,
|
||||||
// Returns the default value if not set.
|
// Returns the default value if not set.
|
||||||
// TODO: this is inefficient, we are recreating the attribute for every
|
// TODO: this is inefficient, we are recreating the attribute for every
|
||||||
// call. This should be set instead.
|
// call. This should be set instead.
|
||||||
|
if (!attr.isConstBuildable()) {
|
||||||
|
PrintFatalError("DefaultValuedAttr of type " + attr.getAttrDefName() +
|
||||||
|
" must have a constBuilder");
|
||||||
|
}
|
||||||
std::string defaultValue = std::string(
|
std::string defaultValue = std::string(
|
||||||
tgfmt(attr.getConstBuilderTemplate(), &fctx, attr.getDefaultValue()));
|
tgfmt(attr.getConstBuilderTemplate(), &fctx, attr.getDefaultValue()));
|
||||||
body << " if (!attr)\n return "
|
body << " if (!attr)\n return "
|
||||||
|
|
Loading…
Reference in New Issue