Skip to content

Commit 0642f4c

Browse files
committed
Add enable_lax_pointer_ordering
Fixes #1308.
1 parent dabdee6 commit 0642f4c

File tree

13 files changed

+82
-2
lines changed

13 files changed

+82
-2
lines changed

CHANGES.md

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Several improvements have been made to JVM verification:
2020
"current" status, so that `enable_experimental` is no longer
2121
necessary for JVM verification.
2222

23+
A new `enable_lax_pointer_ordering` function exists, which relaxes the
24+
restrictions that Crucible imposes on comparisons between pointers from
25+
different allocation blocks.
26+
2327
# Version 0.8
2428

2529
## New Features

intTests/test1308/Makefile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CC = clang
2+
CFLAGS = -g -emit-llvm -frecord-command-line -O2
3+
4+
all: test.bc
5+
6+
test.bc: test.c
7+
$(CC) $(CFLAGS) -c $< -o $@
8+
9+
.PHONY: clean
10+
clean:
11+
rm -f test.bc

intTests/test1308/test.bc

6.22 KB
Binary file not shown.

intTests/test1308/test.c

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <stdint.h>
2+
#include <stdlib.h>
3+
4+
const size_t LEN = 42;
5+
6+
void zip_with_add(uint64_t c[LEN], const uint64_t a[LEN], const uint64_t b[LEN]) {
7+
for (size_t i = 0; i < LEN; i++) {
8+
c[i] = a[i] + b[i];
9+
}
10+
}

intTests/test1308/test.saw

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
enable_lax_pointer_ordering;
2+
3+
let alloc_init_readonly ty v = do {
4+
p <- llvm_alloc_readonly ty;
5+
llvm_points_to p v;
6+
return p;
7+
};
8+
9+
let ptr_to_fresh_readonly n ty = do {
10+
x <- llvm_fresh_var n ty;
11+
p <- alloc_init_readonly ty (llvm_term x);
12+
return (x, p);
13+
};
14+
15+
let LEN = 42;
16+
17+
let zip_with_add_spec = do {
18+
let array_ty = llvm_array LEN (llvm_int 64);
19+
c_ptr <- llvm_alloc array_ty;
20+
(a, a_ptr) <- ptr_to_fresh_readonly "a" array_ty;
21+
(b, b_ptr) <- ptr_to_fresh_readonly "b" array_ty;
22+
23+
llvm_execute_func [c_ptr, a_ptr, b_ptr];
24+
25+
llvm_points_to c_ptr (llvm_term {{ zipWith`{LEN} (+) a b }});
26+
};
27+
28+
mod <- llvm_load_module "test.bc";
29+
llvm_verify mod "zip_with_add" [] false zip_with_add_spec z3;

intTests/test1308/test.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set -e
2+
3+
$SAW test.saw

saw-remote-api/docs/SAW.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ Parameter fields
402402

403403

404404
``option``
405-
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``
405+
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``
406406

407407

408408

saw-remote-api/docs/old-Saw.rst

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ Setting Options
165165
- ``option``: The name of the option to set. This is one of:
166166

167167
* ``lax arithmetic``
168+
* ``lax pointer ordering``
168169
* ``SMT array memory model``
169170
* ``What4 hash consing``
170171

saw-remote-api/src/SAWServer.hs

+1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ initialState readFileFn =
218218
, rwProfilingFile = Nothing
219219
, rwCrucibleAssertThenAssume = False
220220
, rwLaxArith = False
221+
, rwLaxPointerOrdering = False
221222
, rwWhat4HashConsing = False
222223
, rwWhat4HashConsingX86 = False
223224
, rwStackBaseAlign = defaultStackBaseAlign

saw-remote-api/src/SAWServer/SetOption.hs

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ setOption opt =
3131
case opt of
3232
EnableLaxArithmetic enabled ->
3333
updateRW rw { rwLaxArith = enabled }
34+
EnableLaxPointerOrdering enabled ->
35+
updateRW rw { rwLaxPointerOrdering = enabled }
3436
EnableSMTArrayMemoryModel enabled -> undefined
3537
updateRW rw { rwSMTArrayMemoryModel = enabled }
3638
EnableWhat4HashConsing enabled -> undefined
@@ -39,13 +41,15 @@ setOption opt =
3941

4042
data SetOptionParams
4143
= EnableLaxArithmetic Bool
44+
| EnableLaxPointerOrdering Bool
4245
| EnableSMTArrayMemoryModel Bool
4346
| EnableWhat4HashConsing Bool
4447

4548
parseOption :: Object -> String -> Parser SetOptionParams
4649
parseOption o name =
4750
case name of
4851
"lax arithmetic" -> EnableLaxArithmetic <$> o .: "value"
52+
"lax pointer ordering" -> EnableLaxPointerOrdering <$> o .: "value"
4953
"SMT array memory model" -> EnableSMTArrayMemoryModel <$> o .: "value"
5054
"What4 hash consing" -> EnableWhat4HashConsing <$> o .: "value"
5155
_ -> empty
@@ -60,6 +64,7 @@ instance Doc.DescribedMethod SetOptionParams OK where
6064
[ ("option",
6165
Doc.Paragraph [Doc.Text "The option to set and its accompanying value (i.e., true or false); one of the following:"
6266
, Doc.Literal "lax arithmetic", Doc.Text ", "
67+
, Doc.Literal "lax pointer ordering", Doc.Text ", "
6368
, Doc.Literal "SMT array memory model", Doc.Text ", or "
6469
, Doc.Literal "What4 hash consing"
6570
])

src/SAWScript/Crucible/LLVM/Builtins.hs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,7 @@ setupLLVMCrucibleContext pathSat lm action =
13411341
smt_array_memory_model_enabled <- gets rwSMTArrayMemoryModel
13421342
crucible_assert_then_assume_enabled <- gets rwCrucibleAssertThenAssume
13431343
what4HashConsing <- gets rwWhat4HashConsing
1344+
laxPointerOrdering <- gets rwLaxPointerOrdering
13441345
Crucible.llvmPtrWidth ctx $ \wptr ->
13451346
Crucible.withPtrWidth wptr $
13461347
do let ?lc = ctx^.Crucible.llvmTypeCtx
@@ -1377,8 +1378,11 @@ setupLLVMCrucibleContext pathSat lm action =
13771378
crucible_assert_then_assume_enabled
13781379

13791380
let bindings = Crucible.fnBindingsFromList []
1381+
let memOpts = Crucible.defaultMemOptions
1382+
{ Crucible.laxPointerOrdering = laxPointerOrdering
1383+
}
13801384
let simctx = Crucible.initSimContext sym intrinsics halloc stdout
1381-
bindings (Crucible.llvmExtensionImpl Crucible.defaultMemOptions)
1385+
bindings (Crucible.llvmExtensionImpl memOpts)
13821386
Common.SAWCruciblePersonality
13831387
mem <- Crucible.populateConstGlobals sym (Crucible.globalInitMap mtrans)
13841388
=<< Crucible.initializeMemoryConstGlobals sym ctx llvm_mod

src/SAWScript/Interpreter.hs

+11
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ buildTopLevelEnv proxy opts =
475475
, rwCrucibleAssertThenAssume = False
476476
, rwProfilingFile = Nothing
477477
, rwLaxArith = False
478+
, rwLaxPointerOrdering = False
478479
, rwWhat4HashConsing = False
479480
, rwWhat4HashConsingX86 = False
480481
, rwPreservedRegs = []
@@ -543,6 +544,11 @@ enable_lax_arithmetic = do
543544
rw <- getTopLevelRW
544545
putTopLevelRW rw { rwLaxArith = True }
545546

547+
enable_lax_pointer_ordering :: TopLevel ()
548+
enable_lax_pointer_ordering = do
549+
rw <- getTopLevelRW
550+
putTopLevelRW rw { rwLaxPointerOrdering = True }
551+
546552
enable_what4_hash_consing :: TopLevel ()
547553
enable_what4_hash_consing = do
548554
rw <- getTopLevelRW
@@ -764,6 +770,11 @@ primitives = Map.fromList
764770
Current
765771
[ "Enable lax rules for arithmetic overflow in Crucible." ]
766772

773+
, prim "enable_lax_pointer_ordering" "TopLevel ()"
774+
(pureVal enable_lax_pointer_ordering)
775+
Current
776+
[ "Enable lax rules for pointer ordering comparisons in Crucible." ]
777+
767778
, prim "enable_what4_hash_consing" "TopLevel ()"
768779
(pureVal enable_what4_hash_consing)
769780
Current

src/SAWScript/Value.hs

+1
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ data TopLevelRW =
409409
, rwCrucibleAssertThenAssume :: Bool
410410
, rwProfilingFile :: Maybe FilePath
411411
, rwLaxArith :: Bool
412+
, rwLaxPointerOrdering :: Bool
412413

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

0 commit comments

Comments
 (0)