Skip to content

Commit 2414a90

Browse files
authored
[flang] Catch NULL(MOLD=assumed-rank) (#95270)
An assumed-rank dummy argument is not an acceptable MOLD argument to NULL(), whose result must have a known rank at compilation time.
1 parent 010c55b commit 2414a90

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

flang/lib/Evaluate/intrinsics.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,6 +2691,10 @@ SpecificCall IntrinsicProcTable::Implementation::HandleNull(
26912691
mold = nullptr;
26922692
}
26932693
if (mold) {
2694+
if (IsAssumedRank(*arguments[0])) {
2695+
context.messages().Say(arguments[0]->sourceLocation(),
2696+
"MOLD= argument to NULL() must not be assumed-rank"_err_en_US);
2697+
}
26942698
bool isProcPtrTarget{
26952699
IsProcedurePointerTarget(*mold) && !IsNullObjectPointer(*mold)};
26962700
if (isProcPtrTarget || IsAllocatableOrPointerObject(*mold)) {

flang/test/Semantics/null01.f90

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,16 @@ subroutine s1(x)
151151
subroutine s2(x)
152152
type(pdt(*)), pointer, intent(in) :: x
153153
end
154-
subroutine test
154+
subroutine s3(ar)
155+
real, pointer :: ar(..)
156+
end
157+
subroutine test(ar)
158+
real, pointer :: ar(..)
155159
!ERROR: Actual argument associated with dummy argument 'x=' is a NULL() pointer without a MOLD= to provide a character length
156160
call s1(null())
157161
!ERROR: Actual argument associated with dummy argument 'x=' is a NULL() pointer without a MOLD= to provide a value for the assumed type parameter 'n'
158162
call s2(null())
163+
!ERROR: MOLD= argument to NULL() must not be assumed-rank
164+
call s3(null(ar))
159165
end
160166
end

0 commit comments

Comments
 (0)