Skip to content

Commit 2104989

Browse files
committed
[flang] Fix references to equivalenced variables in inner procedures
The code that collects that host associated variables variables in inner procedures was seeing entities of type Fortran::lower::pft::Variable which were created for handling Fortran variables that appear in EQUIVANCE statements. Such entities throw an assertion when `getSymbol() is called on them because they're not of the `Nominal` variant. I wrote several tests (with help from Jean and Eric) for various situations where EQUIVALENCE and host association were combined. In every case where there was a host-associated Fortran variable appeared in an EQUIVALENCE statement, there were two entities created -- an entity of the `AggregateStore` variant and an entity of the `Nominal` variant. So it seems safe and correct to just ignore `Variable`s of the `AggregateStore` variant when gathering host associated entities. So that's what I did. I also added a FIXME to deal with the fact that internal procedures that access variables in EQUIVALENCE sets in outer scopes unnecessarily create their own AggregateStore. Note that my first attempt to fix this was in PR#1165.
1 parent 49db716 commit 2104989

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

flang/lib/Lower/Bridge.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
214214
Fortran::lower::pft::FunctionLikeUnit &funit,
215215
llvm::SetVector<const Fortran::semantics::Symbol *> &escapees) {
216216
for (const auto &var : funit.getOrderedSymbolTable()) {
217+
if (var.isAggregateStore())
218+
continue;
217219
const auto &sym = var.getSymbol();
218220
if (const auto *escapingSym = getIfHostProcedureSymbol(sym)) {
219221
LLVM_DEBUG(llvm::dbgs() << "host associated symbol " << sym << '\n');

flang/lib/Lower/PFTBuilder.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,11 @@ struct SymbolDependenceDepth {
12311231
: vars{vars}, reentrant{reentrant} {}
12321232

12331233
void analyzeAliasesInCurrentScope(const semantics::Scope &scope) {
1234+
// FIXME: When this function is called on the scope of an internal
1235+
// procedure whose parent contains an EQUIVALENCE set and the internal
1236+
// procedure uses variables from that EQUIVALENCE set, we end up creating
1237+
// an AggregateStore for those variables unnecessarily.
1238+
//
12341239
/// If this is a function nested in a module no host associated
12351240
/// symbol are added to the function scope for module symbols used in this
12361241
/// scope. As a result, alias analysis in parent module scopes must be

0 commit comments

Comments
 (0)