[flang-commits] [flang] c1a7783 - [flang] Avoid spurious error message in function result compatibility
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Thu Aug 18 15:04:24 PDT 2022
Author: Peter Klausler
Date: 2022-08-18T14:58:16-07:00
New Revision: c1a77839cc99766c4cf7ef16a323c6423de3f2a9
URL: https://github.com/llvm/llvm-project/commit/c1a77839cc99766c4cf7ef16a323c6423de3f2a9
DIFF: https://github.com/llvm/llvm-project/commit/c1a77839cc99766c4cf7ef16a323c6423de3f2a9.diff
LOG: [flang] Avoid spurious error message in function result compatibility
When checking function interface compatibility for procedure pointer
assignment/initialization or actual/dummy procedure association, don't
emit a diagnositic about function result shape incompatibility unless
the interfaces differ in rank or have distinct constant extents on a
dimension. Function results whose dimensions are determined by dummy
arguments or host-associated variables are not necessarily incompatible.
Differential Revision: https://reviews.llvm.org/D132162
Added:
Modified:
flang/lib/Evaluate/characteristics.cpp
Removed:
################################################################################
diff --git a/flang/lib/Evaluate/characteristics.cpp b/flang/lib/Evaluate/characteristics.cpp
index a2cc866eecd1..25de823fe778 100644
--- a/flang/lib/Evaluate/characteristics.cpp
+++ b/flang/lib/Evaluate/characteristics.cpp
@@ -875,6 +875,23 @@ bool FunctionResult::CanBeReturnedViaImplicitInterface() const {
}
}
+static bool AreCompatibleFunctionResultShapes(const Shape &x, const Shape &y) {
+ int rank{GetRank(x)};
+ if (GetRank(y) != rank) {
+ return false;
+ }
+ for (int j{0}; j < rank; ++j) {
+ if (auto xDim{ToInt64(x[j])}) {
+ if (auto yDim{ToInt64(y[j])}) {
+ if (*xDim != *yDim) {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+}
+
bool FunctionResult::IsCompatibleWith(
const FunctionResult &actual, std::string *whyNot) const {
Attrs actualAttrs{actual.attrs};
@@ -892,9 +909,10 @@ bool FunctionResult::IsCompatibleWith(
*whyNot = "function results have distinct ranks";
}
} else if (!attrs.test(Attr::Allocatable) && !attrs.test(Attr::Pointer) &&
- ifaceTypeShape->shape() != actualTypeShape->shape()) {
+ !AreCompatibleFunctionResultShapes(
+ ifaceTypeShape->shape(), actualTypeShape->shape())) {
if (whyNot) {
- *whyNot = "function results have distinct extents";
+ *whyNot = "function results have distinct constant extents";
}
} else if (!ifaceTypeShape->type().IsTkCompatibleWith(
actualTypeShape->type())) {
More information about the flang-commits
mailing list