Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions flang/lib/Semantics/assignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions flang/test/Semantics/call12.f90
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,11 @@ pure subroutine internal
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok, because hhpd was passed as in out? It wouldn't be ok, if it were passed as in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, and that's a distinct error. You can't use pointer components to bypass the restrictions of INTENT(IN) in a pure subprogram.

!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