Skip to content

Commit b4a19b2

Browse files
authored
Merge pull request #7356 from remi-delmas-3000/dfcc-disable-library-checks
CONTRACTS: Disable checks on `cprover_contracts.c`
2 parents 764519a + 26fb550 commit b4a19b2

File tree

4 files changed

+30
-33
lines changed

4 files changed

+30
-33
lines changed

src/ansi-c/library/cprover_contracts.c

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,6 @@ __CPROVER_contracts_car_t
109109
__CPROVER_contracts_car_create(void *ptr, __CPROVER_size_t size)
110110
{
111111
__CPROVER_HIDE:;
112-
#pragma CPROVER check push
113-
#pragma CPROVER check disable "pointer"
114-
#pragma CPROVER check disable "pointer-primitive"
115-
#pragma CPROVER check disable "unsigned-overflow"
116-
#pragma CPROVER check disable "signed-overflow"
117-
#pragma CPROVER check disable "undefined-shift"
118-
#pragma CPROVER check disable "conversion"
119112
__CPROVER_assert(
120113
((ptr == 0) | __CPROVER_rw_ok(ptr, size)),
121114
"ptr NULL or writable up to size");
@@ -129,7 +122,6 @@ __CPROVER_HIDE:;
129122
"no offset bits overflow on CAR upper bound computation");
130123
return (__CPROVER_contracts_car_t){
131124
.is_writable = ptr != 0, .size = size, .lb = ptr, .ub = (char *)ptr + size};
132-
#pragma CPROVER check pop
133125
}
134126

135127
/// \brief Initialises a __CPROVER_contracts_car_set_ptr_t object
@@ -163,14 +155,6 @@ void __CPROVER_contracts_car_set_insert(
163155
__CPROVER_size_t size)
164156
{
165157
__CPROVER_HIDE:;
166-
#pragma CPROVER check push
167-
#pragma CPROVER check disable "pointer"
168-
#pragma CPROVER check disable "pointer-overflow"
169-
#pragma CPROVER check disable "pointer-primitive"
170-
#pragma CPROVER check disable "unsigned-overflow"
171-
#pragma CPROVER check disable "signed-overflow"
172-
#pragma CPROVER check disable "undefined-shift"
173-
#pragma CPROVER check disable "conversion"
174158
#ifdef DFCC_DEBUG
175159
__CPROVER_assert((set != 0) & (idx < set->max_elems), "no OOB access");
176160
#endif
@@ -188,7 +172,6 @@ __CPROVER_HIDE:;
188172
__CPROVER_contracts_car_t *elem = set->elems + idx;
189173
*elem = (__CPROVER_contracts_car_t){
190174
.is_writable = ptr != 0, .size = size, .lb = ptr, .ub = (char *)ptr + size};
191-
#pragma CPROVER check pop
192175
}
193176

194177
/// \brief Invalidates all cars in the \p set that point into the same object
@@ -1062,18 +1045,10 @@ __CPROVER_HIDE:;
10621045
void *ptr = *current;
10631046

10641047
// call free only iff the pointer is valid preconditions are met
1065-
#pragma CPROVER check push
1066-
#pragma CPROVER check disable "pointer"
1067-
#pragma CPROVER check disable "pointer-primitive"
1068-
#pragma CPROVER check disable "unsigned-overflow"
1069-
#pragma CPROVER check disable "signed-overflow"
1070-
#pragma CPROVER check disable "undefined-shift"
1071-
#pragma CPROVER check disable "conversion"
10721048
// skip checks on r_ok, dynamic_object and pointer_offset
10731049
__CPROVER_bool preconditions =
10741050
(ptr == 0) | (__CPROVER_r_ok(ptr, 0) & __CPROVER_DYNAMIC_OBJECT(ptr) &
10751051
(__CPROVER_POINTER_OFFSET(ptr) == 0));
1076-
#pragma CPROVER check pop
10771052
// If there is aliasing between the pointers in the freeable set,
10781053
// and we attempt to free again one of the already freed pointers,
10791054
// the r_ok condition above will fail, preventing us to deallocate
@@ -1204,13 +1179,6 @@ __CPROVER_HIDE:;
12041179
__CPROVER_assert(
12051180
write_set->linked_is_fresh, "set->linked_is_fresh is not NULL");
12061181
#endif
1207-
#pragma CPROVER check push
1208-
#pragma CPROVER check disable "pointer"
1209-
#pragma CPROVER check disable "pointer-primitive"
1210-
#pragma CPROVER check disable "pointer-overflow"
1211-
#pragma CPROVER check disable "signed-overflow"
1212-
#pragma CPROVER check disable "unsigned-overflow"
1213-
#pragma CPROVER check disable "conversion"
12141182
if(write_set->assume_requires_ctx)
12151183
{
12161184
#ifdef DFCC_DEBUG
@@ -1311,7 +1279,6 @@ __CPROVER_HIDE:;
13111279
__CPROVER_assume(0);
13121280
return 0; // to silence libcheck
13131281
}
1314-
#pragma CPROVER check pop
13151282
}
13161283

13171284
/// \brief Returns the start address of the conditional address range found at

src/goto-instrument/contracts/dynamic-frames/dfcc.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ void dfcct::link_model_and_load_dfcc_library()
248248
// load the dfcc library before instrumentation starts
249249
library.load(other_symbols);
250250

251+
// disable checks on all library functions
252+
library.disable_checks();
253+
251254
// add C prover lib again to fetch any dependencies of the dfcc functions
252255
link_to_library(
253256
goto_model, log.get_message_handler(), cprover_c_library_factory);

src/goto-instrument/contracts/dynamic-frames/dfcc_library.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,29 @@ dfcc_libraryt::get_havoc_hook(const irep_idt &function_id) const
209209
return {};
210210
}
211211

212+
static void add_checked_pragmas(source_locationt &sl)
213+
{
214+
sl.add_pragma("disable:pointer-check");
215+
sl.add_pragma("disable:pointer-primitive-check");
216+
sl.add_pragma("disable:pointer-overflow-check");
217+
sl.add_pragma("disable:signed-overflow-check");
218+
sl.add_pragma("disable:unsigned-overflow-check");
219+
sl.add_pragma("disable:conversion-check");
220+
sl.add_pragma("disable:undefined-shift-check");
221+
}
222+
223+
void dfcc_libraryt::disable_checks()
224+
{
225+
for(const auto &pair : dfcc_fun_to_name)
226+
{
227+
auto &function = goto_model.goto_functions.function_map[pair.second];
228+
for(auto &inst : function.body.instructions)
229+
{
230+
add_checked_pragmas(inst.source_location_nonconst());
231+
}
232+
}
233+
}
234+
212235
std::set<irep_idt> dfcc_libraryt::get_missing_funs()
213236
{
214237
std::set<irep_idt> missing;

src/goto-instrument/contracts/dynamic-frames/dfcc_library.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ class dfcc_libraryt
244244
/// Sets the given hide flag on all instructions of all library functions
245245
void set_hide(bool hide);
246246

247+
/// Adds "checked" pragmas to instructions of all library functions
248+
/// instructions. By default checks are not disabled.
249+
void disable_checks();
250+
247251
/// Returns true iff the given function_id is one of `__CPROVER_assignable`,
248252
/// `__CPROVER_object_whole`, `__CPROVER_object_from`,
249253
/// `__CPROVER_object_upto`, `__CPROVER_freeable`

0 commit comments

Comments
 (0)