[flang] Another validity of the TARGET= argument of ASSOCIATED() for objects

In my previous implementation of the semantic checks for ASSOCIATED(), I
had neglected to check the TARGET= argument for objects to ensure that
it has either the POINTER or TARGET attributes.

I added an implementation and a test.

Differential Revision: https://reviews.llvm.org/D89717
This commit is contained in:
Peter Steinfeld 2020-10-19 11:01:13 -07:00
parent 611959f004
commit 6b66f1cd9b
2 changed files with 17 additions and 1 deletions

View File

@ -1959,6 +1959,19 @@ static bool CheckAssociated(SpecificCall &call,
*pointerSymbol);
} else {
// object pointer and target
if (const Symbol * targetSymbol{GetLastSymbol(*targetExpr)}) {
if (!(targetSymbol->attrs().test(semantics::Attr::POINTER) ||
targetSymbol->attrs().test(
semantics::Attr::TARGET))) {
AttachDeclaration(
messages.Say("TARGET= argument '%s' must have either "
"the POINTER or the TARGET "
"attribute"_err_en_US,
targetName),
*targetSymbol);
}
}
if (const auto pointerType{pointerArg->GetType()}) {
if (const auto targetType{targetArg->GetType()}) {
ok = pointerType->IsTkCompatibleWith(*targetType);

View File

@ -74,7 +74,6 @@ subroutine assoc()
lVar = associated(intVar, intVar)
!ERROR: POINTER= argument of ASSOCIATED() must be a POINTER
lVar = associated(intAllocVar)
lVar = associated(intPointerVar1, intVar) !OK
!ERROR: Arguments of ASSOCIATED() must be a POINTER and an optional valid target
lVar = associated(intPointerVar1, targetRealVar)
lVar = associated(intPointerVar1, targetIntVar1) !OK
@ -82,6 +81,10 @@ subroutine assoc()
lVar = associated(intPointerVar1, targetIntVar2)
lVar = associated(intPointerVar1) !OK
lVar = associated(intPointerVar1, intPointerVar2) !OK
!ERROR: In assignment to object pointer 'intpointervar1', the target 'intvar' is not an object with POINTER or TARGET attributes
intPointerVar1 => intVar
!ERROR: TARGET= argument 'intvar' must have either the POINTER or the TARGET attribute
lVar = associated(intPointerVar1, intVar)
! Procedure pointer tests
intprocPointer1 => intProc !OK