Skip to content
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

Check for constrains C741 through C749 #1100

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 15 additions & 10 deletions lib/Semantics/check-declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,19 +384,24 @@ void CheckHelper::CheckObjectEntity(
CheckAssumedTypeEntity(symbol, details);
symbolBeingChecked_ = nullptr;
if (!details.coshape().empty()) {
bool isDeferredShape{details.coshape().IsDeferredShape()};
if (IsAllocatable(symbol)) {
if (!details.coshape().IsDeferredShape()) { // C746, C827
messages_.Say(
"ALLOCATABLE coarray must have a deferred coshape"_err_en_US);
if (!isDeferredShape) { // C827
messages_.Say("'%s' is an ALLOCATABLE coarray must have a deferred"
" coshape"_err_en_US,
symbol.name());
}
} else if (symbol.owner().IsDerivedType()) { // C746
messages_.Say(
"Coarray components must be ALLOCATABLE and have a deferred "
"coshape"_err_en_US);
std::string deferredMsg{
isDeferredShape ? "" : " and have a deferred coshape"};
messages_.Say("Component '%s' is a coarray and must have the ALLOCATABLE"
" attribute%s"_err_en_US,
symbol.name(), deferredMsg);
} else {
if (!details.coshape().IsAssumedSize()) { // C746, C828
messages_.Say(
"Non-ALLOCATABLE coarray must have an explicit coshape"_err_en_US);
if (!details.coshape().IsAssumedSize()) { // C828
messages_.Say("Component '%s' is a non-ALLOCATABLE coarray must have"
" an explicit coshape"_err_en_US,
symbol.name());
}
}
}
Expand Down Expand Up @@ -469,7 +474,7 @@ void CheckHelper::CheckObjectEntity(
symbol.name());
}
}
}
} // namespace Fortran::semantics

// The six different kinds of array-specs:
// array-spec -> explicit-shape-list | deferred-shape-list
Expand Down
13 changes: 9 additions & 4 deletions lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3835,20 +3835,25 @@ void DeclarationVisitor::Post(const parser::ComponentDecl &x) {
"ISO_FORTRAN_ENV"_err_en_US);
} else {
if (IsIsoCType(derived)) {
Say("A coarray component may not be of C_PTR or C_FUNPTR from "
Say("A coarray component may not be of type C_PTR or C_FUNPTR from "
"ISO_C_BINDING when an allocatable object is a "
"coarray"_err_en_US);
}
}
}
if (FindCoarrayUltimateComponent(*derived)) { // C748
if (auto it{FindCoarrayUltimateComponent(*derived)}) { // C748
Message declMsg{Say(it->name(),
"Type '%s' has coarray ultimate component '%s' declared here"_en_US,
declType->AsFortran(), it.BuildResultDesignatorName())};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this work correctly if the coarray component is declared in a module that is read in from a .mod file?

if (attrs.HasAny({Attr::POINTER, Attr::ALLOCATABLE})) {
Say("A component whose type has a coarray ultimate component "
"cannot be a POINTER or ALLOCATABLE"_err_en_US);
"may not be a POINTER or ALLOCATABLE"_err_en_US)
.Attach(declMsg);
}
if (!arraySpec().empty() || !coarraySpec().empty()) {
Say("A component whose type has a coarray ultimate component "
"cannot be an array or corray"_err_en_US);
"may not be an array or corray"_err_en_US)
.Attach(declMsg);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/Semantics/misc-declarations.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
! - 8.5.19 constraints on the VOLATILE attribute

module m
!ERROR: ALLOCATABLE coarray must have a deferred coshape
!ERROR: 'mustbedeferred' is an ALLOCATABLE coarray must have a deferred coshape
real, allocatable :: mustBeDeferred[*] ! C827
!ERROR: Non-ALLOCATABLE coarray must have an explicit coshape
!ERROR: Component 'mustbeexplicit' is a non-ALLOCATABLE coarray must have an explicit coshape
real :: mustBeExplicit[:] ! C828
type :: hasCoarray
real, allocatable :: coarray[:]
Expand Down
18 changes: 10 additions & 8 deletions test/Semantics/resolve88.f90
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ module m

type testCoArrayType
real, allocatable, codimension[:] :: allocatableField
!ERROR: Coarray components must be ALLOCATABLE and have a deferred coshape
!ERROR: Component 'deferredfield' is a coarray and must have the ALLOCATABLE attribute
real, codimension[:] :: deferredField
!ERROR: 'pointerfield' may not have the POINTER attribute because it is a coarray
!ERROR: Coarray components must be ALLOCATABLE and have a deferred coshape
!ERROR: Component 'pointerfield' is a coarray and must have the ALLOCATABLE attribute
real, pointer, codimension[:] :: pointerField
!ERROR: Coarray components must be ALLOCATABLE and have a deferred coshape
!ERROR: Component 'realfield' is a coarray and must have the ALLOCATABLE attribute and have a deferred coshape
real, codimension[*] :: realField
!ERROR: 'realfield2' is an ALLOCATABLE coarray must have a deferred coshape
real, allocatable, codimension[*] :: realField2
end type testCoArrayType

! C747 If a coarray-spec appears, the component shall not be of type C_PTR or
Expand Down Expand Up @@ -44,12 +46,12 @@ module m
end type team_typeCoarrayType

type c_ptrCoarrayType
!ERROR: A coarray component may not be of C_PTR or C_FUNPTR from ISO_C_BINDING when an allocatable object is a coarray
!ERROR: A coarray component may not be of type C_PTR or C_FUNPTR from ISO_C_BINDING when an allocatable object is a coarray
type(c_ptr), allocatable, codimension[:] :: field
end type c_ptrCoarrayType

type c_funptrCoarrayType
!ERROR: A coarray component may not be of C_PTR or C_FUNPTR from ISO_C_BINDING when an allocatable object is a coarray
!ERROR: A coarray component may not be of type C_PTR or C_FUNPTR from ISO_C_BINDING when an allocatable object is a coarray
type(c_funptr), allocatable, codimension[:] :: field
end type c_funptrCoarrayType

Expand All @@ -62,11 +64,11 @@ module m

type testType
type(coarrayType) :: goodField
!ERROR: A component whose type has a coarray ultimate component cannot be a POINTER or ALLOCATABLE
!ERROR: A component whose type has a coarray ultimate component may not be a POINTER or ALLOCATABLE
type(coarrayType), pointer :: pointerField
!ERROR: A component whose type has a coarray ultimate component cannot be a POINTER or ALLOCATABLE
!ERROR: A component whose type has a coarray ultimate component may not be a POINTER or ALLOCATABLE
type(coarrayType), allocatable :: allocatableField
!ERROR: A component whose type has a coarray ultimate component cannot be an array or corray
!ERROR: A component whose type has a coarray ultimate component may not be an array or corray
type(coarrayType), dimension(3) :: arrayField
end type testType

Expand Down