@@ -904,6 +904,9 @@ static LogicalResult printFunctionBody(CppEmitter &emitter,
904
904
if (emitter.hasValueInScope (arg))
905
905
return functionOp->emitOpError (" block argument #" )
906
906
<< 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" ;
907
910
if (failed (
908
911
emitter.emitType (block.getParentOp ()->getLoc (), arg.getType ()))) {
909
912
return failure ();
@@ -947,6 +950,11 @@ static LogicalResult printOperation(CppEmitter &emitter,
947
950
" with multiple blocks needs variables declared at top" );
948
951
}
949
952
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
+
950
958
CppEmitter::Scope scope (emitter);
951
959
raw_indented_ostream &os = emitter.ostream ();
952
960
if (failed (emitter.emitTypes (functionOp.getLoc (),
@@ -1445,6 +1453,8 @@ LogicalResult CppEmitter::emitType(Location loc, Type type) {
1445
1453
if (!tType.hasStaticShape ())
1446
1454
return emitError (loc, " cannot emit tensor type with non static shape" );
1447
1455
os << " Tensor<" ;
1456
+ if (isa<ArrayType>(tType.getElementType ()))
1457
+ return emitError (loc, " cannot emit tensor of array type " ) << type;
1448
1458
if (failed (emitType (loc, tType.getElementType ())))
1449
1459
return failure ();
1450
1460
auto shape = tType.getShape ();
@@ -1461,7 +1471,16 @@ LogicalResult CppEmitter::emitType(Location loc, Type type) {
1461
1471
os << oType.getValue ();
1462
1472
return success ();
1463
1473
}
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
+ }
1464
1481
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;
1465
1484
if (failed (emitType (loc, pType.getPointee ())))
1466
1485
return failure ();
1467
1486
os << " *" ;
@@ -1483,6 +1502,9 @@ LogicalResult CppEmitter::emitTypes(Location loc, ArrayRef<Type> types) {
1483
1502
}
1484
1503
1485
1504
LogicalResult 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
+ }
1486
1508
os << " std::tuple<" ;
1487
1509
if (failed (interleaveCommaWithError (
1488
1510
types, os, [&](Type type) { return emitType (loc, type); })))
0 commit comments