Skip to content

Commit 8327886

Browse files
authored
Merge pull request #6888 from tautschnig/bugfixes/lhs-cast
Move left-hand side type casts to right-hand side
2 parents e35da92 + 1faa1fe commit 8327886

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
struct S
2+
{
3+
int bf : 2;
4+
};
5+
6+
int foo()
7+
{
8+
return 0;
9+
}
10+
11+
int main()
12+
{
13+
struct S s;
14+
struct S *sp = &s;
15+
if(sp[0].bf = foo())
16+
return 0;
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--dump-c
4+
VERIFICATION SUCCESSFUL
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
9+
--
10+
This test must verify successfully also for the output generated using dump-c,
11+
which previously would fail to compile for it included a type cast on a
12+
left-hand side.

src/goto-programs/goto_clean_expr.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,10 @@ void goto_convertt::clean_expr(
395395
}
396396

397397
// turn into code
398-
code_assignt assignment;
399-
assignment.lhs()=lhs;
400-
assignment.rhs() = side_effect_assign.rhs();
398+
exprt new_lhs = skip_typecast(lhs);
399+
exprt new_rhs = typecast_exprt::conditional_cast(
400+
side_effect_assign.rhs(), new_lhs.type());
401+
code_assignt assignment(std::move(new_lhs), std::move(new_rhs));
401402
assignment.add_source_location()=expr.source_location();
402403
convert_assign(assignment, dest, mode);
403404

0 commit comments

Comments
 (0)