[flang-commits] [flang] ca2be81 - [flang] Fix Symbol::Rank for ProcEntityDetails
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Fri Apr 15 09:54:55 PDT 2022
Author: Peter Klausler
Date: 2022-04-15T09:54:48-07:00
New Revision: ca2be81e34a6d87edb8e555dfac94ab68ee20f70
URL: https://github.com/llvm/llvm-project/commit/ca2be81e34a6d87edb8e555dfac94ab68ee20f70
DIFF: https://github.com/llvm/llvm-project/commit/ca2be81e34a6d87edb8e555dfac94ab68ee20f70.diff
LOG: [flang] Fix Symbol::Rank for ProcEntityDetails
When a procedure pointer or procedure dummy argument has a
defined interface, the rank of the pointer (or dummy) is the
rank of the interface.
Also tweak code discovered in shape analysis when investigating
this problam so that it returns a vector of emptied extents rather
than std::nullopt when the extents are not scope-invariant, so that
the rank can at least be known.
Differential Revision: https://reviews.llvm.org/D123727
Added:
Modified:
flang/include/flang/Semantics/symbol.h
flang/lib/Evaluate/shape.cpp
flang/test/Evaluate/rewrite01.f90
Removed:
################################################################################
diff --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h
index 40753a8c084a4..d4c0b37adb885 100644
--- a/flang/include/flang/Semantics/symbol.h
+++ b/flang/include/flang/Semantics/symbol.h
@@ -639,6 +639,10 @@ class Symbol {
[](const UseDetails &x) { return x.symbol().Rank(); },
[](const HostAssocDetails &x) { return x.symbol().Rank(); },
[](const ObjectEntityDetails &oed) { return oed.shape().Rank(); },
+ [](const ProcEntityDetails &ped) {
+ const Symbol *iface{ped.interface().symbol()};
+ return iface ? iface->Rank() : 0;
+ },
[](const AssocEntityDetails &aed) {
if (const auto &expr{aed.expr()}) {
if (auto assocRank{aed.rank()}) {
diff --git a/flang/lib/Evaluate/shape.cpp b/flang/lib/Evaluate/shape.cpp
index 15e44b9854c1f..a10295236df61 100644
--- a/flang/lib/Evaluate/shape.cpp
+++ b/flang/lib/Evaluate/shape.cpp
@@ -690,9 +690,9 @@ auto GetShapeHelper::operator()(const Symbol &symbol) const -> Result {
// to symbols that belong to the subroutine scope and are
// meaningless on the caller side without the related call
// expression.
- for (auto extent : *resultShape) {
- if (extent && !IsConstantExpr(*extent)) {
- return std::nullopt;
+ for (auto &extent : *resultShape) {
+ if (extent && !IsActuallyConstant(*extent)) {
+ extent.reset();
}
}
}
diff --git a/flang/test/Evaluate/rewrite01.f90 b/flang/test/Evaluate/rewrite01.f90
index 6b8b34dc523bc..94c43d95ab27a 100644
--- a/flang/test/Evaluate/rewrite01.f90
+++ b/flang/test/Evaluate/rewrite01.f90
@@ -57,6 +57,13 @@ subroutine size_test(x, n, m)
end subroutine
subroutine shape_test(x, n, m)
+ abstract interface
+ function foo(n)
+ integer, intent(in) :: n
+ real, pointer :: foo(:,:)
+ end function
+ end interface
+ procedure(foo), pointer :: pf
integer :: x(n, m)
!CHECK: PRINT *, [INTEGER(4)::int(size(x,dim=1,kind=8),kind=4),int(size(x,dim=2,kind=8),kind=4)]
print *, shape(x)
@@ -66,6 +73,8 @@ subroutine shape_test(x, n, m)
print *, shape(returns_array_2(m))
!CHECK: PRINT *, [INTEGER(8)::42_8]
print *, shape(returns_array_3(), kind=8)
+ !CHECK: PRINT *, 2_4
+ print *, rank(pf(1))
end subroutine
subroutine lbound_test(x, n, m)
More information about the flang-commits
mailing list