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

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Thu Jun 23 10:32:35 PDT 2022


Author: Peter Klausler
Date: 2022-06-23T10:32:22-07:00
New Revision: b6fce8b92df5dca2115e8462ae2a1849d7dd66b0

URL: https://github.com/llvm/llvm-project/commit/b6fce8b92df5dca2115e8462ae2a1849d7dd66b0
DIFF: https://github.com/llvm/llvm-project/commit/b6fce8b92df5dca2115e8462ae2a1849d7dd66b0.diff

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

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.

Differential Revision: https://reviews.llvm.org/D128391

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index c96bc364e343..b8908555f8e8 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -345,7 +345,7 @@ bool IsArrayElement(const Expr<T> &expr, bool intoSubstring = true,
 
 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> {

diff  --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index 241f008c6d89..bc9e389cfed9 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -1561,14 +1561,14 @@ std::optional<SpecificCall> IntrinsicInterface::Match(
             (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,

diff  --git a/flang/test/Semantics/misc-intrinsics.f90 b/flang/test/Semantics/misc-intrinsics.f90
index 0dc65fbd098c..b454d4764e41 100644
--- a/flang/test/Semantics/misc-intrinsics.f90
+++ b/flang/test/Semantics/misc-intrinsics.f90
@@ -19,5 +19,8 @@ subroutine test(arg)
     print *, size(array)
     print *, ubound(array)
     print *, lbound(array)
+    print *, size(arg(:,1))
+    print *, ubound(arg(:,1))
+    print *, shape(arg(:,1))
   end subroutine
 end


        


More information about the flang-commits mailing list