[flang] Enforce C15104(5) for coindexed values (#130203)

A object's value can't be copied from another image by means of an
intrinsic assignment statement if it has a derived type that contains a
pointer subobject ultimate component.
This commit is contained in:
Peter Klausler 2025-03-10 13:20:35 -07:00 committed by GitHub
parent 73b96cff01
commit 40d9096fda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 4 deletions

View File

@ -134,10 +134,16 @@ static std::optional<std::string> GetPointerComponentDesignatorName(
// Checks C1594(5,6); false if check fails
bool CheckCopyabilityInPureScope(parser::ContextualMessages &messages,
const SomeExpr &expr, const Scope &scope) {
if (const Symbol * base{GetFirstSymbol(expr)}) {
if (const char *why{
WhyBaseObjectIsSuspicious(base->GetUltimate(), scope)}) {
if (auto pointer{GetPointerComponentDesignatorName(expr)}) {
if (auto pointer{GetPointerComponentDesignatorName(expr)}) {
if (const Symbol * base{GetFirstSymbol(expr)}) {
const char *why{WhyBaseObjectIsSuspicious(base->GetUltimate(), scope)};
if (!why) {
if (auto coarray{evaluate::ExtractCoarrayRef(expr)}) {
base = &coarray->GetLastSymbol();
why = "coindexed";
}
}
if (why) {
evaluate::SayWithDeclaration(messages, *base,
"A pure subprogram may not copy the value of '%s' because it is %s"
" and has the POINTER potential subobject component '%s'"_err_en_US,

View File

@ -104,4 +104,11 @@ module m
localhp = hasPtr(z%a)
end subroutine
end function
pure subroutine test2(hpd, hhpd)
use used
type(hasHiddenPtr), intent(in out) :: hpd, hhpd[*]
hpd = hhpd ! ok
!ERROR: A pure subprogram may not copy the value of 'hhpd' because it is coindexed and has the POINTER potential subobject component '%a%p'
hpd = hhpd[1]
end subroutine
end module