Skip to content

Commit f546b6e

Browse files
authored
[Flang] Relaxing an error when contiguous pointer is assigned to a non-contig… (#86781)
…uous function. Fix from [thtsikas](https://github.com/thtsikas) based on a discussion in [slack](https://flang-compiler.slack.com/archives/C5C58TT32/p1711124374836079). Example: ``` Program test Integer, Pointer, Contiguous :: cont(:) Interface Function f() Integer, Pointer :: f(:) End Function End Interface cont => f() Print *, cont(3) End Program Function f() Integer, Pointer :: f(:) Allocate (f(4),Source=[1,1,42,1]) ! f => f(4:1:-1) !! not contiguous, runtime error End Function f ``` Understanding is that the standard intended to allow this pattern. The restriction 10.2.2.3 p6 Data pointer assignment "If the pointer object has the CONTIGUOUS attribute, the pointer target shall be contiguous." is not associated with a numbered constraint. If there is a mechanism for injecting runtime checks, this would be a place to do it. Absent that, a warning is the best we can do. No other compiler treats contigPtr => func() as an error when func() is not CONTIGUOUS, so a warning would probably be better for consistency. https://godbolt.org/z/5cM6roeEE
1 parent e701c1a commit f546b6e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

flang/lib/Semantics/pointer-assignment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ bool PointerAssignmentChecker::Check(const evaluate::FunctionRef<T> &f) {
266266
} else if (isContiguous_ &&
267267
!funcResult->attrs.test(FunctionResult::Attr::Contiguous)) {
268268
msg = "CONTIGUOUS %s is associated with the result of reference to"
269-
" function '%s' that is not contiguous"_err_en_US;
269+
" function '%s' that is not known to be contiguous"_warn_en_US;
270270
} else if (lhsType_) {
271271
const auto *frTypeAndShape{funcResult->GetTypeAndShape()};
272272
CHECK(frTypeAndShape);

0 commit comments

Comments
 (0)