@@ -131,22 +131,77 @@ The goto-instrument program supports these checks:
131
131
| `--error-label label` | check that given label is unreachable |
132
132
133
133
As all of these checks apply across the entire input program, we may wish to
134
- disable them for selected statements in the program. For example, unsigned
135
- overflows can be expected and acceptable in certain instructions even when
136
- elsewhere we do not expect them. As of version 5.12, CBMC supports selectively
137
- disabling automatically generated properties. To disable property generation,
138
- use `#pragma CPROVER check disable "<name_of_check>"`, which remains in effect
139
- until a `#pragma CPROVER check pop` (to re-enable all properties
140
- disabled before or since the last `#pragma CPROVER check push`) is provided.
134
+ disable or enable them for selected statements in the program.
135
+ For example, unsigned overflows can be expected and acceptable in certain
136
+ instructions even when elsewhere we do not expect them.
137
+ As of version 5.12, CBMC supports selectively disabling or enabling
138
+ automatically generated properties using pragmas.
139
+
140
+
141
+ CPROVER pragmas are handled using a stack:
142
+ - `#pragma CPROVER check push` pushes a new level on the pragma stack
143
+ - `#pragma CPROVER check disable "<name_of_check>"` adds a disable pragma
144
+ at the top of the stack
145
+ - `#pragma CPROVER check enable "<name_of_check>"` adds a enable pragma
146
+ at the top of the stack
147
+ - an `enable` or `disable` pragma for a given check present at the top level
148
+ of the stack shadows other pragmas for the same in lower levels of the stack
149
+ - adding both `enable` and `disable` pragmas for a same check in a same level
150
+ of the stack creates a PARSING_ERROR.
151
+ - `#pragma CPROVER check pop` pops a level in the stack and restores the state
152
+ of pragmas at the sub level
153
+
141
154
For example, for unsigned overflow checks, use
155
+
142
156
```
143
157
unsigned foo(unsigned x)
144
158
{
145
159
#pragma CPROVER check push
160
+ #pragma CPROVER check enable "unsigned-overflow"
161
+ // unsigned overflow check apply here
162
+ x = x + 1;
163
+ #pragma CPROVER check pop
164
+ // unsigned overflow checks do not apply here
165
+ x = x + 2;
166
+ ```
167
+
168
+ ```
169
+ unsigned foo(unsigned x)
170
+ {
171
+ #pragma CPROVER check push
172
+ #pragma CPROVER check enable "unsigned-overflow"
173
+ #pragma CPROVER check enable "signed-overflow"
174
+ // unsigned and signed overflow check apply here
175
+ x = x + 1;
176
+ #pragma CPROVER check push
146
177
#pragma CPROVER check disable "unsigned-overflow"
147
- x = x + 1; // immediately follows the pragma, no unsigned overflow check here
178
+ // only signed overflow check apply here
179
+ x = x + 2;
180
+ #pragma CPROVER check pop
181
+ // unsigned and signed overflow check apply here
182
+ x = x + 3;
183
+ #pragma CPROVER check pop
184
+ // unsigned overflow checks do not apply here
185
+ x = x + 2;
186
+ ```
187
+
188
+ ```
189
+ unsigned foo(unsigned x)
190
+ {
191
+ #pragma CPROVER check push
192
+ #pragma CPROVER check enable "unsigned-overflow"
193
+ #pragma CPROVER check enable "signed-overflow"
194
+ // unsigned and signed overflow check apply here
195
+ x = x + 1;
196
+ #pragma CPROVER check push
197
+ #pragma CPROVER check disable "unsigned-overflow"
198
+ #pragma CPROVER check enable "unsigned-overflow"
199
+ // PARSING_ERROR Found enable and disable pragmas for unsigned-overflow-check
200
+ x = x + 2;
201
+ #pragma CPROVER check pop
202
+ x = x + 3;
148
203
#pragma CPROVER check pop
149
- x = x + 2; // unsigned overflow checks are generated here
204
+ x = x + 2;
150
205
```
151
206
152
207
#### Flag --nan-check limitations
0 commit comments