Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / bug-3093.c
blobc11f17e38b746265e901d303c42214c45fdb0e0d
1 /* bug-3093.c
2 An optimization used an incorrect cast to bool.
3 */
5 #include <testfwk.h>
7 #pragma disable_warning 283
9 #include <stdint.h>
10 #include <string.h>
12 #define UINT8 uint8_t
13 #define UINT16 uint16_t
15 #define U_LESS_THAN(A, B) ((A) - (B) & 0x8000u)
16 #define DISTANCE(A, B) (U_LESS_THAN(A, B) ? (B - A) : (A - B))
18 struct Sprite {
19 UINT8 anim_accum_ticks;
20 UINT8 anim_speed;
21 UINT8 anim_frame;
22 UINT8 frame;
24 UINT16 x;
25 UINT16 y;
28 struct Sprite spr, tgt;
30 struct Sprite *THIS, *scroll_target;
32 #define DIST_ACTION 10
34 int mputs(const char *s)
36 ASSERT (!strcmp (s, "no action"));
39 void test() {
40 if(U_LESS_THAN(DISTANCE(THIS->x + 8, scroll_target->x + 8), DIST_ACTION)) mputs("action"); else mputs("no action");
43 void
44 testBug(void){
45 spr.x = 10, THIS = &spr;
46 tgt.x = 30, scroll_target = &tgt;
47 test();
48 spr.x = 5;
49 tgt.x = 5;
50 test();