Skip to content

Commit 0bd0765

Browse files
authored
EmitC: Allow arrays of size zero (llvm#123292)
This is allowed as a GCC extension, see https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html.
1 parent 1181921 commit 0bd0765

File tree

4 files changed

+7
-11
lines changed

4 files changed

+7
-11
lines changed

mlir/docs/Dialects/emitc.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ The following convention is followed:
1616
floating types.
1717
* If `__bf16` is used, the code requires a compiler that supports it, such as
1818
GCC or Clang.
19+
* If `emitc.array` with a dimension of size zero is used, then the code
20+
requires [a GCC extension](https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html).
1921
* Else the generated code is compatible with C99.
2022

2123
These restrictions are neither inherent to the EmitC dialect itself nor to the

mlir/lib/Dialect/EmitC/IR/EmitC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -971,8 +971,8 @@ LogicalResult emitc::ArrayType::verify(
971971
return emitError() << "shape must not be empty";
972972

973973
for (int64_t dim : shape) {
974-
if (dim <= 0)
975-
return emitError() << "dimensions must have positive size";
974+
if (dim < 0)
975+
return emitError() << "dimensions must have non-negative size";
976976
}
977977

978978
if (!elementType)

mlir/test/Dialect/EmitC/invalid_types.mlir

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ func.func @illegal_array_missing_x(
3636

3737
// -----
3838

39-
func.func @illegal_array_non_positive_dimenson(
40-
// expected-error @+1 {{dimensions must have positive size}}
41-
%arg0: !emitc.array<0xi32>
42-
) {
43-
}
44-
45-
// -----
46-
4739
func.func @illegal_array_missing_type(
4840
// expected-error @+1 {{expected non-function type}}
4941
%arg0: !emitc.array<10x>

mlir/test/Dialect/EmitC/types.mlir

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ func.func @array_types(
1717
// CHECK-SAME: !emitc.array<30x!emitc.ssize_t>
1818
%arg5: !emitc.array<30x!emitc.ssize_t>,
1919
// CHECK-SAME: !emitc.array<30x!emitc.ptrdiff_t>
20-
%arg6: !emitc.array<30x!emitc.ptrdiff_t>
20+
%arg6: !emitc.array<30x!emitc.ptrdiff_t>,
21+
// CHECK-SAME: !emitc.array<0xi64>
22+
%arg7: !emitc.array<0xi64>
2123
) {
2224
return
2325
}

0 commit comments

Comments
 (0)