Menu

#2529 Subtraction of Result of Two Independent Function Calls Incorrectly Eliminated

closed-fixed
None
Front-end
5
2016-07-28
2016-07-28
alvin
No

sdcc -v
3.6.2 #9667 (MINGW64)

sdcc is incorrectly reducing the subtraction of two independent calls to a function to zero.

Here is a test program showing the problem:

int RND0(void);
int RND1(void);

int Q;

void main(void)
{
   Q = RND0() - RND0();
}

sdcc -mz80 -S test.c

_main::
;test2.c:9: Q = RND0() - RND0();
    ld  hl,#0x0000
    ld  (_Q),hl
    ret

 ~~~~~~

As you can see the difference of the two function calls has been replaced with zero.  sdcc is not considering that function calls have side effects.  In this case the function is a random number generator with the difference of two successive calls not being zero.

 If the program is changed to this:

 ~~~~~~

int RND0(void);
int RND1(void);

int Q;

void main(void)
{
   Q = RND0() - RND1();
}

The expected code is generated with both function calls being made and the difference computed.

Discussion

  • Erik Petrich

    Erik Petrich - 2016-07-28
    • status: open --> closed-fixed
    • assigned_to: Erik Petrich
     
  • Erik Petrich

    Erik Petrich - 2016-07-28

    Fixed in revision #9676.

     

Log in to post a comment.