SDCC generates incorrect code for some statements of
the form foo += bar. The current implementation of
those operators transforms the statement to foo = foo +
bar, and then strips out any increment/decrement
operators found in the second instance of foo. However
this does not work in more complex cases, e.g.
getitem()->flags |= 42;
(the getitem() call will be invoked twice).
This patch makes SDCC create temporary variables if
needed in order to store side-effect-ful values. The
above statement now gets transformed to
tmp = getitem(); tmp->flags = tmp->flags | 42;
The generated code could use some more attention from
the peephole optimizer, but at least it is correct.
Log in to post a comment.