Skip to content

Commit 72247ad

Browse files
Initialize shadow memory for string constants
or static variables.
1 parent 83f8587 commit 72247ad

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/goto-symex/symex_assign.cpp

Lines changed: 41 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,29 @@ 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
42+
/// 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+
3662
void symex_assignt::assign_rec(
3763
const exprt &lhs,
3864
const expr_skeletont &full_lhs,
@@ -42,6 +68,21 @@ void symex_assignt::assign_rec(
4268
if(is_ssa_expr(lhs))
4369
{
4470
assign_symbol(to_ssa_expr(lhs), full_lhs, rhs, guard);
71+
72+
// Allocate shadow memory
73+
if(shadow_memory.has_value())
74+
{
75+
bool is_string_constant_init = is_string_constant_initialization(rhs);
76+
if(is_string_constant_init)
77+
{
78+
shadow_memory->symex_field_static_init_string_constant(
79+
state, to_ssa_expr(lhs), rhs);
80+
}
81+
else
82+
{
83+
shadow_memory->symex_field_static_init(state, to_ssa_expr(lhs));
84+
}
85+
}
4586
}
4687
else if(lhs.id() == ID_index)
4788
assign_array<use_update()>(to_index_expr(lhs), full_lhs, rhs, guard);

0 commit comments

Comments
 (0)