- For function like operations, empty regions indicate declarations, so we should not accept an empty region when parsing.
- See https://llvm.discourse.group/t/funcop-parsing-bug/2164
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Can't the users of parseRegion just check to see if it is empty after success and emit an error if they don't want that behavior?
Not really. Note that both
func @foo() func @foo() {}
post parsing look the same (the region attached to FuncOp is empty). So that's too late for the check.
mlir/lib/IR/FunctionImplementation.cpp | ||
---|---|---|
210 | For reference, we cannot do the error check here after parser.parseOptionalRegion() because there is no way to distinguish between no region in the assembly (func @foo) vs an empty region (func @foo {}). |
mlir/lib/IR/FunctionImplementation.cpp | ||
---|---|---|
210 | OptionalParseResult represents 3 different value states. Just change the other parseOptionalRegion to use OptionalParseResult (which it should be doing anyways). Then you could do the following: OptionalParseResult result = parser.parseOptionalRegion(region); if (result) { if (failed(*result)) return failure(); if (region.empty()) ... } return success(); |
For reference, we cannot do the error check here after parser.parseOptionalRegion() because there is no way to distinguish between no region in the assembly (func @foo) vs an empty region (func @foo {}).