[flang] Pointer assignment bounds, section subscript, substring
authorTim Keith <tkeith@nvidia.com>
Tue, 2 Apr 2019 22:36:20 +0000 (15:36 -0700)
committerTim Keith <tkeith@nvidia.com>
Tue, 2 Apr 2019 22:36:20 +0000 (15:36 -0700)
Resolve bounds in pointer assignment.
Remove TODOs for section-subscript and substring range.
Add tests that verify they are done.

Original-commit: flang-compiler/f18@dc2dd85a9a2b08ca906fd53d11faa2886863d4c4
Reviewed-on: https://github.com/flang-compiler/f18/pull/380

flang/lib/semantics/resolve-names.cc
flang/test/semantics/CMakeLists.txt
flang/test/semantics/resolve49.f90 [new file with mode: 0644]

index c05c3adc37e935af78b1d31a218e76f48f626d01..2cd93d2f5fa65837a6fa97f49c3b0147d7ebea4f 100644 (file)
@@ -4251,10 +4251,6 @@ const parser::Name *ResolveNamesVisitor::ResolveStructureComponent(
 
 const parser::Name *ResolveNamesVisitor::ResolveArrayElement(
     const parser::ArrayElement &x) {
-  // TODO: need to resolve these
-  // for (auto &subscript : x.subscripts) {
-  //  ResolveSectionSubscript(subscript);
-  //}
   return ResolveDataRef(x.base);
 }
 
@@ -4611,8 +4607,10 @@ void ResolveNamesVisitor::Post(const parser::AllocateObject &x) {
 }
 bool ResolveNamesVisitor::Pre(const parser::PointerAssignmentStmt &x) {
   const auto &dataRef{std::get<parser::DataRef>(x.t)};
+  const auto &bounds{std::get<parser::PointerAssignmentStmt::Bounds>(x.t)};
   const auto &expr{std::get<parser::Expr>(x.t)};
-  ResolveDataRef(dataRef);;
+  ResolveDataRef(dataRef);
+  Walk(bounds);
   // Resolve unrestricted specific intrinsic procedures as in "p => cos".
   if (const auto *designator{
           std::get_if<common::Indirection<parser::Designator>>(&expr.u)}) {
@@ -4626,10 +4624,13 @@ bool ResolveNamesVisitor::Pre(const parser::PointerAssignmentStmt &x) {
                 [](const auto &) -> const parser::Name * { return nullptr; },
             },
             designator->value().u)}) {
-      return !NameIsKnownOrIntrinsic(*name);
+      if (NameIsKnownOrIntrinsic(*name)) {
+        return false;
+      }
     }
   }
-  return true;
+  Walk(expr);
+  return false;
 }
 void ResolveNamesVisitor::Post(const parser::Designator &x) {
   std::visit(
@@ -4638,7 +4639,6 @@ void ResolveNamesVisitor::Post(const parser::Designator &x) {
           [&](const parser::DataRef &x) { ResolveDataRef(x); },
           [&](const parser::Substring &x) {
             ResolveDataRef(std::get<parser::DataRef>(x.t));
-            // TODO: SubstringRange
           },
       },
       x.u);
index 32c4ad66b0dbd0e1d35bd2808aba8f8fc539a9d4..352f4a9d2dd3d32617fbf1c3bddb252663784737 100644 (file)
@@ -75,6 +75,7 @@ set(ERROR_TESTS
   resolve46.f90
   resolve47.f90
   resolve48.f90
+  resolve49.f90
   structconst01.f90
   structconst02.f90
   structconst03.f90
diff --git a/flang/test/semantics/resolve49.f90 b/flang/test/semantics/resolve49.f90
new file mode 100644 (file)
index 0000000..8d98d54
--- /dev/null
@@ -0,0 +1,47 @@
+! Copyright (c) 2019, NVIDIA CORPORATION.  All rights reserved.
+!
+! Licensed under the Apache License, Version 2.0 (the "License");
+! you may not use this file except in compliance with the License.
+! You may obtain a copy of the License at
+!
+!     http://www.apache.org/licenses/LICENSE-2.0
+!
+! Unless required by applicable law or agreed to in writing, software
+! distributed under the License is distributed on an "AS IS" BASIS,
+! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+! See the License for the specific language governing permissions and
+! limitations under the License.
+
+! Test section subscript
+program p1
+  real :: a(10,10)
+  real :: b(5,5)
+  real :: c
+  integer :: n
+  n = 2
+  b = a(1:10:n,1:n+3)
+end
+
+! Test substring
+program p2
+  character :: a(10)
+  character :: b(5)
+  integer :: n
+  n = 3
+  b = a(n:7)
+  b = a(n+3:)
+  b = a(:n+2)
+  a(n:7) = b
+  a(n+3:) = b
+  a(:n+2) = b
+end
+
+! Test pointer assignment with bounds
+program p3
+  integer, pointer :: a(:,:)
+  integer, target :: b(2,2)
+  integer :: n
+  n = 2
+  a(n:,n:) => b
+  a(1:n,1:n) => b
+end