Skip to content

Commit 4f77995

Browse files
committed
Handle zero sized equivalence in lowering
The interval of zero sized equivalence storage looks like `[i, i[`, so when looking for an interval where `i` belongs, the PFT analysis was crashing. Accept `[i, i[` to be the right interval of null sized symbol starting at i.
1 parent d471d6f commit 4f77995

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

flang/lib/Lower/PFTBuilder.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,10 +1393,15 @@ struct SymbolDependenceDepth {
13931393
LLVM_DEBUG(llvm::dbgs() << "symbol: " << ultimate << '\n');
13941394
LLVM_DEBUG(llvm::dbgs() << "scope: " << scope << '\n');
13951395
auto off = ultimate.offset();
1396+
auto symSize = ultimate.size();
13961397
for (auto &v : stores) {
13971398
if (&v.getOwningScope() == &scope) {
1398-
auto bot = std::get<0>(v.interval);
1399-
if (off >= bot && off < bot + std::get<1>(v.interval))
1399+
auto intervalOff = std::get<0>(v.interval);
1400+
auto intervalSize = std::get<1>(v.interval);
1401+
if (off >= intervalOff && off < intervalOff + intervalSize)
1402+
return &v;
1403+
// Zero sized symbol in zero sized equivalence.
1404+
if (off == intervalOff && symSize == 0)
14001405
return &v;
14011406
}
14021407
}

flang/test/Lower/common-block.f90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
! CHECK: @_QBy = common global [12 x i8] zeroinitializer
66
! CHECK: @_QBz = global { i32, [4 x i8], float } { i32 42, [4 x i8] undef, float 3.000000e+00 }
77
! CHECK: @_QBrien = common global [1 x i8] zeroinitializer
8+
! CHECK: @_QBwith_empty_equiv = common global [8 x i8] zeroinitializer
89

910
! CHECK-LABEL: _QPs0
1011
subroutine s0
@@ -63,3 +64,10 @@ subroutine s5
6364
real r(1:0)
6465
common /rien/ r
6566
end subroutine s5
67+
68+
! CHECK-LABEL: _QPs6
69+
subroutine s6
70+
real r1(1:0), r2(1:0), x, y
71+
common /with_empty_equiv/ x, r1, y
72+
equivalence(r1, r2)
73+
end subroutine s6

0 commit comments

Comments
 (0)