[flang-commits] [PATCH] D128391: [flang] Fix bogus errors from SIZE/SHAPE/UBOUND on assumed-shape

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Jun 22 15:39:31 PDT 2022


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

While it is indeed an error to use SIZE, SHAPE, or UBOUND on an
assumed-shape dummy argument without also supplying a DIM= argument
to the intrinsic function, it is *not* an error to use these intrinsic
functions on sections or expressions of such arrays.  Refine the test
used for the error message.


https://reviews.llvm.org/D128391

Files:
  flang/include/flang/Evaluate/tools.h
  flang/lib/Evaluate/intrinsics.cpp
  flang/test/Semantics/misc-intrinsics.f90


Index: flang/test/Semantics/misc-intrinsics.f90
===================================================================
--- flang/test/Semantics/misc-intrinsics.f90
+++ flang/test/Semantics/misc-intrinsics.f90
@@ -19,5 +19,8 @@
     print *, size(array)
     print *, ubound(array)
     print *, lbound(array)
+    print *, size(arg(:,1))
+    print *, ubound(arg(:,1))
+    print *, shape(arg(:,1))
   end subroutine
 end
Index: flang/lib/Evaluate/intrinsics.cpp
===================================================================
--- flang/lib/Evaluate/intrinsics.cpp
+++ flang/lib/Evaluate/intrinsics.cpp
@@ -1561,14 +1561,14 @@
             (std::strcmp(name, "shape") == 0 ||
                 std::strcmp(name, "size") == 0 ||
                 std::strcmp(name, "ubound") == 0)) {
-          // Check for an assumed-size array argument.
+          // Check for a whole assumed-size array argument.
           // These are disallowed for SHAPE, and require DIM= for
           // SIZE and UBOUND.
           // (A previous error message for UBOUND will take precedence
           // over this one, as this error is caught by the second entry
           // for UBOUND.)
-          if (const Symbol * argSym{GetLastSymbol(*arg)}) {
-            if (semantics::IsAssumedSizeArray(*argSym)) {
+          if (auto named{ExtractNamedEntity(*arg)}) {
+            if (semantics::IsAssumedSizeArray(named->GetLastSymbol())) {
               if (strcmp(name, "shape") == 0) {
                 messages.Say(arg->sourceLocation(),
                     "The '%s=' argument to the intrinsic function '%s' may not be assumed-size"_err_en_US,
Index: flang/include/flang/Evaluate/tools.h
===================================================================
--- flang/include/flang/Evaluate/tools.h
+++ flang/include/flang/Evaluate/tools.h
@@ -345,7 +345,7 @@
 
 template <typename A>
 std::optional<NamedEntity> ExtractNamedEntity(const A &x) {
-  if (auto dataRef{ExtractDataRef(x, true)}) {
+  if (auto dataRef{ExtractDataRef(x)}) {
     return common::visit(
         common::visitors{
             [](SymbolRef &&symbol) -> std::optional<NamedEntity> {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128391.439188.patch
Type: text/x-patch
Size: 2140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220622/90494a70/attachment.bin>


More information about the flang-commits mailing list