diff --git a/regression/goto-instrument/dump-side-effect/main.c b/regression/goto-instrument/dump-side-effect/main.c new file mode 100644 index 00000000000..d3629607819 --- /dev/null +++ b/regression/goto-instrument/dump-side-effect/main.c @@ -0,0 +1,17 @@ +struct S +{ + int bf : 2; +}; + +int foo() +{ + return 0; +} + +int main() +{ + struct S s; + struct S *sp = &s; + if(sp[0].bf = foo()) + return 0; +} diff --git a/regression/goto-instrument/dump-side-effect/test.desc b/regression/goto-instrument/dump-side-effect/test.desc new file mode 100644 index 00000000000..361f68df93b --- /dev/null +++ b/regression/goto-instrument/dump-side-effect/test.desc @@ -0,0 +1,12 @@ +CORE +main.c +--dump-c +VERIFICATION SUCCESSFUL +^EXIT=0$ +^SIGNAL=0$ +-- +^warning: ignoring +-- +This test must verify successfully also for the output generated using dump-c, +which previously would fail to compile for it included a type cast on a +left-hand side. diff --git a/src/goto-programs/goto_clean_expr.cpp b/src/goto-programs/goto_clean_expr.cpp index 3569b887d14..776729291f4 100644 --- a/src/goto-programs/goto_clean_expr.cpp +++ b/src/goto-programs/goto_clean_expr.cpp @@ -395,9 +395,10 @@ void goto_convertt::clean_expr( } // turn into code - code_assignt assignment; - assignment.lhs()=lhs; - assignment.rhs() = side_effect_assign.rhs(); + exprt new_lhs = skip_typecast(lhs); + exprt new_rhs = typecast_exprt::conditional_cast( + side_effect_assign.rhs(), new_lhs.type()); + code_assignt assignment(std::move(new_lhs), std::move(new_rhs)); assignment.add_source_location()=expr.source_location(); convert_assign(assignment, dest, mode);