[flang-commits] [PATCH] D145748: [flang] Detect obvious argument shape incompatibility when checking procedure compatibility

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Mar 10 09:49:18 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGae426a054b0c: [flang] Detect obvious argument shape incompatibility when checking procedure… (authored by klausler).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145748/new/

https://reviews.llvm.org/D145748

Files:
  flang/lib/Evaluate/characteristics.cpp
  flang/test/Semantics/argshape01.f90


Index: flang/test/Semantics/argshape01.f90
===================================================================
--- /dev/null
+++ flang/test/Semantics/argshape01.f90
@@ -0,0 +1,41 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+! Detect incompatible argument shapes
+module m
+ contains
+  subroutine s1(a)
+    real, intent(in) :: a(2,3)
+  end
+  subroutine s2(a)
+    real, intent(in) :: a(3,2)
+  end
+  subroutine s1c(s)
+    procedure(s1) :: s
+  end
+  subroutine s2c(s)
+    procedure(s2) :: s
+  end
+end
+
+program main
+  use m
+  procedure(s1), pointer :: ps1
+  procedure(s2), pointer :: ps2
+  call s1c(s1)
+  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
+  call s1c(s2)
+  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
+  call s2c(s1)
+  call s2c(s2)
+  ps1 => s1
+  !ERROR: Procedure pointer 'ps1' associated with incompatible procedure designator 's2': incompatible dummy argument #1: incompatible dummy data object shapes
+  ps1 => s2
+  !ERROR: Procedure pointer 'ps2' associated with incompatible procedure designator 's1': incompatible dummy argument #1: incompatible dummy data object shapes
+  ps2 => s1
+  ps2 => s2
+  call s1c(ps1)
+  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
+  call s1c(ps2)
+  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
+  call s2c(ps1)
+  call s2c(ps2)
+end
Index: flang/lib/Evaluate/characteristics.cpp
===================================================================
--- flang/lib/Evaluate/characteristics.cpp
+++ flang/lib/Evaluate/characteristics.cpp
@@ -263,8 +263,22 @@
 }
 
 static bool AreCompatibleDummyDataObjectShapes(const Shape &x, const Shape &y) {
-  // TODO: Validate more than just compatible ranks
-  return GetRank(x) == GetRank(y);
+  int n{GetRank(x)};
+  if (n != GetRank(y)) {
+    return false;
+  }
+  auto xIter{x.begin()};
+  auto yIter{y.begin()};
+  for (; n-- > 0; ++xIter, ++yIter) {
+    if (auto xVal{ToInt64(*xIter)}) {
+      if (auto yVal{ToInt64(*yIter)}) {
+        if (*xVal != *yVal) {
+          return false;
+        }
+      }
+    }
+  }
+  return true;
 }
 
 bool DummyDataObject::IsCompatibleWith(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145748.504191.patch
Type: text/x-patch
Size: 2549 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230310/6c34af68/attachment-0001.bin>


More information about the flang-commits mailing list