Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/unreleased/th__fix_SetFuncAllowAttrs_assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fixed:
- Avoid assertion failure from `SetFuncAllowAttrs` when struct is empty to allow `verify()` to pass on empty StructDefOp
27 changes: 15 additions & 12 deletions lib/Dialect/Struct/IR/Ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,21 @@ bool isInStructFunctionNamed(Operation *op, char const *funcName) {
// Again, only valid/implemented for StructDefOp
template <> LogicalResult SetFuncAllowAttrs<StructDefOp>::verifyTrait(Operation *structOp) {
assert(llvm::isa<StructDefOp>(structOp));
llvm::cast<StructDefOp>(structOp).getBody()->walk([](FuncDefOp funcDef) {
if (funcDef.nameIsConstrain()) {
funcDef.setAllowConstraintAttr();
funcDef.setAllowWitnessAttr(false);
} else if (funcDef.nameIsCompute()) {
funcDef.setAllowConstraintAttr(false);
funcDef.setAllowWitnessAttr();
} else if (funcDef.nameIsProduct()) {
funcDef.setAllowConstraintAttr();
funcDef.setAllowWitnessAttr();
}
});
Region &bodyRegion = llvm::cast<StructDefOp>(structOp).getBodyRegion();
if (!bodyRegion.empty()) {
bodyRegion.front().walk([](FuncDefOp funcDef) {
if (funcDef.nameIsConstrain()) {
funcDef.setAllowConstraintAttr();
funcDef.setAllowWitnessAttr(false);
} else if (funcDef.nameIsCompute()) {
funcDef.setAllowConstraintAttr(false);
funcDef.setAllowWitnessAttr();
} else if (funcDef.nameIsProduct()) {
funcDef.setAllowConstraintAttr();
funcDef.setAllowWitnessAttr();
}
});
}
return success();
}

Expand Down
Loading