Skip to content

Commit

Permalink
[flang] Accept pointer assignment w/ remapping to function result
Browse files Browse the repository at this point in the history
When a pointer assignment with bounds remapping has a function
reference as its right-hand side, don't check for array conformance.

Differential Revision: https://reviews.llvm.org/D119845
  • Loading branch information
klausler committed Feb 15, 2022
1 parent 3d85424 commit 7763c01
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion flang/include/flang/Evaluate/characteristics.h
Expand Up @@ -147,7 +147,7 @@ class TypeAndShape {
int Rank() const { return GetRank(shape_); }
bool IsCompatibleWith(parser::ContextualMessages &, const TypeAndShape &that,
const char *thisIs = "pointer", const char *thatIs = "target",
bool isElemental = false,
bool omitShapeConformanceCheck = false,
enum CheckConformanceFlags::Flags = CheckConformanceFlags::None) const;
std::optional<Expr<SubscriptInteger>> MeasureElementSizeInBytes(
FoldingContext &, bool align) const;
Expand Down
5 changes: 3 additions & 2 deletions flang/lib/Evaluate/characteristics.cpp
Expand Up @@ -149,14 +149,15 @@ std::optional<TypeAndShape> TypeAndShape::Characterize(

bool TypeAndShape::IsCompatibleWith(parser::ContextualMessages &messages,
const TypeAndShape &that, const char *thisIs, const char *thatIs,
bool isElemental, enum CheckConformanceFlags::Flags flags) const {
bool omitShapeConformanceCheck,
enum CheckConformanceFlags::Flags flags) const {
if (!type_.IsTkCompatibleWith(that.type_)) {
messages.Say(
"%1$s type '%2$s' is not compatible with %3$s type '%4$s'"_err_en_US,
thatIs, that.AsFortran(), thisIs, AsFortran());
return false;
}
return isElemental ||
return omitShapeConformanceCheck ||
CheckConformance(messages, shape_, that.shape_, flags, thisIs, thatIs)
.value_or(true /*fail only when nonconformance is known now*/);
}
Expand Down
3 changes: 2 additions & 1 deletion flang/lib/Semantics/pointer-assignment.cpp
Expand Up @@ -172,7 +172,8 @@ bool PointerAssignmentChecker::Check(const evaluate::FunctionRef<T> &f) {
const auto *frTypeAndShape{funcResult->GetTypeAndShape()};
CHECK(frTypeAndShape);
if (!lhsType_->IsCompatibleWith(context_.messages(), *frTypeAndShape,
"pointer", "function result", false /*elemental*/,
"pointer", "function result",
isBoundsRemapping_ /*omit shape check*/,
evaluate::CheckConformanceFlags::BothDeferredShape)) {
return false; // IsCompatibleWith() emitted message
}
Expand Down
7 changes: 7 additions & 0 deletions flang/test/Semantics/assign03.f90
Expand Up @@ -218,6 +218,13 @@ subroutine s9
p(1:5,1:5) => x(:,1:2)
!OK - rhs has rank 1 and enough elements
p(1:5,1:5) => y(1:100:2)
!OK - same, but from function result
p(1:5,1:5) => f()
contains
function f()
real, pointer :: f(:)
f => y
end function
end

subroutine s10
Expand Down

0 comments on commit 7763c01

Please sign in to comment.