forked from OSchip/llvm-project
[flang] Enforce rest of semantic constraint C919
A reference to an allocatable or pointer component must be applied to a scalar base object. (This is the second part of constraint C919; the first part is already checked.) Differential Revision: https://reviews.llvm.org/D112241
This commit is contained in:
parent
e7084ceab3
commit
f2360e1156
|
@ -317,6 +317,8 @@ private:
|
|||
const parser::SectionSubscript &);
|
||||
std::vector<Subscript> AnalyzeSectionSubscripts(
|
||||
const std::list<parser::SectionSubscript> &);
|
||||
std::optional<Component> CreateComponent(
|
||||
DataRef &&, const Symbol &, const semantics::Scope &);
|
||||
MaybeExpr Designate(DataRef &&);
|
||||
MaybeExpr CompleteSubscripts(ArrayRef &&);
|
||||
MaybeExpr ApplySubscripts(DataRef &&, std::vector<Subscript> &&);
|
||||
|
|
|
@ -235,7 +235,7 @@ MaybeExpr ExpressionAnalyzer::CompleteSubscripts(ArrayRef &&ref) {
|
|||
for (const auto &expr : ref.subscript()) {
|
||||
subscriptRank += expr.Rank();
|
||||
}
|
||||
if (subscriptRank > 0) {
|
||||
if (subscriptRank > 0) { // C919a
|
||||
Say("Subscripts of component '%s' of rank-%d derived type "
|
||||
"array have rank %d but must all be scalar"_err_en_US,
|
||||
symbol.name(), baseRank, subscriptRank);
|
||||
|
@ -292,7 +292,7 @@ MaybeExpr ExpressionAnalyzer::TopLevelChecks(DataRef &&dataRef) {
|
|||
int componentRank{symbol.Rank()};
|
||||
if (componentRank > 0) {
|
||||
int baseRank{component->base().Rank()};
|
||||
if (baseRank > 0) {
|
||||
if (baseRank > 0) { // C919a
|
||||
Say("Reference to whole rank-%d component '%%%s' of "
|
||||
"rank-%d array of derived type is not allowed"_err_en_US,
|
||||
componentRank, symbol.name(), baseRank);
|
||||
|
@ -972,8 +972,11 @@ static NamedEntity IgnoreAnySubscripts(Designator<SomeDerived> &&designator) {
|
|||
}
|
||||
|
||||
// Components of parent derived types are explicitly represented as such.
|
||||
static std::optional<Component> CreateComponent(
|
||||
std::optional<Component> ExpressionAnalyzer::CreateComponent(
|
||||
DataRef &&base, const Symbol &component, const semantics::Scope &scope) {
|
||||
if (IsAllocatableOrPointer(component) && base.Rank() > 0) { // C919b
|
||||
Say("An allocatable or pointer component reference must be applied to a scalar base"_err_en_US);
|
||||
}
|
||||
if (&component.owner() == &scope) {
|
||||
return Component{std::move(base), component};
|
||||
}
|
||||
|
|
|
@ -29,20 +29,21 @@ Deallocate(pi)
|
|||
|
||||
Deallocate(z%p)
|
||||
|
||||
!ERROR: An allocatable or pointer component reference must be applied to a scalar base
|
||||
Deallocate(x%p, stat=s, errmsg=e)
|
||||
Deallocate(x%p, errmsg=e)
|
||||
Deallocate(x%p, stat=s)
|
||||
Deallocate(x, errmsg=e)
|
||||
Deallocate(x, stat=s)
|
||||
|
||||
Deallocate(y%p, stat=s, errmsg=e)
|
||||
Deallocate(y%p, errmsg=e)
|
||||
Deallocate(y%p, stat=s)
|
||||
Deallocate(y, stat=s, errmsg=e)
|
||||
Deallocate(y, errmsg=e)
|
||||
Deallocate(y, stat=s)
|
||||
|
||||
Deallocate(z, stat=s, errmsg=e)
|
||||
Deallocate(z, errmsg=e)
|
||||
Deallocate(z, stat=s)
|
||||
|
||||
Deallocate(z, y%p, stat=s, errmsg=e)
|
||||
Deallocate(z, y%p, errmsg=e)
|
||||
Deallocate(z, y%p, stat=s)
|
||||
Deallocate(z, y, stat=s, errmsg=e)
|
||||
Deallocate(z, y, errmsg=e)
|
||||
Deallocate(z, y, stat=s)
|
||||
|
||||
End Program
|
||||
|
|
Loading…
Reference in New Issue