Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X86 preconditions #1705

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/SAWScript/Crucible/LLVM/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ module SAWScript.Crucible.LLVM.Builtins
, findDecl
, findDefMaybeStatic
, setupLLVMCrucibleContext
, setupPrestateConditions
, checkSpecReturnType
, verifyPrestate
, verifyPoststate
Expand Down
20 changes: 13 additions & 7 deletions src/SAWScript/Crucible/LLVM/X86.hs
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,24 @@ llvm_verify_x86_common (Some (llvmModule :: LLVMModule x)) path nm globsyms chec
, C._cruciblePersonality = Macaw.MacawSimulatorState
, C._profilingMetrics = Map.empty
}
globals = C.insertGlobal mvar (preState ^. x86Mem) C.emptyGlobals

(globals, assumes) <-
do let globals0 = C.insertGlobal mvar (preState ^. x86Mem) C.emptyGlobals
liftIO $ setupPrestateConditions methodSpec cc (preState ^. x86Mem) env globals0
(methodSpec ^. MS.csPreState . MS.csConditions)

let
macawStructRepr = C.StructRepr $ Macaw.crucArchRegTypes Macaw.x86_64MacawSymbolicFns
initial = C.InitialState ctx globals C.defaultAbortHandler macawStructRepr
$ C.runOverrideSim macawStructRepr
$ Macaw.crucGenArchConstraints Macaw.x86_64MacawSymbolicFns
$ do
liftIO $
forM_ assumes $ \(C.LabeledPred p (md, reason)) ->
do expr <- resolveSAWPred cc p
let loc = MS.conditionLoc md
C.addAssumption bak
(C.GenericAssumption loc reason expr)
r <- C.callCFG cfg . C.RegMap . singleton . C.RegEntry macawStructRepr $ preState ^. x86Regs
globals' <- C.readGlobals
mem' <- C.readGlobal mvar
Expand Down Expand Up @@ -1083,9 +1095,6 @@ assertPost globals env premem preregs mdMap = do
pointsToMatches <- forM (ms ^. MS.csPostState . MS.csPointsTos)
$ assertPointsTo env tyenv nameEnv

let setupConditionMatchesPre = fmap -- assume preconditions
(LO.executeSetupCondition opts sc cc ms)
$ ms ^. MS.csPreState . MS.csConditions
let setupConditionMatchesPost = fmap -- assert postconditions
(LO.learnSetupCondition opts sc cc ms MS.PostState)
$ ms ^. MS.csPostState . MS.csConditions
Expand All @@ -1105,15 +1114,12 @@ assertPost globals env premem preregs mdMap = do
. sequence_ $ mconcat
[ returnMatches
, pointsToMatches
, setupConditionMatchesPre
, setupConditionMatchesPost
, [LO.assertTermEqualities sc cc]
]
st <- case result of
Left err -> throwX86 $ show err
Right (_, st) -> pure st
liftIO . forM_ (view O.osAssumes st) $ \(_md, asum) ->
C.addAssumption bak $ C.GenericAssumption (st ^. O.osLocation) "precondition" asum
liftIO . forM_ (view LO.osAsserts st) $ \(md, W4.LabeledPred p r) ->
do (ann,p') <- W4.annotateTerm sym p
modifyIORef mdMap (Map.insert ann md)
Expand Down