[flang-commits] [PATCH] D112241: [flang] Enforce rest of semantic constraint C919
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Thu Oct 21 10:47:44 PDT 2021
klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
klausler requested review of this revision.
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.)
https://reviews.llvm.org/D112241
Files:
flang/include/flang/Semantics/expression.h
flang/lib/Semantics/expression.cpp
flang/test/Semantics/deallocate01.f90
Index: flang/test/Semantics/deallocate01.f90
===================================================================
--- flang/test/Semantics/deallocate01.f90
+++ flang/test/Semantics/deallocate01.f90
@@ -29,20 +29,21 @@
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
Index: flang/lib/Semantics/expression.cpp
===================================================================
--- flang/lib/Semantics/expression.cpp
+++ flang/lib/Semantics/expression.cpp
@@ -235,7 +235,7 @@
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 @@
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 @@
}
// 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};
}
Index: flang/include/flang/Semantics/expression.h
===================================================================
--- flang/include/flang/Semantics/expression.h
+++ flang/include/flang/Semantics/expression.h
@@ -317,6 +317,8 @@
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> &&);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112241.381321.patch
Type: text/x-patch
Size: 3078 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20211021/712ef588/attachment.bin>
More information about the flang-commits
mailing list