Skip to content

Commit 50dd216

Browse files
[flang] Add -pedantic check for passing non-VOLATILE array section to VOLATILE dummy arg
Add the check, which partially addresses #137369 Implement HasTriplet().
1 parent ae44138 commit 50dd216

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

flang/include/flang/Evaluate/tools.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,9 @@ extern template semantics::UnorderedSymbolSet CollectCudaSymbols(
11231123
// Predicate: does a variable contain a vector-valued subscript (not a triplet)?
11241124
bool HasVectorSubscript(const Expr<SomeType> &);
11251125

1126+
// Predicate: does a variable contain a triplet?
1127+
bool HasTriplet(const Expr<SomeType> &);
1128+
11261129
// Predicate: does an expression contain constant?
11271130
bool HasConstant(const Expr<SomeType> &);
11281131

flang/lib/Evaluate/tools.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,25 @@ bool HasVectorSubscript(const Expr<SomeType> &expr) {
11731173
return HasVectorSubscriptHelper{}(expr);
11741174
}
11751175

1176+
// HasTriplet()
1177+
struct HasTripletHelper
1178+
: public AnyTraverse<HasTripletHelper, bool,
1179+
/*TraverseAssocEntityDetails=*/false> {
1180+
using Base = AnyTraverse<HasTripletHelper, bool, false>;
1181+
HasTripletHelper() : Base{*this} {}
1182+
using Base::operator();
1183+
bool operator()(const Subscript &ss) const {
1184+
return std::holds_alternative<Triplet>(ss.u);
1185+
}
1186+
bool operator()(const ProcedureRef &) const {
1187+
return false; // don't descend into function call arguments
1188+
}
1189+
};
1190+
1191+
bool HasTriplet(const Expr<SomeType> &expr) {
1192+
return HasTripletHelper{}(expr);
1193+
}
1194+
11761195
// HasConstant()
11771196
struct HasConstantHelper : public AnyTraverse<HasConstantHelper, bool,
11781197
/*TraverseAssocEntityDetails=*/false> {

flang/lib/Semantics/definable.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ std::optional<parser::Message> WhyNotDefinable(parser::CharBlock at,
371371
return parser::Message{at,
372372
"Variable '%s' has a vector subscript"_err_en_US, expr.AsFortran()};
373373
}
374+
} else if (evaluate::HasTriplet(expr)) {
375+
return parser::Message{at,
376+
"Variable '%s' has array section"_err_en_US, expr.AsFortran()};
374377
}
375378
if (FindPureProcedureContaining(scope) &&
376379
evaluate::ExtractCoarrayRef(expr)) {

0 commit comments

Comments
 (0)