@@ -881,15 +881,11 @@ static LogicalResult printFunctionArgs(CppEmitter &emitter,
881881 Region::BlockArgListType arguments) {
882882 raw_indented_ostream &os = emitter.ostream ();
883883
884- if (failed (interleaveCommaWithError (arguments, os,
885- [&](BlockArgument arg) -> LogicalResult {
886- return emitter.emitVariableDeclaration (
887- functionOp->getLoc (), arg.getType (),
888- emitter.getOrCreateName (arg));
889- })))
890- return failure ();
891-
892- return success ();
884+ return (interleaveCommaWithError (
885+ arguments, os, [&](BlockArgument arg) -> LogicalResult {
886+ return emitter.emitVariableDeclaration (
887+ functionOp->getLoc (), arg.getType (), emitter.getOrCreateName (arg));
888+ }));
893889}
894890
895891static LogicalResult printFunctionBody (CppEmitter &emitter,
@@ -932,6 +928,9 @@ static LogicalResult printFunctionBody(CppEmitter &emitter,
932928 if (emitter.hasValueInScope (arg))
933929 return functionOp->emitOpError (" block argument #" )
934930 << arg.getArgNumber () << " is out of scope" ;
931+ if (isa<ArrayType>(arg.getType ()))
932+ return functionOp->emitOpError (" cannot emit block argument #" )
933+ << arg.getArgNumber () << " with array type" ;
935934 if (failed (
936935 emitter.emitType (block.getParentOp ()->getLoc (), arg.getType ()))) {
937936 return failure ();
@@ -975,6 +974,11 @@ static LogicalResult printOperation(CppEmitter &emitter,
975974 " with multiple blocks needs variables declared at top" );
976975 }
977976
977+ if (llvm::any_of (functionOp.getResultTypes (),
978+ [](Type type) { return isa<ArrayType>(type); })) {
979+ return functionOp.emitOpError () << " cannot emit array type as result type" ;
980+ }
981+
978982 CppEmitter::Scope scope (emitter);
979983 raw_indented_ostream &os = emitter.ostream ();
980984 if (failed (emitter.emitTypes (functionOp.getLoc (),
@@ -1489,6 +1493,8 @@ LogicalResult CppEmitter::emitType(Location loc, Type type) {
14891493 if (!tType.hasStaticShape ())
14901494 return emitError (loc, " cannot emit tensor type with non static shape" );
14911495 os << " Tensor<" ;
1496+ if (isa<ArrayType>(tType.getElementType ()))
1497+ return emitError (loc, " cannot emit tensor of array type " ) << type;
14921498 if (failed (emitType (loc, tType.getElementType ())))
14931499 return failure ();
14941500 auto shape = tType.getShape ();
@@ -1505,7 +1511,16 @@ LogicalResult CppEmitter::emitType(Location loc, Type type) {
15051511 os << oType.getValue ();
15061512 return success ();
15071513 }
1514+ if (auto aType = dyn_cast<emitc::ArrayType>(type)) {
1515+ if (failed (emitType (loc, aType.getElementType ())))
1516+ return failure ();
1517+ for (auto dim : aType.getShape ())
1518+ os << " [" << dim << " ]" ;
1519+ return success ();
1520+ }
15081521 if (auto pType = dyn_cast<emitc::PointerType>(type)) {
1522+ if (isa<ArrayType>(pType.getPointee ()))
1523+ return emitError (loc, " cannot emit pointer to array type " ) << type;
15091524 if (failed (emitType (loc, pType.getPointee ())))
15101525 return failure ();
15111526 os << " *" ;
@@ -1527,6 +1542,9 @@ LogicalResult CppEmitter::emitTypes(Location loc, ArrayRef<Type> types) {
15271542}
15281543
15291544LogicalResult CppEmitter::emitTupleType (Location loc, ArrayRef<Type> types) {
1545+ if (llvm::any_of (types, [](Type type) { return isa<ArrayType>(type); })) {
1546+ return emitError (loc, " cannot emit tuple of array type" );
1547+ }
15301548 os << " std::tuple<" ;
15311549 if (failed (interleaveCommaWithError (
15321550 types, os, [&](Type type) { return emitType (loc, type); })))
0 commit comments