Skip to content

Commit f11feee

Browse files
Initialize shadow memory for string constants
or static variables.
1 parent 0976572 commit f11feee

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/goto-symex/symex_assign.cpp

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

1212
#include "symex_assign.h"
1313

14+
#include <util/arith_tools.h>
1415
#include <util/byte_operators.h>
1516
#include <util/expr_util.h>
1617
#include <util/pointer_expr.h>
@@ -34,6 +35,28 @@ constexpr bool use_update()
3435
#endif
3536
}
3637

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

0 commit comments

Comments
 (0)