[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@dc2dd85a9a
Reviewed-on: https://github.com/flang-compiler/f18/pull/380
This commit is contained in:
Tim Keith 2019-04-02 15:36:20 -07:00
parent 06481a4eff
commit 0f4ef956a9
3 changed files with 56 additions and 8 deletions

View 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);

View File

@ -75,6 +75,7 @@ set(ERROR_TESTS
resolve46.f90
resolve47.f90
resolve48.f90
resolve49.f90
structconst01.f90
structconst02.f90
structconst03.f90

View File

@ -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