From c05380d518056189412e12128a8906b8ca6f6717 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 4 Feb 2023 13:19:27 -0800 Subject: [PATCH] Count CFEExit as control flow for the purposes of finding dominators --- src/ShellCheck/CFG.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ShellCheck/CFG.hs b/src/ShellCheck/CFG.hs index e0c6267..f882adc 100644 --- a/src/ShellCheck/CFG.hs +++ b/src/ShellCheck/CFG.hs @@ -192,7 +192,7 @@ buildGraph params root = base idToRange = M.fromList mapping - isRealEdge (from, to, edge) = case edge of CFEFlow -> True; _ -> False + isRealEdge (from, to, edge) = case edge of CFEFlow -> True; CFEExit -> True; _ -> False onlyRealEdges = filter isRealEdge edges (_, mainExit) = fromJust $ M.lookup (getId root) idToRange @@ -1301,7 +1301,10 @@ findPostDominators mainexit graph = asArray reversed = grev withExitEdges postDoms = dom reversed mainexit (_, maxNode) = nodeRange graph - asArray = array (0, maxNode) postDoms + -- Holes in the array cause "Exception: (Array.!): undefined array element" while + -- inspecting/debugging, so fill the array first and then update. + initializedArray = listArray (0, maxNode) $ repeat [] + asArray = initializedArray // postDoms return [] runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])