Skip to content

Commit 7cf33ff

Browse files
author
Daniel Kroening
authored
Merge pull request #3298 from diffblue/manual-fixes
Online user manual fixes
2 parents 6747d24 + 37c2a68 commit 7cf33ff

File tree

7 files changed

+425
-37
lines changed

7 files changed

+425
-37
lines changed

doc/cprover-manual/binsearch.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
int binsearch(int x)
2+
{
3+
int a[16];
4+
signed low = 0, high = 16;
5+
6+
while(low < high)
7+
{
8+
signed middle = low + ((high - low) >> 1);
9+
10+
if(a[middle] < x)
11+
high = middle;
12+
else if(a[middle] > x)
13+
low = middle + 1;
14+
else // a[middle]==x
15+
return middle;
16+
}
17+
18+
return -1;
19+
}

doc/cprover-manual/cbmc-tutorial.md

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ definitions from the various .c files, just like a linker. But instead
4242
of producing a binary for execution, CBMC performs symbolic simulation
4343
on the program.
4444

45-
As an example, consider the following simple program, named file1.c:
45+
As an example, consider the following simple program, named
46+
[file1.c](https://raw.githubusercontent.com/diffblue/cbmc/develop/doc/cprover-manual/file1.c):
4647

4748
```C
48-
int puts(const char *s) { }
49+
int puts(const char *s)
50+
{
51+
}
4952

50-
int main(int argc, char **argv) {
53+
int main(int argc, char **argv)
54+
{
5155
puts(argv[2]);
5256
}
5357
```
@@ -63,7 +67,7 @@ cbmc file1.c --show-properties --bounds-check --pointer-check
6367
The two options `--bounds-check` and `--pointer-check` instruct CBMC to
6468
look for errors related to pointers and array bounds. CBMC will print
6569
the list of properties it checks. Note that it lists, among others, a
66-
property labelled with "object bounds in argv" together with the location
70+
property labelled with "pointer outside object bounds in argv" together with the location
6771
of the faulty array access. As you can see, CBMC largely determines the
6872
property it needs to check itself. This is realized by means of a
6973
preliminary static analysis, which relies on computing a fixed point on
@@ -106,7 +110,7 @@ property for the object bounds of `argv` does not hold, and will thus
106110
print a line as follows:
107111
108112
```plaintext
109-
[main.pointer_dereference.6] dereference failure: object bounds in argv[(signed long int)2]: FAILURE
113+
[main.pointer_dereference.6] dereference failure: pointer outside object bounds in argv[(signed long int)2]: FAILURE
110114
```
111115

112116
### Counterexample Traces
@@ -160,20 +164,23 @@ When running the previous example, you will have noted that CBMC unwinds
160164
the `for` loop in the program. As CBMC performs Bounded Model Checking,
161165
all loops have to have a finite upper run-time bound in order to
162166
guarantee that all bugs are found. CBMC can optionally check that enough
163-
unwinding is performed. As an example, consider the program binsearch.c:
167+
unwinding is performed. As an example, consider the program
168+
[binsearch.c](https://raw.githubusercontent.com/diffblue/cbmc/develop/doc/cprover-manual/binsearch1.c):
164169

165170
```C
166-
int binsearch(int x) {
171+
int binsearch(int x)
172+
{
167173
int a[16];
168-
signed low=0, high=16;
174+
signed low = 0, high = 16;
169175

170-
while(low<high) {
171-
signed middle=low+((high-low)>>1);
176+
while(low < high)
177+
{
178+
signed middle = low + ((high - low) >> 1);
172179

173-
if(a[middle]<x)
174-
high=middle;
175-
else if(a[middle]>x)
176-
low=middle+1;
180+
if(a[middle] < x)
181+
high = middle;
182+
else if(a[middle] > x)
183+
low = middle + 1;
177184
else // a[middle]==x
178185
return middle;
179186
}
@@ -202,40 +209,48 @@ obtained with the option `--property`.
202209

203210
### Unbounded Loops
204211

205-
CBMC can also be used for programs with unbounded loops. In this case,
206-
CBMC is used for bug hunting only; CBMC does not attempt to find all
207-
bugs. The following program (lock-example.c) is an example of a program
208-
with a user-specified property:
212+
CBMC can also be used for programs with unbounded loops. In this case, CBMC
213+
is used for bug hunting only; CBMC does not attempt to find all bugs. The
214+
following program
215+
([lock-example.c](https://raw.githubusercontent.com/diffblue/cbmc/develop/doc/cprover-manual/lock-example.c))
216+
is an example of a program with a user-specified property:
209217

210218
```C
211219
_Bool nondet_bool();
212220
_Bool LOCK = 0;
213221

214-
_Bool lock() {
215-
if(nondet_bool()) {
222+
_Bool lock()
223+
{
224+
if(nondet_bool())
225+
{
216226
assert(!LOCK);
217-
LOCK=1;
218-
return 1; }
227+
LOCK = 1;
228+
return 1;
229+
}
219230

220231
return 0;
221232
}
222233

223-
void unlock() {
234+
void unlock()
235+
{
224236
assert(LOCK);
225-
LOCK=0;
237+
LOCK = 0;
226238
}
227239

228-
int main() {
240+
int main()
241+
{
229242
unsigned got_lock = 0;
230243
int times;
231244

232-
while(times > 0) {
233-
if(lock()) {
245+
while(times > 0)
246+
{
247+
if(lock())
248+
{
234249
got_lock++;
235250
/* critical section */
236251
}
237252

238-
if(got_lock!=0)
253+
if(got_lock != 0)
239254
unlock();
240255

241256
got_lock--;

doc/cprover-manual/file1.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
int puts(const char *s)
2+
{
3+
}
4+
5+
int main(int argc, char **argv)
6+
{
7+
puts(argv[2]);
8+
}

doc/cprover-manual/index.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@
1212

1313
## 4. [Test Suite Generation](test-suite/)
1414

15-
## 5. Modeling
15+
## 5. [Program Properties](properties/)
16+
17+
## 6. Modeling
1618

1719
[Nondeterminism](modeling/nondeterminism/),
1820
[Assumptions](modeling/assumptions/),
1921
[Pointers](modeling/pointers/),
2022
[Floating Point](modeling/floating-point/)
2123

22-
## 6. Build Systems
24+
## 7. Build Systems
2325

2426
[Integration into Build Systems with goto-cc](goto-cc/),
2527
[Integration with Visual Studio builds](visual-studio/)
2628

27-
## 7. [The CPROVER API Reference](api/)
29+
## 8. [The CPROVER API Reference](api/)
2830

doc/cprover-manual/installation.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ and an a set of header files.
1414

1515
2. **Windows:** The Windows version of CBMC requires the preprocessor
1616
`cl.exe`, which is part of Microsoft Visual Studio. We recommend the
17-
free [Visual Studio Community
18-
2013](http://www.visualstudio.com/en-us/products/visual-studio-community-vs).
17+
free [Visual Studio Community](http://www.visualstudio.com/en-us/products/visual-studio-community-vs).
1918

2019
3. **MacOS:** Install the [XCode Command Line
2120
Utilities](http://developer.apple.com/technologies/xcode.html) prior
@@ -27,10 +26,11 @@ and the directories that contain the header files. You must run CBMC
2726
from within the *Visual Studio Command Prompt*.
2827

2928
Note that the distribution files for the [Eclipse
30-
plugin](installation-plugin.shtml) include the CBMC executable.
31-
Therefore, if you intend to run CBMC exclusively within Eclipse, you can
32-
skip the installation of the CBMC executable. However, you still have to
33-
install the compiler environment as described above.
29+
plugin](http://www.cprover.org/eclipse-plugin/)
30+
include the CBMC executable. Therefore, if you intend to run CBMC
31+
exclusively within Eclipse, you can skip the installation of the CBMC
32+
executable. However, you still have to install the compiler environment as
33+
described above.
3434

3535
### Installing the CBMC Binaries
3636

doc/cprover-manual/lock-example.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
_Bool nondet_bool();
2+
_Bool LOCK = 0;
3+
4+
_Bool lock()
5+
{
6+
if(nondet_bool())
7+
{
8+
assert(!LOCK);
9+
LOCK = 1;
10+
return 1;
11+
}
12+
13+
return 0;
14+
}
15+
16+
void unlock()
17+
{
18+
assert(LOCK);
19+
LOCK = 0;
20+
}
21+
22+
int main()
23+
{
24+
unsigned got_lock = 0;
25+
int times;
26+
27+
while(times > 0)
28+
{
29+
if(lock())
30+
{
31+
got_lock++;
32+
/* critical section */
33+
}
34+
35+
if(got_lock != 0)
36+
unlock();
37+
38+
got_lock--;
39+
times--;
40+
}
41+
}

0 commit comments

Comments
 (0)