Skip to content

Commit 092d352

Browse files
Initialize shadow memory for string constants
or static variables.
1 parent f00b1d5 commit 092d352

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/goto-symex/symex_assign.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "symex_assign.h"
1313

14+
#include <util/arith_tools.h>
1415
#include <util/byte_operators.h>
16+
#include <util/c_types.h>
1517
#include <util/expr_util.h>
18+
#include <util/pointer_expr.h>
1619
#include <util/range.h>
1720

1821
#include "expr_skeleton.h"
@@ -33,6 +36,28 @@ constexpr bool use_update()
3336
#endif
3437
}
3538

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

0 commit comments

Comments
 (0)