Skip to content

Commit 8fd4926

Browse files
author
Remi Delmas
committed
Documentation update
1 parent ecd24a9 commit 8fd4926

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

doc/cprover-manual/properties.md

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,40 +134,64 @@ As all of these checks apply across the entire input program, we may wish to
134134
disable them for selected statements in the program. For example, unsigned
135135
overflows can be expected and acceptable in certain instructions even when
136136
elsewhere we do not expect them. As of version 5.12, CBMC supports selectively
137-
disabling or enabling automatically generated properties.
137+
disabling or enabling automatically generated properties using pragmas.
138138
139-
To disable property generation,
140-
use `#pragma CPROVER check disable "<name_of_check>"`, which remains in effect
141-
until a `#pragma CPROVER check pop` (to re-enable all properties
142-
disabled or enabled before or since the last `#pragma CPROVER check push`) is provided.
139+
140+
CPROVER pragmas are handled using a stack:
141+
- `#pragma CPROVER check push` pushes a new level on the pragma stack
142+
- `#pragma CPROVER check disable "<name_of_check>"` adds a disable pragma at the top of the stack
143+
- `#pragma CPROVER check enable "<name_of_check>"` adds a enable pragma at the top of the stack
144+
- an `enable` or `disable` pragma for a given check present at the top level of the stack shadows other pragmas for the same in lower levels of the stack
145+
- adding both `enable` and `disable` pragmas for a same check in a same level of the stack creates a warning, the most recent pragma takes precedence
146+
- `#pragma CPROVER check pop` pops a level in the stack and restores the state of pragmas at the sub level
143147
144148
For example, for unsigned overflow checks, use
149+
145150
```
146151
unsigned foo(unsigned x)
147152
{
148153
#pragma CPROVER check push
149-
#pragma CPROVER check disable "unsigned-overflow"
150-
x = x + 1; // immediately follows the pragma, no unsigned overflow check here
154+
#pragma CPROVER check enable "unsigned-overflow"
155+
x = x + 1; // immediately follows the pragma, unsigned overflow check apply here
151156
#pragma CPROVER check pop
152-
x = x + 2; // unsigned overflow checks are generated here
157+
x = x + 2; // unsigned overflow checks do not apply here
153158
```
154159
155-
To enable property generation,
156-
use `#pragma CPROVER check enable "<name_of_check>"`, which remains in effect
157-
until a `#pragma CPROVER check pop` (to re-enable all properties
158-
disabled or enabled before or since the last `#pragma CPROVER check push`) is provided.
160+
```
161+
unsigned foo(unsigned x)
162+
{
163+
#pragma CPROVER check push
164+
#pragma CPROVER check enable "unsigned-overflow"
165+
#pragma CPROVER check enable "signed-overflow"
166+
x = x + 1; // unsigned and signed overflow check apply here
167+
#pragma CPROVER check push
168+
#pragma CPROVER check disable "unsigned-overflow"
169+
x = x + 2; // only signed overflow check apply here
170+
#pragma CPROVER check pop
171+
x = x + 3; // unsigned and signed overflow check apply here
172+
#pragma CPROVER check pop
173+
x = x + 2; // unsigned overflow checks do not apply here
174+
```
159175
160-
For example, for unsigned overflow checks, use
161176
```
162177
unsigned foo(unsigned x)
163178
{
164179
#pragma CPROVER check push
165180
#pragma CPROVER check enable "unsigned-overflow"
166-
x = x + 1; // immediately follows the pragma, unsigned overflow check are generated here
181+
#pragma CPROVER check enable "signed-overflow"
182+
x = x + 1; // unsigned and signed overflow check apply here
183+
#pragma CPROVER check push
184+
#pragma CPROVER check disable "unsigned-overflow"
185+
#pragma CPROVER check enable "unsigned-overflow"
186+
// warning: both enable and disable for unsigned-overflow (last one takes precedence)
187+
x = x + 2; // unsigned and signed overflow check apply here
167188
#pragma CPROVER check pop
168-
x = x + 2; // unsigned overflow checks are not generated here
189+
x = x + 3; // unsigned and signed overflow check apply here
190+
#pragma CPROVER check pop
191+
x = x + 2; // unsigned overflow checks do not apply here
169192
```
170193
194+
171195
#### Flag --nan-check limitations
172196
173197
Please note that `--nan-check` flag is adding not-a-number checks only for

0 commit comments

Comments
 (0)