struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug-2807.c
bloba2e61a8b501e981f8ad41e7dbaa983acd3d59d93
1 /* bug-2807.c
2 Overwritten operand in code generation for division.
3 */
5 #include <testfwk.h>
7 #include <stdint.h>
9 typedef struct
11 uint8_t interval;
12 uint8_t duration;
14 Buzzer_request;
16 typedef struct
18 const Buzzer_request* request;
19 uint8_t state;
21 Buzzer;
23 int f(const char *c)
25 static int truecount;
27 if(*c == 't')
28 truecount++;
30 ASSERT(truecount <= 1);
32 return (0);
35 void Buzzer_tick(Buzzer* const self)
37 const Buzzer_request* const request = self->request;
39 const uint8_t state = self->state + 1U;
41 self->state = state;
43 if(request->duration && (state < request->duration))
45 f("stop\n");
47 else if (request->interval)
49 if ((state % request->interval) == 0U)
51 // This if statement is always true due to overwritten request->interval.
52 if((state / request->interval) % 2U)
54 f("true\n");
56 else
58 f("false\n");
65 void testBuzzer(void)
67 Buzzer_request request = { 1, 0 };
68 Buzzer buzzer = { &request, 0 };
70 Buzzer_tick(&buzzer);
71 Buzzer_tick(&buzzer);