Skip to content

Commit e5d050e

Browse files
Initialize shadow memory for string constants
or static variables.
1 parent 2df9107 commit e5d050e

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/goto-symex/symex_assign.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "symex_assign.h"
1313

14-
#include "expr_skeleton.h"
15-
#include "goto_symex_state.h"
1614
#include <util/byte_operators.h>
1715
#include <util/config.h>
1816
#include <util/expr_util.h>
1917
#include <util/pointer_expr.h>
2018
#include <util/range.h>
2119

20+
#include "arith_tools.h"
21+
#include "c_types.h"
22+
#include "expr_skeleton.h"
23+
#include "goto_symex_state.h"
2224
#include "symex_config.h"
2325

2426
// We can either use with_exprt or update_exprt when building expressions that
@@ -35,6 +37,28 @@ constexpr bool use_update()
3537
#endif
3638
}
3739

40+
/// Determine whether the RHS expression is a string constant initialization
41+
/// \param rhs The RHS expression
42+
/// \return True if the expression points to the first character of a string constant
43+
static bool is_string_constant_initialization(const exprt &rhs)
44+
{
45+
if(rhs.id() == ID_address_of)
46+
{
47+
const address_of_exprt &address_of = to_address_of_expr(rhs);
48+
if(address_of.object().id() == ID_index)
49+
{
50+
const index_exprt &index = to_index_expr(address_of.object());
51+
if(
52+
index.array().id() == ID_string_constant &&
53+
index.index() == from_integer(0, c_index_type()))
54+
{
55+
return true;
56+
}
57+
}
58+
}
59+
return false;
60+
}
61+
3862
void symex_assignt::assign_rec(
3963
const exprt &lhs,
4064
const expr_skeletont &full_lhs,
@@ -44,6 +68,18 @@ void symex_assignt::assign_rec(
4468
if(is_ssa_expr(lhs))
4569
{
4670
assign_symbol(to_ssa_expr(lhs), full_lhs, rhs, guard);
71+
72+
// Allocate shadow memory
73+
bool is_string_constant_init = is_string_constant_initialization(rhs);
74+
if(is_string_constant_init)
75+
{
76+
shadow_memory.symex_field_static_init_string_constant(
77+
state, to_ssa_expr(lhs), rhs);
78+
}
79+
else
80+
{
81+
shadow_memory.symex_field_static_init(state, to_ssa_expr(lhs));
82+
}
4783
}
4884
else if(lhs.id() == ID_index)
4985
assign_array<use_update()>(to_index_expr(lhs), full_lhs, rhs, guard);

0 commit comments

Comments
 (0)