Added a couple more tests for checkUnusedVar which has revealed two bugs

One of these bugs is that array variables are counted as unused when they are used subscripted.  I think that should be solved when we flip back to the listify approach.

The second bug is more interesting, as it is triggered only in a certain arrangement with an IF.  It's either a bug in the flow-graph building or in the varsTouchedAfter code.
This commit is contained in:
Neil Brown 2008-11-20 15:06:36 +00:00
parent 5f9bd6b829
commit e117422c31
2 changed files with 38 additions and 0 deletions

View File

@ -54,6 +54,39 @@ testUnusedVar = TestList
[decl (return A.Int) oX []]
`becomes`
oSEQ []
,testSame "Used array variable" $ wrap $
oSEQ [
decl (return $ A.Array [A.Dimension $ intLiteral 2] A.Int) oX
[oX `sub` 0 *:= (return (0::Int))]
]
,testSame "One variable, used in one IF branch" $ wrap $
oSEQ [
decl (return A.Int) oX
[oIF
[ifChoice (True, oX *:= (return (0::Int)))
,ifChoice (True, oSKIP)
]
]
]
,testSame "One variable, declared in an IF and used in one IF branch" $ wrap $
oIF
[
decl (return A.Int) oX
[ifChoice (True, oX *:= (return (0::Int)))
,ifChoice (True, oSKIP)
]
]
,testSame "One variable, declared in an IF and used in second IF branch" $ wrap $
oIF
[
decl (return A.Int) oX
[ifChoice (True, oSKIP)
,ifChoice (True, oX *:= (return (0::Int)))
]
]
]
where
wrap x = oPROC "foo" [] x oempty

View File

@ -23,6 +23,7 @@ module OccamEDSL (ExpInp, ExpInpT,
oALT, guard,
oIF, ifChoice,
Occ, oA, oB, oC, oX, oY, oZ, p0, p1, p2, (*?), (*!), (*:=), (*+), decl, decl', decl'',
sub,
oempty, testOccamPass,
oprocess,
testOccamPassWarn, testOccamPassTransform, ExpInpC(shouldComeFrom),
@ -292,6 +293,10 @@ infix 8 *:=
return (A.Dyadic emptyMeta A.Add x' y')
sub :: ExpInp A.Variable -> Int -> ExpInp A.Variable
sub v n = liftM (A.SubscriptedVariable emptyMeta (A.Subscript emptyMeta A.CheckBoth
$ intLiteral $ toInteger n)) v
decl :: Data a => ExpInp A.Type -> ExpInp A.Variable ->
[O (A.Structured a)] -> O (A.Structured a)
decl bty bvar scope = do