Skip to content

Commit 1a50c53

Browse files
Enrico SteffinlongoNlightNFotis
Enrico Steffinlongo
authored andcommitted
Fix issue with set and non-bit-sized value
1 parent 64117a0 commit 1a50c53

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
@@ -154,11 +154,18 @@ void shadow_memoryt::symex_set_field(
154154
<< ". Insert a cast to the type that you want to access.";
155155
throw invalid_input_exceptiont(s.str());
156156
}
157+
158+
// Get the type of the shadow memory for this field
159+
const typet &sm_field_type = get_field_init_type(field_name, state);
160+
// Add a conditional cast to the shadow memory field type if `rhs` is not of
161+
// the expected type
162+
const exprt casted_rhs =
163+
typecast_exprt::conditional_cast(rhs, sm_field_type);
157164
// We replicate the rhs value on each byte of the value that we set.
158165
// This allows the get_field or/max semantics to operate correctly
159166
// on unions.
160167
const auto per_byte_rhs =
161-
expr_initializer(lhs.type(), expr.source_location(), ns, rhs);
168+
expr_initializer(lhs.type(), expr.source_location(), ns, casted_rhs);
162169
CHECK_RETURN(per_byte_rhs.has_value());
163170

164171
#ifdef DEBUG_SM

src/goto-symex/shadow_memory_util.cpp

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

259+
const typet &
260+
get_field_init_type(const irep_idt &field_name, const goto_symex_statet &state)
261+
{
262+
const exprt &field_init_expr = get_field_init_expr(field_name, state);
263+
return field_init_expr.type();
264+
}
265+
259266
/// Given a pointer expression `address` checks if any expr in value_set is
260267
/// compatible
261268
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)