Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Commit f2360e1

Browse files
committed
[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
1 parent e7084ce commit f2360e1

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

flang/include/flang/Semantics/expression.h

+2
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ class ExpressionAnalyzer {
317317
const parser::SectionSubscript &);
318318
std::vector<Subscript> AnalyzeSectionSubscripts(
319319
const std::list<parser::SectionSubscript> &);
320+
std::optional<Component> CreateComponent(
321+
DataRef &&, const Symbol &, const semantics::Scope &);
320322
MaybeExpr Designate(DataRef &&);
321323
MaybeExpr CompleteSubscripts(ArrayRef &&);
322324
MaybeExpr ApplySubscripts(DataRef &&, std::vector<Subscript> &&);

flang/lib/Semantics/expression.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ MaybeExpr ExpressionAnalyzer::CompleteSubscripts(ArrayRef &&ref) {
235235
for (const auto &expr : ref.subscript()) {
236236
subscriptRank += expr.Rank();
237237
}
238-
if (subscriptRank > 0) {
238+
if (subscriptRank > 0) { // C919a
239239
Say("Subscripts of component '%s' of rank-%d derived type "
240240
"array have rank %d but must all be scalar"_err_en_US,
241241
symbol.name(), baseRank, subscriptRank);
@@ -292,7 +292,7 @@ MaybeExpr ExpressionAnalyzer::TopLevelChecks(DataRef &&dataRef) {
292292
int componentRank{symbol.Rank()};
293293
if (componentRank > 0) {
294294
int baseRank{component->base().Rank()};
295-
if (baseRank > 0) {
295+
if (baseRank > 0) { // C919a
296296
Say("Reference to whole rank-%d component '%%%s' of "
297297
"rank-%d array of derived type is not allowed"_err_en_US,
298298
componentRank, symbol.name(), baseRank);
@@ -972,8 +972,11 @@ static NamedEntity IgnoreAnySubscripts(Designator<SomeDerived> &&designator) {
972972
}
973973

974974
// Components of parent derived types are explicitly represented as such.
975-
static std::optional<Component> CreateComponent(
975+
std::optional<Component> ExpressionAnalyzer::CreateComponent(
976976
DataRef &&base, const Symbol &component, const semantics::Scope &scope) {
977+
if (IsAllocatableOrPointer(component) && base.Rank() > 0) { // C919b
978+
Say("An allocatable or pointer component reference must be applied to a scalar base"_err_en_US);
979+
}
977980
if (&component.owner() == &scope) {
978981
return Component{std::move(base), component};
979982
}

flang/test/Semantics/deallocate01.f90

+9-8
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,21 @@
2929

3030
Deallocate(z%p)
3131

32+
!ERROR: An allocatable or pointer component reference must be applied to a scalar base
3233
Deallocate(x%p, stat=s, errmsg=e)
33-
Deallocate(x%p, errmsg=e)
34-
Deallocate(x%p, stat=s)
34+
Deallocate(x, errmsg=e)
35+
Deallocate(x, stat=s)
3536

36-
Deallocate(y%p, stat=s, errmsg=e)
37-
Deallocate(y%p, errmsg=e)
38-
Deallocate(y%p, stat=s)
37+
Deallocate(y, stat=s, errmsg=e)
38+
Deallocate(y, errmsg=e)
39+
Deallocate(y, stat=s)
3940

4041
Deallocate(z, stat=s, errmsg=e)
4142
Deallocate(z, errmsg=e)
4243
Deallocate(z, stat=s)
4344

44-
Deallocate(z, y%p, stat=s, errmsg=e)
45-
Deallocate(z, y%p, errmsg=e)
46-
Deallocate(z, y%p, stat=s)
45+
Deallocate(z, y, stat=s, errmsg=e)
46+
Deallocate(z, y, errmsg=e)
47+
Deallocate(z, y, stat=s)
4748

4849
End Program

0 commit comments

Comments
 (0)