Skip to content

Commit 28cc960

Browse files
committed
[flang] Fix bogus errors about CONTIGUOUS attribute
Incorrect error messages were issuing for symbol table entries with the CONTIGUOUS attribute that didn't deserve them, like host association symbols. Put the CONTIGUOUS check into CheckObjectEntity(). Differential Revision: https://reviews.llvm.org/D150712
1 parent 191d487 commit 28cc960

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

flang/lib/Semantics/check-declarations.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,6 @@ void CheckHelper::Check(const Symbol &symbol) {
261261
CheckExplicitSave(symbol);
262262
}
263263
const auto *object{symbol.detailsIf<ObjectEntityDetails>()};
264-
if (symbol.attrs().test(Attr::CONTIGUOUS)) {
265-
if ((!object && !symbol.has<UseDetails>()) ||
266-
!((IsPointer(symbol) && symbol.Rank() > 0) || IsAssumedShape(symbol) ||
267-
evaluate::IsAssumedRank(symbol))) {
268-
if (symbol.owner().IsDerivedType()) { // C752
269-
messages_.Say(
270-
"A CONTIGUOUS component must be an array with the POINTER attribute"_err_en_US);
271-
} else { // C830
272-
messages_.Say(
273-
"CONTIGUOUS entity must be an array pointer, assumed-shape, or assumed-rank"_err_en_US);
274-
}
275-
}
276-
}
277264
CheckGlobalName(symbol);
278265
if (isDone) {
279266
return; // following checks do not apply
@@ -848,6 +835,17 @@ void CheckHelper::CheckObjectEntity(
848835
"'%s' is a data object and may not be EXTERNAL"_err_en_US,
849836
symbol.name());
850837
}
838+
if (symbol.attrs().test(Attr::CONTIGUOUS)) {
839+
if ((IsPointer(symbol) && symbol.Rank() > 0) || IsAssumedShape(symbol) ||
840+
evaluate::IsAssumedRank(symbol)) {
841+
} else if (symbol.owner().IsDerivedType()) { // C752
842+
messages_.Say(
843+
"A CONTIGUOUS component must be an array with the POINTER attribute"_err_en_US);
844+
} else { // C830
845+
messages_.Say(
846+
"CONTIGUOUS entity must be an array pointer, assumed-shape, or assumed-rank"_err_en_US);
847+
}
848+
}
851849
}
852850

853851
void CheckHelper::CheckPointerInitialization(const Symbol &symbol) {

flang/test/Semantics/resolve14.f90

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ program p2
2727
contiguous w
2828
!ERROR: 'z' is use-associated from module 'm2' and cannot be re-declared
2929
integer z
30+
real, target :: a(10)
31+
real, contiguous, pointer :: p(:) => a
3032
!ERROR: Reference to 'y' is ambiguous
3133
y = 1
34+
contains
35+
subroutine inner
36+
p(1) = 0. ! ok - check for regression on contiguous host assoc.
37+
end subroutine
3238
end

0 commit comments

Comments
 (0)