Skip to content

Commit

Permalink
[flang] Catch NULL(MOLD=assumed-rank)
Browse files Browse the repository at this point in the history
An assumed-rank dummy argument is not an acceptable MOLD argument
to NULL(), whose result must have a known rank at compilation time.
  • Loading branch information
klausler committed Jun 12, 2024
1 parent 1fbf748 commit dcd6b84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions flang/lib/Evaluate/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2691,6 +2691,10 @@ SpecificCall IntrinsicProcTable::Implementation::HandleNull(
mold = nullptr;
}
if (mold) {
if (IsAssumedRank(*arguments[0])) {
context.messages().Say(arguments[0]->sourceLocation(),
"MOLD= argument to NULL() must not be assumed-rank"_err_en_US);
}
bool isProcPtrTarget{
IsProcedurePointerTarget(*mold) && !IsNullObjectPointer(*mold)};
if (isProcPtrTarget || IsAllocatableOrPointerObject(*mold)) {
Expand Down
8 changes: 7 additions & 1 deletion flang/test/Semantics/null01.f90
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,16 @@ subroutine s1(x)
subroutine s2(x)
type(pdt(*)), pointer, intent(in) :: x
end
subroutine test
subroutine s3(ar)
real, pointer :: ar(..)
end
subroutine test(ar)
real, pointer :: ar(..)
!ERROR: Actual argument associated with dummy argument 'x=' is a NULL() pointer without a MOLD= to provide a character length
call s1(null())
!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'
call s2(null())
!ERROR: MOLD= argument to NULL() must not be assumed-rank
call s3(null(ar))
end
end

0 comments on commit dcd6b84

Please sign in to comment.