Skip to content

Commit eb0a3c7

Browse files
authored
Merge pull request #406 from GaloisInc/vr/register-use-bvand
support alignment ops when processing statements in `RegisterUse`
2 parents 82aae49 + dc1591d commit eb0a3c7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

base/src/Data/Macaw/Analysis/RegisterUse.hs

+13
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import Control.Monad (unless, when, zipWithM_)
7171
import Control.Monad.Except (MonadError(..), Except)
7272
import Control.Monad.Reader (MonadReader(..), ReaderT(..), asks)
7373
import Control.Monad.State.Strict (MonadState(..), State, StateT, execStateT, evalState, gets, modify)
74+
import qualified Data.Bits as Bits
7475
import qualified Data.ByteString.Char8 as BSC
7576
import qualified Data.ByteString as BS
7677
import Data.Foldable
@@ -664,20 +665,32 @@ addMemAccessInfo :: StmtIndex -> MemAccessInfo arch ids -> StartInfer arch ids (
664665
addMemAccessInfo idx i = seq idx $ seq i $ do
665666
modify $ \s -> s { sisMemAccessStack = (idx,i) : sisMemAccessStack s }
666667

668+
-- | @processApp aid app@ computes the effect of a program assignment @aid <- app@. When `app` is
669+
-- a computation over a stack offset expression (a `FrameExpr`), we attempt to simplify it, as we
670+
-- require a concrete stack offset when computing `postCallConstraints`.
667671
processApp :: (OrdF (ArchReg arch), MemWidth (ArchAddrWidth arch))
668672
=> AssignId ids tp
669673
-> App (Value arch ids) tp
670674
-> StartInfer arch ids ()
671675
processApp aid app = do
672676
ctx <- ask
673677
am <- gets sisAssignMap
678+
-- This inspects the `app` term to detect cases where the abstract expression can be simplified
679+
-- down to a `FrameExpr` expression. In such cases, the simplified expression is registered as
680+
-- the value for this assignment. Otherwise, the value for the assignment remains abstract.
681+
-- This may not be exhaustive, so if you encounter the `CallStackHeightError` in
682+
-- `postCallConstraints`, you may need to extend the patterns recognized here.
674683
case fmapFC (valueToStartExpr ctx am) app of
675684
BVAdd _ (FrameExpr o) (IVCValue (BVCValue _ c)) ->
676685
setAssignVal aid (FrameExpr (o+fromInteger c))
677686
BVAdd _ (IVCValue (BVCValue _ c)) (FrameExpr o) ->
678687
setAssignVal aid (FrameExpr (o+fromInteger c))
679688
BVSub _ (FrameExpr o) (IVCValue (BVCValue _ c)) ->
680689
setAssignVal aid (FrameExpr (o-fromInteger c))
690+
BVAnd _ (FrameExpr o) (IVCValue (BVCValue _ c)) ->
691+
setAssignVal aid (FrameExpr (o Bits..&. fromInteger c))
692+
BVAnd _ (IVCValue (BVCValue _ c)) (FrameExpr o) ->
693+
setAssignVal aid (FrameExpr (o Bits..&. fromInteger c))
681694
appExpr -> do
682695
c <- gets sisAppCache
683696
-- Check to see if we have seen an app equivalent to

0 commit comments

Comments
 (0)