Skip to content

Commit

Permalink
Relax disjoint check for globals and fresh pointers. (#1858)
Browse files Browse the repository at this point in the history
* Relax disjoint check for globals and fresh pointers.

* Add test.

* Address comments.
  • Loading branch information
andreistefanescu committed Apr 19, 2023
1 parent a14d9a0 commit fad48d8
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 2 deletions.
11 changes: 11 additions & 0 deletions intTests/test_llvm_global_fresh_pointer/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CLANG ?= clang
CFLAGS = -g -frecord-command-line

all: test.bc

test.bc: test.c
$(CLANG) -c -emit-llvm $(CFLAGS) $< -o $@

clean:
rm -f test.bc

Binary file added intTests/test_llvm_global_fresh_pointer/test.bc
Binary file not shown.
8 changes: 8 additions & 0 deletions intTests/test_llvm_global_fresh_pointer/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
int glb;

void foo(const int *x) {}

void bar(const int *x) {
foo(x);
}

30 changes: 30 additions & 0 deletions intTests/test_llvm_global_fresh_pointer/test.saw
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
enable_experimental;

m <- llvm_load_module "test.bc";

// test the fact that glb and x_ptr are allowed to alias each other.
let foo_spec = do {
llvm_alloc_global "glb";
x_ptr <- llvm_fresh_pointer (llvm_int 32);

llvm_execute_func [x_ptr];
};

foo_ov <- llvm_verify m "foo"
[]
false
foo_spec
(do {
print_goal;
w4_unint_z3 [];
});

llvm_verify m "bar"
[foo_ov]
false
foo_spec
(do {
print_goal;
w4_unint_z3 [];
});

4 changes: 4 additions & 0 deletions intTests/test_llvm_global_fresh_pointer/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set -e

$SAW test.saw

7 changes: 5 additions & 2 deletions src/SAWScript/Crucible/LLVM/Override.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,8 +1044,11 @@ enforceDisjointAllocGlobal ::
(LLVMAllocGlobal arch, LLVMPtr (Crucible.ArchWidth arch)) ->
OverrideMatcher (LLVM arch) md ()
enforceDisjointAllocGlobal sym loc
(LLVMAllocSpec _pmut _pty _palign psz pMd _pfresh _p_sym_init, p)
(LLVMAllocGlobal qloc (L.Symbol qname), q) =
(LLVMAllocSpec _pmut _pty _palign psz pMd pfresh _p_sym_init, p)
(LLVMAllocGlobal qloc (L.Symbol qname), q)
| pfresh =
pure () -- Fresh pointers need not be disjoint
| otherwise =
do let Crucible.LLVMPointer pblk _ = p
let Crucible.LLVMPointer qblk _ = q
c <- liftIO $ W4.notPred sym =<< W4.natEq sym pblk qblk
Expand Down

0 comments on commit fad48d8

Please sign in to comment.