Skip to content

Commit

Permalink
EmitC: Allow arrays of size zero (llvm#123292)
Browse files Browse the repository at this point in the history
This is allowed as a GCC extension, see
https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html.
  • Loading branch information
mgehre-amd authored Jan 17, 2025
1 parent 1181921 commit 0bd0765
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
2 changes: 2 additions & 0 deletions mlir/docs/Dialects/emitc.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ The following convention is followed:
floating types.
* If `__bf16` is used, the code requires a compiler that supports it, such as
GCC or Clang.
* If `emitc.array` with a dimension of size zero is used, then the code
requires [a GCC extension](https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html).
* Else the generated code is compatible with C99.

These restrictions are neither inherent to the EmitC dialect itself nor to the
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Dialect/EmitC/IR/EmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,8 @@ LogicalResult emitc::ArrayType::verify(
return emitError() << "shape must not be empty";

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

if (!elementType)
Expand Down
8 changes: 0 additions & 8 deletions mlir/test/Dialect/EmitC/invalid_types.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ func.func @illegal_array_missing_x(

// -----

func.func @illegal_array_non_positive_dimenson(
// expected-error @+1 {{dimensions must have positive size}}
%arg0: !emitc.array<0xi32>
) {
}

// -----

func.func @illegal_array_missing_type(
// expected-error @+1 {{expected non-function type}}
%arg0: !emitc.array<10x>
Expand Down
4 changes: 3 additions & 1 deletion mlir/test/Dialect/EmitC/types.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ func.func @array_types(
// CHECK-SAME: !emitc.array<30x!emitc.ssize_t>
%arg5: !emitc.array<30x!emitc.ssize_t>,
// CHECK-SAME: !emitc.array<30x!emitc.ptrdiff_t>
%arg6: !emitc.array<30x!emitc.ptrdiff_t>
%arg6: !emitc.array<30x!emitc.ptrdiff_t>,
// CHECK-SAME: !emitc.array<0xi64>
%arg7: !emitc.array<0xi64>
) {
return
}
Expand Down

0 comments on commit 0bd0765

Please sign in to comment.