Skip to content

Commit f06ea10

Browse files
authored
[flang] Do definability checking in RANK() clauses (#71607)
I explicitly skipped definability checking for construct entities under a RANK() clause. I don't know what I was thinking at the time; it's obviously incorrect! Fix, and add tests.
1 parent 6899f03 commit f06ea10

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

flang/lib/Semantics/definable.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ static std::optional<parser::Message> WhyNotDefinableBase(parser::CharBlock at,
9595
bool acceptAllocatable{flags.test(DefinabilityFlag::AcceptAllocatable)};
9696
bool isTargetDefinition{!isPointerDefinition && IsPointer(ultimate)};
9797
if (const auto *association{ultimate.detailsIf<AssocEntityDetails>()}) {
98-
if (association->rank().has_value()) {
99-
return std::nullopt; // SELECT RANK always modifiable variable
100-
} else if (!IsVariable(association->expr())) {
98+
if (!IsVariable(association->expr())) {
10199
return BlameSymbol(at,
102100
"'%s' is construct associated with an expression"_en_US, original);
103101
} else if (evaluate::HasVectorSubscript(association->expr().value())) {

flang/test/Semantics/select-rank03.f90

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,27 @@ subroutine pointers(p)
130130
p => t1
131131
end select
132132
end
133+
subroutine undefinable(p)
134+
real, pointer, intent(in) :: p(..)
135+
real, target :: t
136+
select rank(p)
137+
rank (0)
138+
!ERROR: The left-hand side of a pointer assignment is not definable
139+
!BECAUSE: 'p' is an INTENT(IN) dummy argument
140+
p => t
141+
!ERROR: Name in DEALLOCATE statement is not definable
142+
!BECAUSE: 'p' is an INTENT(IN) dummy argument
143+
deallocate(p)
144+
!ERROR: RANK (*) cannot be used when selector is POINTER or ALLOCATABLE
145+
rank (*)
146+
!ERROR: Whole assumed-size array 'p' may not appear here without subscripts
147+
!ERROR: Name in DEALLOCATE statement is not definable
148+
!BECAUSE: 'p' is an INTENT(IN) dummy argument
149+
deallocate(p)
150+
rank default
151+
!ERROR: Name in DEALLOCATE statement is not definable
152+
!BECAUSE: 'p' is an INTENT(IN) dummy argument
153+
deallocate(p)
154+
end select
155+
end
133156
end

0 commit comments

Comments
 (0)