|
| 1 | +[CPROVER Manual TOC](../) |
| 2 | + |
| 3 | +## The CPROVER API Reference |
| 4 | + |
| 5 | +The following sections summarize the functions available to programs |
| 6 | +that are passed to the CPROVER tools. |
| 7 | + |
| 8 | +### Functions |
| 9 | + |
| 10 | +#### \_\_CPROVER\_assume, \_\_CPROVER\_assert, assert |
| 11 | + |
| 12 | +```C |
| 13 | +void __CPROVER_assume(_Bool assumption); |
| 14 | +void __CPROVER_assert(_Bool assertion, const char *description); |
| 15 | +void assert(_Bool assertion); |
| 16 | +``` |
| 17 | +
|
| 18 | +The function **\_\_CPROVER\_assume** adds an expression as a constraint |
| 19 | +to the program. If the expression evaluates to false, the execution |
| 20 | +aborts without failure. More detail on the use of assumptions is in the |
| 21 | +section on [Assumptions](../modeling/assumptions/). |
| 22 | +
|
| 23 | +#### \_\_CPROVER\_r_ok, \_\_CPROVER\_w_ok |
| 24 | +
|
| 25 | +```C |
| 26 | +void __CPROVER_r_ok(const void *, size_t size); |
| 27 | +void __CPROVER_w_ok(cosnt void *, size_t size); |
| 28 | +``` |
| 29 | + |
| 30 | +The function **\_\_CPROVER\_r_ok** returns true if reading the piece of |
| 31 | +memory starting at the given pointer with the given size is safe. |
| 32 | +**\_\_CPROVER\_w_ok** does the same with writing. |
| 33 | + |
| 34 | +#### \_\_CPROVER\_same\_object, \_\_CPROVER\_POINTER\_OBJECT, \_\_CPROVER\_POINTER\_OFFSET, \_\_CPROVER\_DYNAMIC\_OBJECT |
| 35 | + |
| 36 | +```C |
| 37 | +_Bool __CPROVER_same_object(const void *, const void *); |
| 38 | +__CPROVER_size_t __CPROVER_POINTER_OBJECT(const void *p); |
| 39 | +__CPROVER_ssize_t __CPROVER_POINTER_OFFSET(const void *p); |
| 40 | +_Bool __CPROVER_DYNAMIC_OBJECT(const void *p); |
| 41 | +``` |
| 42 | +
|
| 43 | +The function **\_\_CPROVER\_same\_object** returns true if the two |
| 44 | +pointers given as arguments point to the same object. The function |
| 45 | +**\_\_CPROVER\_POINTER\_OFFSET** returns the offset of the given pointer |
| 46 | +relative to the base address of the object. The function |
| 47 | +**\_\_CPROVER\_DYNAMIC\_OBJECT** returns true if the pointer passed as |
| 48 | +arguments points to a dynamically allocated object. |
| 49 | +
|
| 50 | +#### \_\_CPROVER\_is\_zero\_string, \_\_CPROVER\_zero\_string\_length, \_\_CPROVER\_buffer\_size |
| 51 | +
|
| 52 | +```C |
| 53 | +_Bool __CPROVER_is_zero_string(const void *); |
| 54 | +__CPROVER_size_t __CPROVER_zero_string_length(const void *); |
| 55 | +__CPROVER_size_t __CPROVER_buffer_size(const void *); |
| 56 | +``` |
| 57 | + |
| 58 | +#### \_\_CPROVER\_initialize |
| 59 | + |
| 60 | +```C |
| 61 | +void __CPROVER_initialize(void); |
| 62 | +``` |
| 63 | +
|
| 64 | +The function **\_\_CPROVER\_initialize** computes the initial state of |
| 65 | +the program. It is called prior to calling the main procedure of the |
| 66 | +program. |
| 67 | +
|
| 68 | +#### \_\_CPROVER\_input, \_\_CPROVER\_output |
| 69 | +
|
| 70 | +```C |
| 71 | +void __CPROVER_input(const char *id, ...); |
| 72 | +void __CPROVER_output(const char *id, ...); |
| 73 | +``` |
| 74 | + |
| 75 | +The functions **\_\_CPROVER\_input** and **\_\_CPROVER\_output** are |
| 76 | +used to report an input or output value. Note that they do not generate |
| 77 | +input or output values. The first argument is a string constant to |
| 78 | +distinguish multiple inputs and outputs (inputs are typically generated |
| 79 | +using nondeterminism, as described [here](../modeling/nondeterminism/)). The |
| 80 | +string constant is followed by an arbitrary number of values of |
| 81 | +arbitrary types. |
| 82 | + |
| 83 | +#### \_\_CPROVER\_cover |
| 84 | + |
| 85 | +```C |
| 86 | +void __CPROVER_cover(_Bool condition); |
| 87 | +``` |
| 88 | +
|
| 89 | +This statement defines a custom coverage criterion, for usage with the |
| 90 | +[test suite generation feature](cover.shtml). |
| 91 | +
|
| 92 | +#### \_\_CPROVER\_isnan, \_\_CPROVER\_isfinite, \_\_CPROVER\_isinf, \_\_CPROVER\_isnormal, \_\_CPROVER\_sign |
| 93 | +
|
| 94 | +```C |
| 95 | +_Bool __CPROVER_isnan(double f); |
| 96 | +_Bool __CPROVER_isfinite(double f); |
| 97 | +_Bool __CPROVER_isinf(double f); |
| 98 | +_Bool __CPROVER_isnormal(double f); |
| 99 | +_Bool __CPROVER_sign(double f); |
| 100 | +``` |
| 101 | + |
| 102 | +The function **\_\_CPROVER\_isnan** returns true if the double-precision |
| 103 | +floating-point number passed as argument is a |
| 104 | +[NaN](http://en.wikipedia.org/wiki/NaN). |
| 105 | + |
| 106 | +The function **\_\_CPROVER\_isfinite** returns true if the |
| 107 | +double-precision floating-point number passed as argument is a finite |
| 108 | +number. |
| 109 | + |
| 110 | +This function **\_\_CPROVER\_isinf** returns true if the |
| 111 | +double-precision floating-point number passed as argument is plus or |
| 112 | +minus infinity. |
| 113 | + |
| 114 | +The function **\_\_CPROVER\_isnormal** returns true if the |
| 115 | +double-precision floating-point number passed as argument is a normal |
| 116 | +number. |
| 117 | + |
| 118 | +This function **\_\_CPROVER\_sign** returns true if the double-precision |
| 119 | +floating-point number passed as argument is negative. |
| 120 | + |
| 121 | +#### \_\_CPROVER\_abs, \_\_CPROVER\_labs, \_\_CPROVER\_fabs, \_\_CPROVER\_fabsl, \_\_CPROVER\_fabsf |
| 122 | + |
| 123 | +```C |
| 124 | +int __CPROVER_abs(int x); |
| 125 | +long int __CPROVER_labs(long int x); |
| 126 | +double __CPROVER_fabs(double x); |
| 127 | +long double __CPROVER_fabsl(long double x); |
| 128 | +float __CPROVER_fabsf(float x); |
| 129 | +``` |
| 130 | +
|
| 131 | +These functions return the absolute value of the given argument. |
| 132 | +
|
| 133 | +#### \_\_CPROVER\_array\_equal, \_\_CPROVER\_array\_copy, \_\_CPROVER\_array\_set |
| 134 | +
|
| 135 | +```C |
| 136 | +_Bool __CPROVER_array_equal(const void array1[], const void array2[]); |
| 137 | +void __CPROVER_array_copy(const void dest[], const void src[]); |
| 138 | +void __CPROVER_array_set(const void dest[], value); |
| 139 | +``` |
| 140 | + |
| 141 | +The function **\_\_CPROVER\_array\_equal** returns true if the values |
| 142 | +stored in the given arrays are equal. The function |
| 143 | +**\_\_CPROVER\_array\_copy** copies the contents of the array **src** to |
| 144 | +the array **dest**. The function **\_\_CPROVER\_array\_set** initializes |
| 145 | +the array **dest** with the given value. |
| 146 | + |
| 147 | +#### Uninterpreted Functions |
| 148 | + |
| 149 | +Uninterpreted functions are documented \ref man_modelling-nondet "here". |
| 150 | + |
| 151 | +### Predefined Types and Symbols |
| 152 | + |
| 153 | +#### \_\_CPROVER\_bitvector |
| 154 | + |
| 155 | +```C |
| 156 | +__CPROVER_bitvector [ expression ] |
| 157 | +``` |
| 158 | + |
| 159 | +This type is only available in the C frontend. It is used to specify a |
| 160 | +bit vector with arbitrary but fixed size. The usual integer type |
| 161 | +modifiers **signed** and **unsigned** can be applied. The usual |
| 162 | +arithmetic promotions will be applied to operands of this type. |
| 163 | + |
| 164 | +#### \_\_CPROVER\_floatbv |
| 165 | + |
| 166 | +```C |
| 167 | +__CPROVER_floatbv [ expression ] [ expression ] |
| 168 | +``` |
| 169 | + |
| 170 | +This type is only available in the C frontend. It is used to specify an |
| 171 | +IEEE-754 floating point number with arbitrary but fixed size. The first |
| 172 | +parameter is the total size (in bits) of the number, and the second is |
| 173 | +the size (in bits) of the mantissa, or significand (not including the |
| 174 | +hidden bit, thus for single precision this should be 23). |
| 175 | + |
| 176 | +#### \_\_CPROVER\_fixedbv |
| 177 | + |
| 178 | +```C |
| 179 | +__CPROVER_fixedbv [ expression ] [ expression ] |
| 180 | +``` |
| 181 | + |
| 182 | +This type is only available in the C frontend. It is used to specify a |
| 183 | +fixed-point bit vector with arbitrary but fixed size. The first |
| 184 | +parameter is the total size (in bits) of the type, and the second is the |
| 185 | +number of bits after the radix point. |
| 186 | + |
| 187 | +#### \_\_CPROVER\_size\_t |
| 188 | + |
| 189 | +The type of sizeof expressions. |
| 190 | + |
| 191 | +#### \_\_CPROVER\_rounding\_mode |
| 192 | + |
| 193 | +```C |
| 194 | +extern int __CPROVER_rounding_mode; |
| 195 | +``` |
| 196 | + |
| 197 | +This variable contains the IEEE floating-point arithmetic rounding mode. |
| 198 | + |
| 199 | +#### \_\_CPROVER\_constant\_infinity\_uint |
| 200 | + |
| 201 | +This is a constant that models a large unsigned integer. |
| 202 | + |
| 203 | +#### \_\_CPROVER\_integer, \_\_CPROVER\_rational |
| 204 | + |
| 205 | +**\_\_CPROVER\_integer** is an unbounded, signed integer type. |
| 206 | +**\_\_CPROVER\_rational** is an unbounded, signed rational number type. |
| 207 | + |
| 208 | +#### \_\_CPROVER\_memory |
| 209 | + |
| 210 | +```C |
| 211 | +extern unsigned char __CPROVER_memory[]; |
| 212 | +``` |
| 213 | + |
| 214 | +This array models the contents of integer-addressed memory. |
| 215 | + |
| 216 | +#### \_\_CPROVER::unsignedbv<N> (C++ only) |
| 217 | + |
| 218 | +This type is the equivalent of **unsigned \_\_CPROVER\_bitvector\[N\]** |
| 219 | +in the C++ front-end. |
| 220 | + |
| 221 | +#### \_\_CPROVER::signedbv<N> (C++ only) |
| 222 | + |
| 223 | +This type is the equivalent of **signed \_\_CPROVER\_bitvector\[N\]** in |
| 224 | +the C++ front-end. |
| 225 | + |
| 226 | +#### \_\_CPROVER::fixedbv<N> (C++ only) |
| 227 | + |
| 228 | +This type is the equivalent of **\_\_CPROVER\_fixedbv\[N,m\]** in the |
| 229 | +C++ front-end. |
| 230 | + |
| 231 | +### Concurrency |
| 232 | + |
| 233 | +Asynchronous threads are created by preceding an instruction with a |
| 234 | +label with the prefix **\_\_CPROVER\_ASYNC\_**. |
| 235 | + |
0 commit comments