Skip to content

Commit 1026142

Browse files
author
Enrico Steffinlongo
committed
Fix issue with set and non-bit-sized value
1 parent f1ba6fd commit 1026142

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
@@ -258,6 +258,13 @@ get_field_init_expr(const irep_idt &field_name, const goto_symex_statet &state)
258258
return field_type_it->second;
259259
}
260260

261+
const typet &
262+
get_field_init_type(const irep_idt &field_name, const goto_symex_statet &state)
263+
{
264+
const exprt &field_init_expr = get_field_init_expr(field_name, state);
265+
return field_init_expr.type();
266+
}
267+
261268
/// Given a pointer expression `address` checks if any expr in value_set is
262269
/// compatible
263270
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
@@ -111,6 +111,10 @@ std::vector<std::pair<exprt, exprt>> get_shadow_dereference_candidates(
111111
const typet &lhs_type,
112112
bool &exact_match);
113113

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

0 commit comments

Comments
 (0)