Skip to content

Commit

Permalink
Add enable_lax_pointer_ordering
Browse files Browse the repository at this point in the history
Fixes #1308.
  • Loading branch information
RyanGlScott committed May 25, 2021
1 parent 5535b03 commit 6ec6e69
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Several improvements have been made to JVM verification:
"current" status, so that `enable_experimental` is no longer
necessary for JVM verification.

A new `enable_lax_pointer_ordering` function exists, which relaxes the
restrictions that Crucible imposes on comparisons between pointers from
different allocation blocks.

# Version 0.8

## New Features
Expand Down
11 changes: 11 additions & 0 deletions intTests/test1308/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CC = clang
CFLAGS = -g -emit-llvm -frecord-command-line -O2

all: test.bc

test.bc: test.c
$(CC) $(CFLAGS) -c $< -o $@

.PHONY: clean
clean:
rm -f test.bc
Binary file added intTests/test1308/test.bc
Binary file not shown.
10 changes: 10 additions & 0 deletions intTests/test1308/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdint.h>
#include <stdlib.h>

const size_t LEN = 42;

void zip_with_add(uint64_t c[LEN], const uint64_t a[LEN], const uint64_t b[LEN]) {
for (size_t i = 0; i < LEN; i++) {
c[i] = a[i] + b[i];
}
}
29 changes: 29 additions & 0 deletions intTests/test1308/test.saw
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
enable_lax_pointer_ordering;

let alloc_init_readonly ty v = do {
p <- llvm_alloc_readonly ty;
llvm_points_to p v;
return p;
};

let ptr_to_fresh_readonly n ty = do {
x <- llvm_fresh_var n ty;
p <- alloc_init_readonly ty (llvm_term x);
return (x, p);
};

let LEN = 42;

let zip_with_add_spec = do {
let array_ty = llvm_array LEN (llvm_int 64);
c_ptr <- llvm_alloc array_ty;
(a, a_ptr) <- ptr_to_fresh_readonly "a" array_ty;
(b, b_ptr) <- ptr_to_fresh_readonly "b" array_ty;

llvm_execute_func [c_ptr, a_ptr, b_ptr];

llvm_points_to c_ptr (llvm_term {{ zipWith`{LEN} (+) a b }});
};

mod <- llvm_load_module "test.bc";
llvm_verify mod "zip_with_add" [] false zip_with_add_spec z3;
3 changes: 3 additions & 0 deletions intTests/test1308/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set -e

$SAW test.saw
2 changes: 1 addition & 1 deletion saw-remote-api/docs/SAW.rst
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ SAW/set option (command)


``option``
The option to set and its accompanying value (i.e., true or false); one of the following:``lax arithmetic``, ``SMT array memory model``, or ``What4 hash consing``
The option to set and its accompanying value (i.e., true or false); one of the following:``lax arithmetic``, ``lax pointer ordering``, ``SMT array memory model``, or ``What4 hash consing``


Set a SAW option in the server.
Expand Down
1 change: 1 addition & 0 deletions saw-remote-api/docs/old-Saw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ Setting Options
- ``option``: The name of the option to set. This is one of:

* ``lax arithmetic``
* ``lax pointer ordering``
* ``SMT array memory model``
* ``What4 hash consing``

Expand Down
1 change: 1 addition & 0 deletions saw-remote-api/src/SAWServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ initialState readFileFn =
, rwProfilingFile = Nothing
, rwCrucibleAssertThenAssume = False
, rwLaxArith = False
, rwLaxPointerOrdering = False
, rwWhat4HashConsing = False
, rwWhat4HashConsingX86 = False
, rwStackBaseAlign = defaultStackBaseAlign
Expand Down
5 changes: 5 additions & 0 deletions saw-remote-api/src/SAWServer/SetOption.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ setOption opt =
case opt of
EnableLaxArithmetic enabled ->
updateRW rw { rwLaxArith = enabled }
EnableLaxPointerOrdering enabled ->
updateRW rw { rwLaxPointerOrdering = enabled }
EnableSMTArrayMemoryModel enabled -> undefined
updateRW rw { rwSMTArrayMemoryModel = enabled }
EnableWhat4HashConsing enabled -> undefined
Expand All @@ -38,13 +40,15 @@ setOption opt =

data SetOptionParams
= EnableLaxArithmetic Bool
| EnableLaxPointerOrdering Bool
| EnableSMTArrayMemoryModel Bool
| EnableWhat4HashConsing Bool

parseOption :: Object -> String -> Parser SetOptionParams
parseOption o name =
case name of
"lax arithmetic" -> EnableLaxArithmetic <$> o .: "value"
"lax pointer ordering" -> EnableLaxPointerOrdering <$> o .: "value"
"SMT array memory model" -> EnableSMTArrayMemoryModel <$> o .: "value"
"What4 hash consing" -> EnableWhat4HashConsing <$> o .: "value"
_ -> empty
Expand All @@ -59,6 +63,7 @@ instance Doc.DescribedParams SetOptionParams where
[ ("option",
Doc.Paragraph [Doc.Text "The option to set and its accompanying value (i.e., true or false); one of the following:"
, Doc.Literal "lax arithmetic", Doc.Text ", "
, Doc.Literal "lax pointer ordering", Doc.Text ", "
, Doc.Literal "SMT array memory model", Doc.Text ", or "
, Doc.Literal "What4 hash consing"
])
Expand Down
6 changes: 5 additions & 1 deletion src/SAWScript/Crucible/LLVM/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,7 @@ setupLLVMCrucibleContext pathSat lm action =
smt_array_memory_model_enabled <- gets rwSMTArrayMemoryModel
crucible_assert_then_assume_enabled <- gets rwCrucibleAssertThenAssume
what4HashConsing <- gets rwWhat4HashConsing
laxPointerOrdering <- gets rwLaxPointerOrdering
Crucible.llvmPtrWidth ctx $ \wptr ->
Crucible.withPtrWidth wptr $
do let ?lc = ctx^.Crucible.llvmTypeCtx
Expand Down Expand Up @@ -1348,8 +1349,11 @@ setupLLVMCrucibleContext pathSat lm action =
crucible_assert_then_assume_enabled

let bindings = Crucible.fnBindingsFromList []
let memOpts = Crucible.defaultMemOptions
{ Crucible.laxPointerOrdering = laxPointerOrdering
}
let simctx = Crucible.initSimContext sym intrinsics halloc stdout
bindings (Crucible.llvmExtensionImpl Crucible.defaultMemOptions)
bindings (Crucible.llvmExtensionImpl memOpts)
Common.SAWCruciblePersonality
mem <- Crucible.populateConstGlobals sym (Crucible.globalInitMap mtrans)
=<< Crucible.initializeMemoryConstGlobals sym ctx llvm_mod
Expand Down
11 changes: 11 additions & 0 deletions src/SAWScript/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ buildTopLevelEnv proxy opts =
, rwCrucibleAssertThenAssume = False
, rwProfilingFile = Nothing
, rwLaxArith = False
, rwLaxPointerOrdering = False
, rwWhat4HashConsing = False
, rwWhat4HashConsingX86 = False
, rwPreservedRegs = []
Expand Down Expand Up @@ -538,6 +539,11 @@ enable_lax_arithmetic = do
rw <- getTopLevelRW
putTopLevelRW rw { rwLaxArith = True }

enable_lax_pointer_ordering :: TopLevel ()
enable_lax_pointer_ordering = do
rw <- getTopLevelRW
putTopLevelRW rw { rwLaxPointerOrdering = True }

enable_what4_hash_consing :: TopLevel ()
enable_what4_hash_consing = do
rw <- getTopLevelRW
Expand Down Expand Up @@ -759,6 +765,11 @@ primitives = Map.fromList
Current
[ "Enable lax rules for arithmetic overflow in Crucible." ]

, prim "enable_lax_pointer_ordering" "TopLevel ()"
(pureVal enable_lax_pointer_ordering)
Current
[ "Enable lax rules for pointer ordering comparisons in Crucible." ]

, prim "enable_what4_hash_consing" "TopLevel ()"
(pureVal enable_what4_hash_consing)
Current
Expand Down
3 changes: 2 additions & 1 deletion src/SAWScript/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ showsProofResult opts r =
case r of
ValidProof _ _ -> showString "Valid"
InvalidProof _ ts _ -> showString "Invalid: [" . showMulti "" ts
UnfinishedProof st -> showString "Unfinished: " . shows (length (psGoals st)) . showString " goals remaining"
UnfinishedProof st -> showString "Unfinished: " . shows (length (psGoals st)) . showString " goals remaining"
where
opts' = sawPPOpts opts
showVal t = shows (ppFirstOrderValue opts' t)
Expand Down Expand Up @@ -402,6 +402,7 @@ data TopLevelRW =
, rwCrucibleAssertThenAssume :: Bool
, rwProfilingFile :: Maybe FilePath
, rwLaxArith :: Bool
, rwLaxPointerOrdering :: Bool

-- FIXME: These might be better split into "simulator hash-consing" and "tactic hash-consing"
, rwWhat4HashConsing :: Bool
Expand Down

0 comments on commit 6ec6e69

Please sign in to comment.