Skip to content

Commit 77b3bc6

Browse files
author
Brian Huffman
committed
Add integration test for llvm_points_to_at_type command.
1 parent 7d59fd6 commit 77b3bc6

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test.bc : test.c
2+
clang -c -emit-llvm -g -o test.bc test.c
2.48 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
void f (int *p) {
2+
p[2] = p[0];
3+
p[3] = p[1];
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// This is a test to demonstrate the use of the saw-script LLVM setup
2+
// declaration `llvm_points_to_at_type`.
3+
4+
bc <- llvm_load_module "test.bc";
5+
6+
let i32 = llvm_int 32;
7+
8+
// The function `f` copies the first half of an array into the second
9+
// half. So the full array needs to be allocated, but only the first
10+
// half needs to be initialized.
11+
12+
// This first example fails because the types don't match in the first
13+
// `llvm_points_to` declaration.
14+
fails (
15+
llvm_verify bc "f" [] false
16+
do {
17+
x <- llvm_fresh_var "x" (llvm_array 2 i32);
18+
p <- llvm_alloc (llvm_array 4 i32);
19+
llvm_points_to p (llvm_term x);
20+
llvm_execute_func [p];
21+
llvm_points_to p (llvm_term {{ x # x }});
22+
}
23+
z3);
24+
25+
// Changing `llvm_points_to` to `llvm_points_to_at_type` will work, as
26+
// long as the specified type matches the type of the rhs.
27+
f_ov <-
28+
llvm_verify bc "f" [] false
29+
do {
30+
x <- llvm_fresh_var "x" (llvm_array 2 i32);
31+
p <- llvm_alloc (llvm_array 4 i32);
32+
llvm_points_to_at_type p (llvm_array 2 i32) (llvm_term x);
33+
llvm_execute_func [p];
34+
llvm_points_to p (llvm_term {{ x # x }});
35+
}
36+
z3;
37+
38+
// But if the specified type does not match the rhs, the declaration
39+
// will fail with another type mismatch error.
40+
fails (
41+
llvm_verify bc "f" [] false
42+
do {
43+
x <- llvm_fresh_var "x" (llvm_array 2 i32);
44+
p <- llvm_alloc (llvm_array 4 i32);
45+
llvm_points_to_at_type p (llvm_array 3 i32) (llvm_term x);
46+
llvm_execute_func [p];
47+
llvm_points_to p (llvm_term {{ x # x }});
48+
}
49+
z3);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$SAW test.saw

0 commit comments

Comments
 (0)