-
Notifications
You must be signed in to change notification settings - Fork 63
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
Array copy set prep #1515
Array copy set prep #1515
Changes from 15 commits
d5d1c68
6e5e014
b12e9e6
48872d2
e6c168d
9e1cb40
42899bb
349d001
7fbf5dd
16ab2b0
83580ed
8041408
2c05dbc
31321c2
ddbba7b
4cd4aa3
b41fa9e
eb83fb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ module SAWScript.Crucible.LLVM.Builtins | |
, llvm_alloc_readonly | ||
, llvm_alloc_readonly_aligned | ||
, llvm_alloc_with_size | ||
, llvm_alloc_sym_init | ||
, llvm_symbolic_alloc | ||
, llvm_alloc_global | ||
, llvm_fresh_expanded_val | ||
|
@@ -487,7 +488,7 @@ withMethodSpec :: | |
LLVMModule arch -> | ||
String {- ^ Name of the function -} -> | ||
LLVMCrucibleSetupM () {- ^ Boundary specification -} -> | ||
((?lc :: Crucible.TypeContext, ?memOpts::Crucible.MemOptions, Crucible.HasPtrWidth (Crucible.ArchWidth arch), Crucible.HasLLVMAnn Sym) => | ||
((?lc :: Crucible.TypeContext, ?memOpts::Crucible.MemOptions, ?w4EvalTactic :: W4EvalTactic, Crucible.HasPtrWidth (Crucible.ArchWidth arch), Crucible.HasLLVMAnn Sym) => | ||
LLVMCrucibleContext arch -> MS.CrucibleMethodSpecIR (LLVM arch) -> TopLevel a) -> | ||
TopLevel a | ||
withMethodSpec pathSat lm nm setup action = | ||
|
@@ -533,6 +534,7 @@ withMethodSpec pathSat lm nm setup action = | |
verifyMethodSpec :: | ||
( ?lc :: Crucible.TypeContext | ||
, ?memOpts::Crucible.MemOptions | ||
, ?w4EvalTactic :: W4EvalTactic | ||
, Crucible.HasPtrWidth (Crucible.ArchWidth arch) | ||
, Crucible.HasLLVMAnn Sym | ||
) => | ||
|
@@ -739,7 +741,7 @@ checkSpecReturnType cc mspec = | |
-- Returns a tuple of (arguments, preconditions, pointer values, | ||
-- memory). | ||
verifyPrestate :: | ||
(Crucible.HasPtrWidth (Crucible.ArchWidth arch), Crucible.HasLLVMAnn Sym) => | ||
(?w4EvalTactic :: W4EvalTactic, Crucible.HasPtrWidth (Crucible.ArchWidth arch), Crucible.HasLLVMAnn Sym) => | ||
Options -> | ||
LLVMCrucibleContext arch -> | ||
MS.CrucibleMethodSpecIR (LLVM arch) -> | ||
|
@@ -853,7 +855,7 @@ checkRegisterCompatibility mt mt' = | |
return (st == st') | ||
|
||
resolveArguments :: | ||
(?lc :: Crucible.TypeContext, Crucible.HasPtrWidth (Crucible.ArchWidth arch)) => | ||
(?lc :: Crucible.TypeContext, ?w4EvalTactic :: W4EvalTactic, Crucible.HasPtrWidth (Crucible.ArchWidth arch)) => | ||
LLVMCrucibleContext arch -> | ||
Crucible.MemImpl Sym -> | ||
MS.CrucibleMethodSpecIR (LLVM arch) -> | ||
|
@@ -925,7 +927,7 @@ setupGlobalAllocs cc mspec mem0 = foldM go mem0 $ mspec ^. MS.csGlobalAllocs | |
-- function spec, write the given value to the address of the given | ||
-- pointer. | ||
setupPrePointsTos :: forall arch. | ||
(?lc :: Crucible.TypeContext, Crucible.HasPtrWidth (Crucible.ArchWidth arch), Crucible.HasLLVMAnn Sym) => | ||
(?lc :: Crucible.TypeContext, ?w4EvalTactic :: W4EvalTactic, Crucible.HasPtrWidth (Crucible.ArchWidth arch), Crucible.HasLLVMAnn Sym) => | ||
MS.CrucibleMethodSpecIR (LLVM arch) -> | ||
Options -> | ||
LLVMCrucibleContext arch -> | ||
|
@@ -954,7 +956,7 @@ setupPrePointsTos mspec opts cc env pts mem0 = foldM go mem0 pts | |
-- | Sets up globals (ghost variable), and collects boolean terms | ||
-- that should be assumed to be true. | ||
setupPrestateConditions :: | ||
(?lc :: Crucible.TypeContext, Crucible.HasPtrWidth (Crucible.ArchWidth arch)) => | ||
(?lc :: Crucible.TypeContext, ?w4EvalTactic :: W4EvalTactic, Crucible.HasPtrWidth (Crucible.ArchWidth arch)) => | ||
MS.CrucibleMethodSpecIR (LLVM arch) -> | ||
LLVMCrucibleContext arch -> | ||
Crucible.MemImpl Sym -> | ||
|
@@ -1007,20 +1009,19 @@ assertEqualVals cc v1 v2 = | |
|
||
-- TODO(langston): combine with/move to executeAllocation | ||
doAlloc :: | ||
(Crucible.HasPtrWidth (Crucible.ArchWidth arch)) => | ||
(?w4EvalTactic :: W4EvalTactic, Crucible.HasPtrWidth (Crucible.ArchWidth arch), Crucible.HasLLVMAnn Sym) => | ||
LLVMCrucibleContext arch -> | ||
AllocIndex -> | ||
LLVMAllocSpec -> | ||
StateT MemImpl IO (LLVMPtr (Crucible.ArchWidth arch)) | ||
doAlloc cc i (LLVMAllocSpec mut _memTy alignment sz loc fresh) | ||
doAlloc cc i (LLVMAllocSpec mut _memTy alignment sz loc fresh initialization) | ||
| fresh = liftIO $ executeFreshPointer cc i | ||
| otherwise = | ||
StateT $ \mem -> | ||
do let sym = cc^.ccBackend | ||
sz' <- liftIO $ resolveSAWSymBV cc Crucible.PtrWidth sz | ||
let l = show (W4.plSourceLoc loc) | ||
liftIO $ | ||
Crucible.doMalloc sym Crucible.HeapAlloc mut l mem sz' alignment | ||
liftIO $ doAllocSymInit sym mem mut alignment sz' l initialization | ||
|
||
-------------------------------------------------------------------------------- | ||
|
||
|
@@ -1045,6 +1046,7 @@ ppGlobalPair cc gp = | |
registerOverride :: | ||
( ?lc :: Crucible.TypeContext | ||
, ?memOpts::Crucible.MemOptions | ||
, ?w4EvalTactic :: W4EvalTactic | ||
, Crucible.HasPtrWidth wptr | ||
, wptr ~ Crucible.ArchWidth arch | ||
, Crucible.HasLLVMAnn Sym | ||
|
@@ -1087,6 +1089,7 @@ registerOverride opts cc sim_ctx top_loc cs = | |
registerInvariantOverride :: | ||
( ?lc :: Crucible.TypeContext | ||
, ?memOpts::Crucible.MemOptions | ||
, ?w4EvalTactic :: W4EvalTactic | ||
, Crucible.HasPtrWidth (Crucible.ArchWidth arch) | ||
, Crucible.HasLLVMAnn Sym | ||
) => | ||
|
@@ -1168,6 +1171,7 @@ withBreakpointCfgAndBlockId context name parent k = | |
verifySimulate :: | ||
( ?lc :: Crucible.TypeContext | ||
, ?memOpts::Crucible.MemOptions | ||
, ?w4EvalTactic :: W4EvalTactic | ||
, Crucible.HasPtrWidth wptr | ||
, wptr ~ Crucible.ArchWidth arch | ||
, Crucible.HasLLVMAnn Sym | ||
|
@@ -1287,6 +1291,7 @@ scAndList sc = conj . filter nontrivial | |
verifyPoststate :: | ||
( ?lc :: Crucible.TypeContext | ||
, ?memOpts::Crucible.MemOptions | ||
, ?w4EvalTactic :: W4EvalTactic | ||
, Crucible.HasPtrWidth wptr | ||
, wptr ~ Crucible.ArchWidth arch | ||
, Crucible.HasLLVMAnn Sym | ||
|
@@ -1355,7 +1360,7 @@ verifyPoststate cc mspec env0 globals ret = | |
setupLLVMCrucibleContext :: | ||
Bool {- ^ enable path sat checking -} -> | ||
LLVMModule arch -> | ||
((?lc :: Crucible.TypeContext, ?memOpts::Crucible.MemOptions, Crucible.HasPtrWidth (Crucible.ArchWidth arch), Crucible.HasLLVMAnn Sym) => | ||
((?lc :: Crucible.TypeContext, ?memOpts::Crucible.MemOptions, ?w4EvalTactic :: W4EvalTactic, Crucible.HasPtrWidth (Crucible.ArchWidth arch), Crucible.HasLLVMAnn Sym) => | ||
LLVMCrucibleContext arch -> TopLevel a) -> | ||
TopLevel a | ||
setupLLVMCrucibleContext pathSat lm action = | ||
|
@@ -1370,6 +1375,8 @@ setupLLVMCrucibleContext pathSat lm action = | |
crucible_assert_then_assume_enabled <- gets rwCrucibleAssertThenAssume | ||
what4HashConsing <- gets rwWhat4HashConsing | ||
laxPointerOrdering <- gets rwLaxPointerOrdering | ||
what4Eval <- gets rwWhat4Eval | ||
crucibleTimeout <- gets rwCrucibleTimeout | ||
Crucible.llvmPtrWidth ctx $ \wptr -> | ||
Crucible.withPtrWidth wptr $ | ||
do let ?lc = ctx^.Crucible.llvmTypeCtx | ||
|
@@ -1378,10 +1385,11 @@ setupLLVMCrucibleContext pathSat lm action = | |
} | ||
let ?intrinsicsOpts = Crucible.defaultIntrinsicsOptions | ||
let ?recordLLVMAnnotation = \_ _ -> return () | ||
let ?w4EvalTactic = W4EvalTactic { doW4Eval = what4Eval } | ||
cc <- | ||
io $ | ||
do let verbosity = simVerbose opts | ||
sym <- Common.newSAWCoreBackend sc | ||
sym <- Common.newSAWCoreBackendWithTimeout sc crucibleTimeout | ||
|
||
let cfg = W4.getConfiguration sym | ||
verbSetting <- W4.getOptionSetting W4.verbosity cfg | ||
|
@@ -1866,9 +1874,10 @@ llvm_alloc_with_mutability_and_size :: | |
Crucible.Mutability -> | ||
Maybe (Crucible.Bytes) -> | ||
Maybe Crucible.Alignment -> | ||
LLVMAllocSpecInit -> | ||
L.Type -> | ||
LLVMCrucibleSetupM (AllLLVM SetupValue) | ||
llvm_alloc_with_mutability_and_size mut sz alignment lty = | ||
llvm_alloc_with_mutability_and_size mut sz alignment initialization lty = | ||
LLVMCrucibleSetupM $ | ||
do cctx <- getLLVMCrucibleContext | ||
loc <- getW4Position "llvm_alloc" | ||
|
@@ -1913,13 +1922,14 @@ llvm_alloc_with_mutability_and_size mut sz alignment lty = | |
, _allocSpecBytes = sz'' | ||
, _allocSpecLoc = loc | ||
, _allocSpecFresh = False | ||
, _allocSpecInit = initialization | ||
} | ||
|
||
llvm_alloc :: | ||
L.Type -> | ||
LLVMCrucibleSetupM (AllLLVM SetupValue) | ||
llvm_alloc = | ||
llvm_alloc_with_mutability_and_size Crucible.Mutable Nothing Nothing | ||
llvm_alloc_with_mutability_and_size Crucible.Mutable Nothing Nothing LLVMAllocSpecNoInitialization | ||
|
||
llvm_alloc_aligned :: | ||
Int -> | ||
|
@@ -1932,7 +1942,7 @@ llvm_alloc_readonly :: | |
L.Type -> | ||
LLVMCrucibleSetupM (AllLLVM SetupValue) | ||
llvm_alloc_readonly = | ||
llvm_alloc_with_mutability_and_size Crucible.Immutable Nothing Nothing | ||
llvm_alloc_with_mutability_and_size Crucible.Immutable Nothing Nothing LLVMAllocSpecNoInitialization | ||
|
||
llvm_alloc_readonly_aligned :: | ||
Int -> | ||
|
@@ -1952,6 +1962,7 @@ llvm_alloc_aligned_with_mutability mut n lty = | |
mut | ||
Nothing | ||
(Just alignment) | ||
LLVMAllocSpecNoInitialization | ||
lty | ||
|
||
coerceAlignment :: Int -> CrucibleSetup (LLVM arch) Crucible.Alignment | ||
|
@@ -1975,8 +1986,13 @@ llvm_alloc_with_size sz lty = | |
Crucible.Mutable | ||
(Just (Crucible.toBytes sz)) | ||
Nothing | ||
LLVMAllocSpecNoInitialization | ||
lty | ||
|
||
llvm_alloc_sym_init :: L.Type -> LLVMCrucibleSetupM (AllLLVM SetupValue) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious: does this work in practice when you apply in an a specification that is assumed with I suppose this is a long-winded way of asking for some more test cases using |
||
llvm_alloc_sym_init = | ||
llvm_alloc_with_mutability_and_size Crucible.Mutable Nothing Nothing LLVMAllocSpecSymbolicInitialization | ||
|
||
llvm_symbolic_alloc :: | ||
Bool -> | ||
Int -> | ||
|
@@ -2008,6 +2024,7 @@ llvm_symbolic_alloc ro align_bytes sz = | |
, _allocSpecBytes = sz | ||
, _allocSpecLoc = loc | ||
, _allocSpecFresh = False | ||
, _allocSpecInit = LLVMAllocSpecNoInitialization | ||
} | ||
n <- Setup.csVarCounter <<%= nextAllocIndex | ||
Setup.currentState . MS.csAllocs . at n ?= spec | ||
|
@@ -2057,6 +2074,7 @@ constructFreshPointer mid loc memTy = | |
, _allocSpecBytes = sz | ||
, _allocSpecLoc = loc | ||
, _allocSpecFresh = True | ||
, _allocSpecInit = LLVMAllocSpecNoInitialization | ||
} | ||
-- TODO: refactor | ||
case mid of | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's open ticket about plumbing this new option through the RPC server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what it's worth, it's fairly easy to add support for toggling options like this in
saw-remote-api
. You basically just add a new constructor here, and then update the code insetOption
,parseOption
, andinstance Doc.DescribedMethod SetOptionParams OK
accordingly.