[flang-commits] [flang] c86b450 - [fir] Restrict array type on fir.insert_on_range
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Thu Nov 4 00:54:13 PDT 2021
Author: Valentin Clement
Date: 2021-11-04T08:54:09+01:00
New Revision: c86b4503a94c277534ce4b9a5c015a6ac151b98a
URL: https://github.com/llvm/llvm-project/commit/c86b4503a94c277534ce4b9a5c015a6ac151b98a
DIFF: https://github.com/llvm/llvm-project/commit/c86b4503a94c277534ce4b9a5c015a6ac151b98a.diff
LOG: [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.
Reviewed By: mehdi_amini
Differential Revision: https://reviews.llvm.org/D113092
Added:
Modified:
flang/include/flang/Optimizer/Dialect/FIROps.td
flang/lib/Optimizer/Dialect/FIROps.cpp
flang/test/Fir/invalid.fir
Removed:
################################################################################
diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td
index 963c06de66597..1a6cd9b7f00fc 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROps.td
+++ b/flang/include/flang/Optimizer/Dialect/FIROps.td
@@ -1978,7 +1978,8 @@ def fir_InsertOnRangeOp : fir_OneResultOp<"insert_on_range", [NoSideEffect]> {
let summary = "insert sub-value into a range on an existing sequence";
let description = [{
- Insert copies of a value into an entity with an array type.
+ Insert copies of a value into an entity with an array type of constant shape
+ and size.
Returns a new ssa value with the same type as the original entity.
The values are inserted at a contiguous range of indices in Fortran
row-to-column element order as specified by lower and upper bound
diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index 6196d3a375b72..bdeced9c7b617 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -1387,6 +1387,8 @@ void fir::FieldIndexOp::build(mlir::OpBuilder &builder,
/// Range bounds must be nonnegative, and the range must not be empty.
static mlir::LogicalResult verify(fir::InsertOnRangeOp op) {
+ if (fir::hasDynamicSize(op.seq().getType()))
+ return op.emitOpError("must have constant shape and size");
if (op.coor().size() < 2 || op.coor().size() % 2 != 0)
return op.emitOpError("has uneven number of values in ranges");
bool rangeIsKnownToBeNonempty = false;
diff --git a/flang/test/Fir/invalid.fir b/flang/test/Fir/invalid.fir
index d25322245c598..8bc2ac6793e8c 100644
--- a/flang/test/Fir/invalid.fir
+++ b/flang/test/Fir/invalid.fir
@@ -464,6 +464,26 @@ fir.global internal @_QEmultiarray : !fir.array<32x32xi32> {
// -----
+fir.global internal @_QEmultiarray : !fir.array<?xi32> {
+ %c0_i32 = arith.constant 1 : i32
+ %0 = fir.undefined !fir.array<?xi32>
+ // expected-error at +1 {{'fir.insert_on_range' op must have constant shape and size}}
+ %2 = fir.insert_on_range %0, %c0_i32, [0 : index, 10 : index] : (!fir.array<?xi32>, i32) -> !fir.array<?xi32>
+ fir.has_value %2 : !fir.array<?xi32>
+}
+
+// -----
+
+fir.global internal @_QEmultiarray : !fir.array<*:i32> {
+ %c0_i32 = arith.constant 1 : i32
+ %0 = fir.undefined !fir.array<*:i32>
+ // expected-error at +1 {{'fir.insert_on_range' op must have constant shape and size}}
+ %2 = fir.insert_on_range %0, %c0_i32, [0 : index, 10 : index] : (!fir.array<*:i32>, i32) -> !fir.array<*:i32>
+ fir.has_value %2 : !fir.array<*:i32>
+}
+
+// -----
+
func @bad_save_result(%buffer : !fir.ref<!fir.array<?xf64>>, %n :index) {
%res = fir.call @array_func() : () -> !fir.array<?xf32>
%shape = fir.shape %n : (index) -> !fir.shape<1>
More information about the flang-commits
mailing list