From e165030751cdcf7a9acdc50cbff4324eccd1743c Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Sun, 8 Feb 2009 23:08:58 +0000 Subject: [PATCH] Stopped Tock checking arrays that are declared inside the PAR being examined Fixes #84 --- checks/ArrayUsageCheck.hs | 10 +++++++++- testcases/automatic/usage-check-2.occ.test | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/checks/ArrayUsageCheck.hs b/checks/ArrayUsageCheck.hs index a1176bb..0a2fe59 100644 --- a/checks/ArrayUsageCheck.hs +++ b/checks/ArrayUsageCheck.hs @@ -99,6 +99,13 @@ checkArrayUsage :: forall m. (Die m, CSMR m, MonadIO m) => (Meta, ParItems (BK, checkArrayUsage (m,p) = mapM_ (checkIndexes m) $ Map.toList $ groupArrayIndexes $ fmap (transformPair id nodeVars) p where + getDecl :: UsageLabel -> Maybe String + getDecl = join . fmap getScopeIn . nodeDecl + where + getScopeIn (ScopeIn _ n) = Just n + getScopeIn _ = Nothing + + -- Takes a ParItems Vars, and returns a map from array-variable-name to a list of writes and a list of reads for that array. -- Returns (array name, list of written-to indexes, list of read-from indexes) groupArrayIndexes :: ParItems (BK, Vars) -> Map.Map String (ParItems (BK, [A.Expression], [A.Expression])) @@ -135,7 +142,8 @@ checkArrayUsage (m,p) = mapM_ (checkIndexes m) $ Map.toList $ checkIndexes :: Meta -> (String, ParItems (BK, [A.Expression], [A.Expression])) -> m () checkIndexes m (arrName, indexes) = do sharedNames <- getCompState >>* csNameAttr - when (Map.lookup arrName sharedNames /= Just NameShared) $ + let declNames = [x | Just x <- fmap (getDecl . snd) $ flattenParItems p] + when (Map.lookup arrName sharedNames /= Just NameShared && arrName `notElem` declNames) $ do userArrName <- getRealName (A.Name undefined arrName) arrType <- astTypeOf (A.Name undefined arrName) arrLength <- case arrType of diff --git a/testcases/automatic/usage-check-2.occ.test b/testcases/automatic/usage-check-2.occ.test index ae9dfe5..11d5860 100644 --- a/testcases/automatic/usage-check-2.occ.test +++ b/testcases/automatic/usage-check-2.occ.test @@ -48,4 +48,12 @@ PROC m() PAR j = 0 FOR 2 b[(j * 8) + i] := 3 +%PASS Safe use of variable declared inside PAR + [10]INT c: + c[0] := 1 +%PASS Safe parallel use of variable declared inside PAR + [10]INT c: + PAR + c[0] := 1 + c[1] := 2 %