Skip to content

Commit b6cf384

Browse files
authored
[fir] Restrict array type on fir.insert_on_range
* [fir] Restrict array type on fir.insert_on_range Sequence type had no restriction on the insert_on_range operation. This patch adds a restriction for the type to have constant shape and size. Differential Revision: https://reviews.llvm.org/D113092
1 parent ee5aa72 commit b6cf384

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

flang/include/flang/Optimizer/Dialect/FIROps.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,8 @@ def fir_InsertOnRangeOp : fir_OneResultOp<"insert_on_range", [NoSideEffect]> {
20562056
let summary = "insert sub-value into a range on an existing sequence";
20572057

20582058
let description = [{
2059-
Insert copies of a value into an entity with an array type.
2059+
Insert copies of a value into an entity with an array type of constant shape
2060+
and size.
20602061
Returns a new ssa value with the same type as the original entity.
20612062
The values are inserted at a contiguous range of indices in Fortran
20622063
row-to-column element order as specified by lower and upper bound

flang/lib/Optimizer/Dialect/FIROps.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,8 @@ void fir::InsertOnRangeOp::build(mlir::OpBuilder &builder,
14621462

14631463
/// Range bounds must be nonnegative, and the range must not be empty.
14641464
static mlir::LogicalResult verify(fir::InsertOnRangeOp op) {
1465+
if (fir::hasDynamicSize(op.seq().getType()))
1466+
return op.emitOpError("must have constant shape and size");
14651467
if (op.coor().size() < 2 || op.coor().size() % 2 != 0)
14661468
return op.emitOpError("has uneven number of values in ranges");
14671469
bool rangeIsKnownToBeNonempty = false;

flang/test/Fir/invalid.fir

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,26 @@ fir.global internal @_QEmultiarray : !fir.array<32x32xi32> {
541541

542542
// -----
543543

544+
fir.global internal @_QEmultiarray : !fir.array<?xi32> {
545+
%c0_i32 = arith.constant 1 : i32
546+
%0 = fir.undefined !fir.array<?xi32>
547+
// expected-error@+1 {{'fir.insert_on_range' op must have constant shape and size}}
548+
%2 = fir.insert_on_range %0, %c0_i32, [0 : index, 10 : index] : (!fir.array<?xi32>, i32) -> !fir.array<?xi32>
549+
fir.has_value %2 : !fir.array<?xi32>
550+
}
551+
552+
// -----
553+
554+
fir.global internal @_QEmultiarray : !fir.array<*:i32> {
555+
%c0_i32 = arith.constant 1 : i32
556+
%0 = fir.undefined !fir.array<*:i32>
557+
// expected-error@+1 {{'fir.insert_on_range' op must have constant shape and size}}
558+
%2 = fir.insert_on_range %0, %c0_i32, [0 : index, 10 : index] : (!fir.array<*:i32>, i32) -> !fir.array<*:i32>
559+
fir.has_value %2 : !fir.array<*:i32>
560+
}
561+
562+
// -----
563+
544564
func @bad_array_modify(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index, %f : f32) {
545565
%i10 = arith.constant 10 : index
546566
%j20 = arith.constant 20 : index

0 commit comments

Comments
 (0)