diff --git a/flang/lib/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp index 965e5d43c8b2..48c638bcb933 100644 --- a/flang/lib/Evaluate/tools.cpp +++ b/flang/lib/Evaluate/tools.cpp @@ -767,7 +767,7 @@ bool IsObjectPointer(const Expr &expr, FoldingContext &context) { return false; } else if (const auto *funcRef{UnwrapProcedureRef(expr)}) { return IsVariable(*funcRef); - } else if (const Symbol * symbol{GetLastSymbol(expr)}) { + } else if (const Symbol * symbol{UnwrapWholeSymbolOrComponentDataRef(expr)}) { return IsPointer(symbol->GetUltimate()); } else { return false; diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp index 45a83fe71098..3f39e064e6d6 100644 --- a/flang/lib/Semantics/check-call.cpp +++ b/flang/lib/Semantics/check-call.cpp @@ -309,29 +309,34 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy, "Coindexed scalar actual argument must be associated with a scalar %s"_err_en_US, dummyName); } - if (!IsArrayElement(actual) && - !(actualType.type().category() == TypeCategory::Character && - actualType.type().kind() == 1) && - !(dummy.type.type().IsAssumedType() && dummyIsAssumedSize) && - !dummyIsAssumedRank) { - messages.Say( - "Whole scalar actual argument may not be associated with a %s array"_err_en_US, - dummyName); - } - if (actualIsPolymorphic) { - messages.Say( - "Polymorphic scalar may not be associated with a %s array"_err_en_US, - dummyName); - } - if (actualIsPointer) { - messages.Say( - "Scalar POINTER target may not be associated with a %s array"_err_en_US, - dummyName); - } - if (actualLastSymbol && IsAssumedShape(*actualLastSymbol)) { - messages.Say( - "Element of assumed-shape array may not be associated with a %s array"_err_en_US, - dummyName); + bool actualIsArrayElement{IsArrayElement(actual)}; + bool actualIsCKindCharacter{ + actualType.type().category() == TypeCategory::Character && + actualType.type().kind() == 1}; + if (!actualIsCKindCharacter) { + if (!actualIsArrayElement && + !(dummy.type.type().IsAssumedType() && dummyIsAssumedSize) && + !dummyIsAssumedRank) { + messages.Say( + "Whole scalar actual argument may not be associated with a %s array"_err_en_US, + dummyName); + } + if (actualIsPolymorphic) { + messages.Say( + "Polymorphic scalar may not be associated with a %s array"_err_en_US, + dummyName); + } + if (actualIsArrayElement && actualLastSymbol && + IsPointer(*actualLastSymbol)) { + messages.Say( + "Element of pointer array may not be associated with a %s array"_err_en_US, + dummyName); + } + if (actualLastSymbol && IsAssumedShape(*actualLastSymbol)) { + messages.Say( + "Element of assumed-shape array may not be associated with a %s array"_err_en_US, + dummyName); + } } } if (actualLastObject && actualLastObject->IsCoarray() && diff --git a/flang/test/Semantics/call03.f90 b/flang/test/Semantics/call03.f90 index e89bce7ae089..24e7e40264e7 100644 --- a/flang/test/Semantics/call03.f90 +++ b/flang/test/Semantics/call03.f90 @@ -196,21 +196,28 @@ module m01 subroutine charray(x) character :: x(10) end subroutine - subroutine test09(ashape, polyarray, c) ! 15.5.2.4(14), 15.5.2.11 + subroutine test09(ashape, polyarray, c, assumed_shape_char) ! 15.5.2.4(14), 15.5.2.11 real :: x, arr(10) real, pointer :: p(:) + real, pointer :: p_scalar + character(10), pointer :: char_pointer(:) + character(*) :: assumed_shape_char(:) real :: ashape(:) class(t) :: polyarray(*) character(10) :: c(:) !ERROR: Whole scalar actual argument may not be associated with a dummy argument 'x=' array call assumedsize(x) - !ERROR: Scalar POINTER target may not be associated with a dummy argument 'x=' array + !ERROR: Whole scalar actual argument may not be associated with a dummy argument 'x=' array + call assumedsize(p_scalar) + !ERROR: Element of pointer array may not be associated with a dummy argument 'x=' array call assumedsize(p(1)) !ERROR: Element of assumed-shape array may not be associated with a dummy argument 'x=' array call assumedsize(ashape(1)) !ERROR: Polymorphic scalar may not be associated with a dummy argument 'x=' array call polyassumedsize(polyarray(1)) call charray(c(1:1)) ! not an error if character + call charray(char_pointer(1)) ! not an error if character + call charray(assumed_shape_char(1)) ! not an error if character call assumedsize(arr(1)) ! not an error if element in sequence call assumedrank(x) ! not an error call assumedtypeandsize(x) ! not an error diff --git a/flang/test/Semantics/call07.f90 b/flang/test/Semantics/call07.f90 index db5e0a691459..673648979ab5 100644 --- a/flang/test/Semantics/call07.f90 +++ b/flang/test/Semantics/call07.f90 @@ -14,6 +14,9 @@ module m subroutine s03(p) real, pointer, intent(in) :: p(:) end subroutine + subroutine s04(p) + real, pointer :: p + end subroutine subroutine test !ERROR: CONTIGUOUS POINTER must be an array @@ -30,6 +33,8 @@ module m call s03(a03) ! ok !ERROR: Actual argument associated with POINTER dummy argument 'p=' must also be POINTER unless INTENT(IN) call s02(a03) + !ERROR: Actual argument associated with POINTER dummy argument 'p=' must also be POINTER unless INTENT(IN) + call s04(a02(1)) !ERROR: An array section with a vector subscript may not be a pointer target call s03(a03([1,2,4])) !ERROR: A coindexed object may not be a pointer target