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

Remove redundant "valid pointer" checks from memory loads and stores. #310

Merged
merged 2 commits into from
Aug 8, 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
4 changes: 4 additions & 0 deletions symbolic/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@
- The following functions now have a `?memOpts :: MemOptions` constraint:
- `Data.Macaw.Symbolic.Memory.newGlobalMemory`
- `Data.Macaw.Symbolic.MemOps.{doWriteMem,doCondWriteMem}`

### Behavioral Changes

- Redundant pointer validity checks have been removed from `doReadMem`, `doCondReadMem`, `doWriteMem`, and `doCondWriteMem`; this should be mostly invisible to library clients unless they rely on goal counts or goal numbers
23 changes: 2 additions & 21 deletions symbolic/src/Data/Macaw/Symbolic/MemOps.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,11 +1005,6 @@ doReadMem ::
IO (RegValue sym (ToCrucibleType ty))
doReadMem bak mem ptrWidth memRep ptr = hasPtrClass ptrWidth $
do let sym = backendGetSym bak
-- Check pointer is valid.
-- Note. I think we should check that pointer has at least "bytes" bytes available?
ok <- isValidPtr sym mem ptrWidth ptr
check bak ok "doReadMem" $
"Reading through an invalid pointer: " ++ show (Mem.ppPtr ptr)
ty <- case memReprToStorageType (getEnd mem) memRep of
Left msg -> throwIO $ userError msg
Right tp -> pure tp
Expand Down Expand Up @@ -1042,11 +1037,6 @@ doCondReadMem ::
IO (RegValue sym (ToCrucibleType ty))
doCondReadMem bak mem ptrWidth memRep cond ptr def = hasPtrClass ptrWidth $
do let sym = backendGetSym bak
-- Check pointer is valid.
-- Note. I think we should check that pointer has at least "bytes" bytes available?
ok <- isValidPtr sym mem ptrWidth ptr
check bak ok "doCondReadMem" $
"Conditional read through an invalid pointer: " ++ show (Mem.ppPtr ptr)

ty <- case memReprToStorageType (getEnd mem) memRep of
Left msg -> throwIO $ userError msg
Expand Down Expand Up @@ -1082,11 +1072,7 @@ doWriteMem ::
RegValue sym (ToCrucibleType ty) ->
IO (MemImpl sym)
doWriteMem bak mem ptrWidth memRep ptr val = hasPtrClass ptrWidth $
do let sym = backendGetSym bak
ok <- isValidPtr sym mem ptrWidth ptr
check bak ok "doWriteMem" $
"Write to an invalid location: " ++ show (Mem.ppPtr ptr)
ty <- case memReprToStorageType (getEnd mem) memRep of
do ty <- case memReprToStorageType (getEnd mem) memRep of
Left msg -> throwIO $ userError msg
Right tp -> pure tp
let alignment = noAlignment -- default to byte alignment (FIXME)
Expand Down Expand Up @@ -1114,12 +1100,7 @@ doCondWriteMem ::
RegValue sym (ToCrucibleType ty) ->
IO (MemImpl sym)
doCondWriteMem bak mem ptrWidth memRep cond ptr val = hasPtrClass ptrWidth $
do let sym = backendGetSym bak
ok <- isValidPtr sym mem ptrWidth ptr
condOk <- impliesPred sym cond ok
check bak condOk "doWriteMem" $
"Write to an invalid location: " ++ show (Mem.ppPtr ptr)
ty <- case memReprToStorageType (getEnd mem) memRep of
do ty <- case memReprToStorageType (getEnd mem) memRep of
Left msg -> throwIO $ userError msg
Right tp -> pure tp
let alignment = noAlignment -- default to byte alignment (FIXME)
Expand Down