Skip to content

Commit 4b98e35

Browse files
committed
genBackEdgeMap: Convert to BackEdgeMap only after filtering for dominance.
Conversion to BackEdgeMap too soon screws up one-to-many nodes, since it is a one-to-one map. This wasn't a problem in the past because of the way we translated loops into AST, the 'continue' basic block was always a 1-entrance, 1-exit deal. But now it is possible for a do-loop to be translated into a single basic block with multiple exits, so the bug is triggered.
1 parent 8a663c3 commit 4b98e35

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/Language/Fortran/Analysis/DataFlow.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,9 @@ type BackEdgeMap = IM.IntMap Node
325325
-- target node dominates the source node. If the backedges are viewed
326326
-- as (m -> n) then n is considered the 'loop-header'
327327
genBackEdgeMap :: Graph gr => DomMap -> gr a b -> BackEdgeMap
328-
genBackEdgeMap domMap = IM.filterWithKey isBackEdge . IM.fromList . edges
328+
genBackEdgeMap domMap = IM.fromList . filter isBackEdge . edges
329329
where
330-
isBackEdge s t = t `IS.member` (fromJustMsg "genBackEdgeMap" $ s `IM.lookup` domMap)
330+
isBackEdge (s, t) = t `IS.member` (fromJustMsg "genBackEdgeMap" $ s `IM.lookup` domMap)
331331

332332
-- | For each loop in the program, find out which bblock nodes are
333333
-- part of the loop by looking through the backedges (m, n) where n is

test/Language/Fortran/Analysis/DataFlowSpec.hs

+23
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ spec =
178178
let ivMap = genInductionVarMapByASTBlock bedges gr
179179
(sort . map (\ x -> (head x, length x)) . group . sort . map S.size $ IM.elems ivMap) `shouldBe` [(1,3),(2,3)]
180180

181+
describe "bug36" $ do
182+
let pf = pParser F90 programBug36
183+
let sgr = genSuperBBGr (genBBlockMap pf)
184+
let gr = superBBGrGraph sgr
185+
let domMap = dominators gr
186+
let bedges = genBackEdgeMap domMap gr
187+
it "loopNodes" $ do
188+
length (loopNodes bedges gr) `shouldBe` 2
189+
181190
--------------------------------------------------
182191
-- Label-finding helper functions to help write tests that are
183192
-- insensitive to minor changes to the AST.
@@ -315,6 +324,20 @@ programRd4 = unlines [
315324
, ""
316325
]
317326

327+
-- do not use line numbers
328+
programBug36 = unlines [
329+
"program foo"
330+
, " implicit none"
331+
, " integer :: i, j"
332+
, " real, dimension(100) :: a, b"
333+
, " do i=1,100"
334+
, " do j=1,100"
335+
, " a(i) = b(i) + b(1)"
336+
, " end do"
337+
, " end do"
338+
, "end program"
339+
]
340+
318341
-- Local variables:
319342
-- mode: haskell
320343
-- haskell-program-name: "cabal repl test-suite:spec"

0 commit comments

Comments
 (0)