cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
dfcc_pointer_in_range.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Dynamic frame condition checking for function contracts
4
5
Author: Remi Delmas, delmasrd@amazon.com
6
Date: August 2022
7
8
\*******************************************************************/
9
10
#include "
dfcc_pointer_in_range.h
"
11
12
#include <
util/cprover_prefix.h
>
13
#include <
util/pointer_expr.h
>
14
#include <
util/prefix.h
>
15
#include <
util/replace_expr.h
>
16
#include <
util/std_code.h
>
17
#include <
util/suffix.h
>
18
#include <
util/symbol.h
>
19
20
#include "
dfcc_cfg_info.h
"
21
#include "
dfcc_library.h
"
22
23
dfcc_pointer_in_ranget::dfcc_pointer_in_ranget
(
24
dfcc_libraryt
&
library
,
25
message_handlert
&
message_handler
)
26
:
library
(
library
),
message_handler
(
message_handler
),
log
(
message_handler
)
27
{
28
}
29
30
void
dfcc_pointer_in_ranget::rewrite_calls
(
31
goto_programt
&program,
32
dfcc_cfg_infot
cfg_info)
33
{
34
rewrite_calls
(
35
program,
36
program.
instructions
.begin(),
37
program.
instructions
.end(),
38
cfg_info);
39
}
40
41
void
dfcc_pointer_in_ranget::rewrite_calls
(
42
goto_programt
&program,
43
goto_programt::targett
first_instruction,
44
const
goto_programt::targett
&last_instruction,
45
dfcc_cfg_infot
cfg_info)
46
{
47
auto
&target = first_instruction;
48
while
(target != last_instruction)
49
{
50
if
(target->is_function_call())
51
{
52
const
auto
&function = target->call_function();
53
54
if
(function.id() == ID_symbol)
55
{
56
const
irep_idt
&fun_name =
to_symbol_expr
(function).
get_identifier
();
57
58
if
(
has_prefix
(
59
id2string
(fun_name),
CPROVER_PREFIX
"pointer_in_range_dfcc"
))
60
{
61
// add address on second operand
62
target->call_arguments()[1] =
63
address_of_exprt
(target->call_arguments()[1]);
64
65
// fix the function name.
66
to_symbol_expr
(target->call_function())
67
.
set_identifier
(
68
library
.dfcc_fun_symbol[
dfcc_funt::POINTER_IN_RANGE_DFCC
].name);
69
70
// pass the may_fail flag
71
// pass the may_fail flag
72
if
(function.source_location().get_bool(
"no_fail"
))
73
target->call_arguments().push_back(
false_exprt
());
74
else
75
target->call_arguments().push_back(
true_exprt
());
76
77
// pass the write_set
78
target->call_arguments().push_back(cfg_info.
get_write_set
(target));
79
}
80
}
81
}
82
target++;
83
}
84
}
address_of_exprt
Operator to return the address of an object.
Definition
pointer_expr.h:540
dfcc_cfg_infot
Computes natural loops, enforces normal form conditions, computes the nesting graph,...
Definition
dfcc_cfg_info.h:243
dfcc_cfg_infot::get_write_set
const exprt & get_write_set(goto_programt::const_targett target) const
Returns the write set variable to use for the given instruction Returns the write set for the loop,...
Definition
dfcc_cfg_info.cpp:662
dfcc_libraryt
Class interface to library types and functions defined in cprover_contracts.c.
Definition
dfcc_library.h:163
dfcc_pointer_in_ranget::message_handler
message_handlert & message_handler
Definition
dfcc_pointer_in_range.h:55
dfcc_pointer_in_ranget::rewrite_calls
void rewrite_calls(goto_programt &program, dfcc_cfg_infot cfg_info)
Rewrites calls to pointer_in_range predicates into calls to the library implementation in the given p...
Definition
dfcc_pointer_in_range.cpp:30
dfcc_pointer_in_ranget::log
messaget log
Definition
dfcc_pointer_in_range.h:56
dfcc_pointer_in_ranget::dfcc_pointer_in_ranget
dfcc_pointer_in_ranget(dfcc_libraryt &library, message_handlert &message_handler)
Definition
dfcc_pointer_in_range.cpp:23
dfcc_pointer_in_ranget::library
dfcc_libraryt & library
Definition
dfcc_pointer_in_range.h:54
false_exprt
The Boolean constant false.
Definition
std_expr.h:3125
goto_programt
A generic container class for the GOTO intermediate representation of one function.
Definition
goto_program.h:72
goto_programt::instructions
instructionst instructions
The list of instructions in the goto program.
Definition
goto_program.h:621
goto_programt::targett
instructionst::iterator targett
Definition
goto_program.h:613
message_handlert
Definition
message.h:27
symbol_exprt::set_identifier
void set_identifier(const irep_idt &identifier)
Definition
std_expr.h:156
symbol_exprt::get_identifier
const irep_idt & get_identifier() const
Definition
std_expr.h:161
true_exprt
The Boolean constant true.
Definition
std_expr.h:3116
has_prefix
bool has_prefix(const std::string &s, const std::string &prefix)
Definition
converter.cpp:13
cprover_prefix.h
CPROVER_PREFIX
#define CPROVER_PREFIX
Definition
cprover_prefix.h:14
dfcc_cfg_info.h
Class that computes CFG information about the loop structure of a GOTO function for the purpose of dy...
dfcc_library.h
Dynamic frame condition checking library loading.
dfcc_funt::POINTER_IN_RANGE_DFCC
@ POINTER_IN_RANGE_DFCC
Definition
dfcc_library.h:141
dfcc_pointer_in_range.h
Instruments occurrences of pointer_in_range predicates in programs encoding requires and ensures clau...
id2string
const std::string & id2string(const irep_idt &d)
Definition
irep.h:44
pointer_expr.h
API to expression classes for Pointers.
prefix.h
replace_expr.h
std_code.h
to_symbol_expr
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
Definition
std_expr.h:211
suffix.h
symbol.h
Symbol table entry.
irep_idt
dstringt irep_idt
Definition
verification_result.h:16
goto-instrument
contracts
dynamic-frames
dfcc_pointer_in_range.cpp
Generated by
1.17.0