@@ -71,6 +71,7 @@ import Control.Monad (unless, when, zipWithM_)
71
71
import Control.Monad.Except (MonadError (.. ), Except )
72
72
import Control.Monad.Reader (MonadReader (.. ), ReaderT (.. ), asks )
73
73
import Control.Monad.State.Strict (MonadState (.. ), State , StateT , execStateT , evalState , gets , modify )
74
+ import qualified Data.Bits as Bits
74
75
import qualified Data.ByteString.Char8 as BSC
75
76
import qualified Data.ByteString as BS
76
77
import Data.Foldable
@@ -664,20 +665,32 @@ addMemAccessInfo :: StmtIndex -> MemAccessInfo arch ids -> StartInfer arch ids (
664
665
addMemAccessInfo idx i = seq idx $ seq i $ do
665
666
modify $ \ s -> s { sisMemAccessStack = (idx,i) : sisMemAccessStack s }
666
667
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`.
667
671
processApp :: (OrdF (ArchReg arch ), MemWidth (ArchAddrWidth arch ))
668
672
=> AssignId ids tp
669
673
-> App (Value arch ids ) tp
670
674
-> StartInfer arch ids ()
671
675
processApp aid app = do
672
676
ctx <- ask
673
677
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.
674
683
case fmapFC (valueToStartExpr ctx am) app of
675
684
BVAdd _ (FrameExpr o) (IVCValue (BVCValue _ c)) ->
676
685
setAssignVal aid (FrameExpr (o+ fromInteger c))
677
686
BVAdd _ (IVCValue (BVCValue _ c)) (FrameExpr o) ->
678
687
setAssignVal aid (FrameExpr (o+ fromInteger c))
679
688
BVSub _ (FrameExpr o) (IVCValue (BVCValue _ c)) ->
680
689
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))
681
694
appExpr -> do
682
695
c <- gets sisAppCache
683
696
-- Check to see if we have seen an app equivalent to
0 commit comments