Skip to content

Commit 20329f3

Browse files
author
Enrico Steffinlongo
committed
Fix issue with set and non-bit-sized value
1 parent c4a12ec commit 20329f3

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/goto-symex/shadow_memory.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,18 @@ void shadow_memoryt::symex_set_field(
156156
<< ". Insert a cast to the type that you want to access.";
157157
throw invalid_input_exceptiont(s.str());
158158
}
159+
160+
// Get the type of the shadow memory for this field
161+
const typet &sm_field_type = get_field_init_type(field_name, state);
162+
// Add a conditional cast to the shadow memory field type if `rhs` is not of
163+
// the expected type
164+
const exprt casted_rhs =
165+
typecast_exprt::conditional_cast(rhs, sm_field_type);
159166
// We replicate the rhs value on each byte of the value that we set.
160167
// This allows the get_field or/max semantics to operate correctly
161168
// on unions.
162169
const auto per_byte_rhs =
163-
expr_initializer(lhs.type(), expr.source_location(), ns, rhs);
170+
expr_initializer(lhs.type(), expr.source_location(), ns, casted_rhs);
164171
CHECK_RETURN(per_byte_rhs.has_value());
165172

166173
#ifdef DEBUG_SM

src/goto-symex/shadow_memory_util.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,13 @@ get_field_init_expr(const irep_idt &field_name, const goto_symex_statet &state)
257257
return field_type_it->second;
258258
}
259259

260+
const typet &
261+
get_field_init_type(const irep_idt &field_name, const goto_symex_statet &state)
262+
{
263+
const exprt &field_init_expr = get_field_init_expr(field_name, state);
264+
return field_init_expr.type();
265+
}
266+
260267
/// Given a pointer expression `address` checks if any expr in value_set is
261268
/// compatible
262269
bool contains_null_or_invalid(

src/goto-symex/shadow_memory_util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ std::vector<std::pair<exprt, exprt>> get_shadow_dereference_candidates(
110110
const typet &lhs_type,
111111
bool &exact_match);
112112

113+
// TODO: doxygen
114+
const typet &
115+
get_field_init_type(const irep_idt &field_name, const goto_symex_statet &state);
116+
113117
// TODO: doxygen
114118
bool contains_null_or_invalid(
115119
const std::vector<exprt> &value_set,

0 commit comments

Comments
 (0)