[PATCH] D113092: [fir] Restrict array type on fir.insert_on_range
Valentin Clement via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 3 03:04:08 PDT 2021
clementval created this revision.
clementval added reviewers: jeanPerier, schweitz.
Herald added a subscriber: mehdi_amini.
Herald added a project: Flang.
clementval requested review of this revision.
Herald added subscribers: llvm-commits, jdoerfert.
Herald added a project: LLVM.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D113092
Files:
flang/lib/Optimizer/Dialect/FIROps.cpp
flang/test/Fir/invalid.fir
Index: flang/test/Fir/invalid.fir
===================================================================
--- flang/test/Fir/invalid.fir
+++ flang/test/Fir/invalid.fir
@@ -464,6 +464,26 @@
// -----
+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>
Index: flang/lib/Optimizer/Dialect/FIROps.cpp
===================================================================
--- flang/lib/Optimizer/Dialect/FIROps.cpp
+++ flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -1387,6 +1387,10 @@
/// 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()) ||
+ fir::sequenceWithNonConstantShape(
+ op.seq().getType().cast<fir::SequenceType>()))
+ 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113092.384377.patch
Type: text/x-patch
Size: 1910 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211103/0844387a/attachment.bin>
More information about the llvm-commits
mailing list