From 0f4ef956a91a556e9bf6092d41435364f682c62c Mon Sep 17 00:00:00 2001 From: Tim Keith Date: Tue, 2 Apr 2019 15:36:20 -0700 Subject: [PATCH] [flang] Pointer assignment bounds, section subscript, substring 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 | 16 ++++++------ flang/test/semantics/CMakeLists.txt | 1 + flang/test/semantics/resolve49.f90 | 47 ++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 flang/test/semantics/resolve49.f90 diff --git a/flang/lib/semantics/resolve-names.cc b/flang/lib/semantics/resolve-names.cc index c05c3ad..2cd93d2 100644 --- a/flang/lib/semantics/resolve-names.cc +++ b/flang/lib/semantics/resolve-names.cc @@ -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(x.t)}; + const auto &bounds{std::get(x.t)}; const auto &expr{std::get(x.t)}; - ResolveDataRef(dataRef);; + ResolveDataRef(dataRef); + Walk(bounds); // Resolve unrestricted specific intrinsic procedures as in "p => cos". if (const auto *designator{ std::get_if>(&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(x.t)); - // TODO: SubstringRange }, }, x.u); diff --git a/flang/test/semantics/CMakeLists.txt b/flang/test/semantics/CMakeLists.txt index 32c4ad6..352f4a9 100644 --- a/flang/test/semantics/CMakeLists.txt +++ b/flang/test/semantics/CMakeLists.txt @@ -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 index 0000000..8d98d54 --- /dev/null +++ b/flang/test/semantics/resolve49.f90 @@ -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 -- 2.7.4