Skip to content

Commit d536812

Browse files
author
kroening
committed
dynamic memory fixes
git-svn-id: svn+ssh://svn.cprover.org/srv/svn/cbmc/trunk@1050 6afb6bc1-c8e4-404c-8f48-9ae832c5b171
1 parent 2cfd2f3 commit d536812

File tree

5 files changed

+51
-23
lines changed

5 files changed

+51
-23
lines changed

src/cbmc/show_vcc.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ void bmct::show_vcc(std::ostream &out)
7171
std::string string_value;
7272
languages.from_expr(p_it->cond_expr, string_value);
7373
out << "{-" << count << "} " << string_value << std::endl;
74+
75+
#if 0
76+
languages.from_expr(p_it->guard_expr, string_value);
77+
out << "GUARD: " << string_value << std::endl;
78+
out << std::endl;
79+
#endif
80+
7481
count++;
7582
}
7683

src/goto-programs/dynamic_memory.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Author: Daniel Kroening, [email protected]
1616

1717
/*******************************************************************\
1818
19-
Function: valid_object
19+
Function: deallocated
2020
2121
Inputs:
2222
@@ -26,15 +26,15 @@ Function: valid_object
2626
2727
\*******************************************************************/
2828

29-
exprt valid_object(const namespacet &ns, const exprt &pointer)
29+
exprt deallocated(const namespacet &ns, const exprt &pointer)
3030
{
3131
// we check __CPROVER_deallocated!
3232
const symbolt &deallocated_symbol=ns.lookup(CPROVER_PREFIX "deallocated");
3333

3434
exprt same_object_expr(ID_same_object, bool_typet());
3535
same_object_expr.copy_to_operands(pointer, symbol_expr(deallocated_symbol));
3636

37-
return not_exprt(same_object_expr);
37+
return same_object_expr;
3838
}
3939

4040
/*******************************************************************\

src/goto-programs/dynamic_memory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include <namespace.h>
1313

14-
exprt valid_object(const namespacet &ns, const exprt &pointer);
14+
exprt deallocated(const namespacet &ns, const exprt &pointer);
1515
exprt dynamic_size(const namespacet &ns, const exprt &pointer);
1616
exprt pointer_object_has_type(const namespacet &ns, const exprt &pointer, const typet &type);
1717
exprt dynamic_object(const exprt &pointer);

src/goto-symex/builtin_functions.cpp

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,40 +114,61 @@ void basic_symext::symex_malloc(
114114
}
115115
}
116116
}
117-
117+
118118
if(object_type.is_nil())
119119
object_type=array_typet(uchar_type(), tmp_size);
120-
121-
// must use renamed size in the above,
122-
// or it can change!
120+
121+
// we introduce a fresh symbol for the size
122+
// to prevent any issues of the size getting ever changed
123+
124+
if(object_type.id()==ID_array &&
125+
!to_array_type(object_type).size().is_constant())
126+
{
127+
exprt &size=to_array_type(object_type).size();
128+
129+
symbolt size_symbol;
130+
131+
size_symbol.base_name="dynamic_object_size"+i2string(dynamic_counter);
132+
size_symbol.name="symex_dynamic::"+id2string(size_symbol.base_name);
133+
size_symbol.lvalue=true;
134+
size_symbol.type=tmp_size.type();
135+
size_symbol.mode=ID_C;
136+
137+
new_context.add(size_symbol);
138+
139+
guardt guard;
140+
symex_assign_rec(state, symbol_expr(size_symbol), nil_exprt(), size, guard, VISIBLE);
141+
142+
size=symbol_expr(size_symbol);
143+
}
123144
}
124145

125146
// value
126-
symbolt symbol;
147+
symbolt value_symbol;
127148

128-
symbol.base_name="dynamic_object"+i2string(dynamic_counter);
129-
symbol.name="symex_dynamic::"+id2string(symbol.base_name);
130-
symbol.lvalue=true;
131-
symbol.type=object_type;
132-
symbol.type.set("#dynamic", true);
133-
symbol.mode=ID_C;
149+
value_symbol.base_name="dynamic_object"+i2string(dynamic_counter);
150+
value_symbol.name="symex_dynamic::"+id2string(value_symbol.base_name);
151+
value_symbol.lvalue=true;
152+
value_symbol.type=object_type;
153+
value_symbol.type.set("#dynamic", true);
154+
value_symbol.mode=ID_C;
134155

135-
new_context.add(symbol);
156+
new_context.add(value_symbol);
136157

137158
address_of_exprt rhs;
138159

139160
if(object_type.id()==ID_array)
140161
{
141-
rhs.type()=pointer_typet(symbol.type.subtype());
142-
index_exprt index_expr(symbol.type.subtype());
143-
index_expr.array()=symbol_expr(symbol);
162+
rhs.type()=pointer_typet(value_symbol.type.subtype());
163+
index_exprt index_expr(value_symbol.type.subtype());
164+
index_expr.array()=symbol_expr(value_symbol);
144165
index_expr.index()=gen_zero(index_type());
145166
rhs.op0()=index_expr;
146167
}
147168
else
148169
{
149-
rhs.op0()=symbol_expr(symbol);
150-
rhs.type()=pointer_typet(symbol.type);
170+
rhs.op0()=symbol_expr(value_symbol);
171+
rhs.type()=pointer_typet(value_symbol.type);
151172
}
152173

153174
if(rhs.type()!=lhs.type())

src/goto-symex/goto_symex_state.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,8 @@ void goto_symex_statet::rename_address(
474474
const namespacet &ns,
475475
levelt level)
476476
{
477-
// do full renaming for type
478-
rename(expr.type(), ns, level);
477+
// only do L1!
478+
rename(expr.type(), ns, L1);
479479

480480
if(expr.id()==ID_symbol)
481481
{

0 commit comments

Comments
 (0)