[flang-commits] [PATCH] D121145: [flang] Runtime validation of SPREAD(DIM=dim) argument

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Mar 7 11:45:55 PST 2022


klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

Crash when DIM= is not a valid dimension in the result.


https://reviews.llvm.org/D121145

Files:
  flang/runtime/transformational.cpp


Index: flang/runtime/transformational.cpp
===================================================================
--- flang/runtime/transformational.cpp
+++ flang/runtime/transformational.cpp
@@ -456,6 +456,11 @@
   Terminator terminator{sourceFile, line};
   int rank{source.rank() + 1};
   RUNTIME_CHECK(terminator, rank <= maxRank);
+  if (dim < 1 || dim > rank) {
+    terminator.Crash("SPREAD: DIM=%d argument for rank-%d source array "
+                     "must be greater than 1 and less than or equal to %d",
+        dim, rank - 1, rank);
+  }
   ncopies = std::max<std::int64_t>(ncopies, 0);
   SubscriptValue extent[maxRank];
   int k{0};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121145.413577.patch
Type: text/x-patch
Size: 648 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220307/f0e9f0d2/attachment-0001.bin>


More information about the flang-commits mailing list