@@ -904,6 +904,9 @@ static LogicalResult printFunctionBody(CppEmitter &emitter,
904904 if (emitter.hasValueInScope (arg))
905905 return functionOp->emitOpError (" block argument #" )
906906 << arg.getArgNumber () << " is out of scope" ;
907+ if (isa<ArrayType>(arg.getType ()))
908+ return functionOp->emitOpError (" cannot emit block argument #" )
909+ << arg.getArgNumber () << " with array type" ;
907910 if (failed (
908911 emitter.emitType (block.getParentOp ()->getLoc (), arg.getType ()))) {
909912 return failure ();
@@ -947,6 +950,11 @@ static LogicalResult printOperation(CppEmitter &emitter,
947950 " with multiple blocks needs variables declared at top" );
948951 }
949952
953+ if (llvm::any_of (functionOp.getResultTypes (),
954+ [](Type type) { return isa<ArrayType>(type); })) {
955+ return functionOp.emitOpError () << " cannot emit array type as result type" ;
956+ }
957+
950958 CppEmitter::Scope scope (emitter);
951959 raw_indented_ostream &os = emitter.ostream ();
952960 if (failed (emitter.emitTypes (functionOp.getLoc (),
@@ -1445,6 +1453,8 @@ LogicalResult CppEmitter::emitType(Location loc, Type type) {
14451453 if (!tType.hasStaticShape ())
14461454 return emitError (loc, " cannot emit tensor type with non static shape" );
14471455 os << " Tensor<" ;
1456+ if (isa<ArrayType>(tType.getElementType ()))
1457+ return emitError (loc, " cannot emit tensor of array type " ) << type;
14481458 if (failed (emitType (loc, tType.getElementType ())))
14491459 return failure ();
14501460 auto shape = tType.getShape ();
@@ -1461,7 +1471,16 @@ LogicalResult CppEmitter::emitType(Location loc, Type type) {
14611471 os << oType.getValue ();
14621472 return success ();
14631473 }
1474+ if (auto aType = dyn_cast<emitc::ArrayType>(type)) {
1475+ if (failed (emitType (loc, aType.getElementType ())))
1476+ return failure ();
1477+ for (auto dim : aType.getShape ())
1478+ os << " [" << dim << " ]" ;
1479+ return success ();
1480+ }
14641481 if (auto pType = dyn_cast<emitc::PointerType>(type)) {
1482+ if (isa<ArrayType>(pType.getPointee ()))
1483+ return emitError (loc, " cannot emit pointer to array type " ) << type;
14651484 if (failed (emitType (loc, pType.getPointee ())))
14661485 return failure ();
14671486 os << " *" ;
@@ -1483,6 +1502,9 @@ LogicalResult CppEmitter::emitTypes(Location loc, ArrayRef<Type> types) {
14831502}
14841503
14851504LogicalResult CppEmitter::emitTupleType (Location loc, ArrayRef<Type> types) {
1505+ if (llvm::any_of (types, [](Type type) { return isa<ArrayType>(type); })) {
1506+ return emitError (loc, " cannot emit tuple of array type" );
1507+ }
14861508 os << " std::tuple<" ;
14871509 if (failed (interleaveCommaWithError (
14881510 types, os, [&](Type type) { return emitType (loc, type); })))
0 commit comments