struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug2740884.c
blob57264f026e815f97f2caed951051dcc81c3e8e80
1 /*
2 bug2740884.c
3 */
5 /*
6 * [ 2740884 ] Incorrect assignment in array of structs
7 * https://sourceforge.net/tracker/?func=detail&group_id=599&atid=100599&aid=2740884
9 * a bug in SDCCast.c:1883 isConformingBody()
10 * case... PTR_OP
11 * causing loopreversal to be erroneously applied here
13 * case... INC_OP and DEC_OP
14 * suffer the same way
16 * (compile "make -C .. ALL_TESTS=./tests/bug2740884.c")
19 #include <testfwk.h>
22 struct {
23 char Route;
24 } doors[4];
26 void foo(void) {
27 char i;
28 for (i = 1; i <= 2; i++)
29 doors[i].Route = 0x24;
32 void bar(void) {
33 char i;
34 for (i = 1; i <= 2; i++)
35 doors[i].Route ++;
38 void baz(void) {
39 char i;
40 for (i = 1; i <= 2; i++)
41 doors[i].Route --;
45 void
46 testBug(void)
48 doors[0].Route = 0;
49 doors[1].Route = 0;
50 doors[2].Route = 0;
51 doors[3].Route = 0;
53 foo();
55 ASSERT(doors[0].Route == 0);
56 ASSERT(doors[1].Route == 0x24);
57 ASSERT(doors[2].Route == 0x24);
58 ASSERT(doors[3].Route == 0);
60 bar();
62 ASSERT(doors[0].Route == 0);
63 ASSERT(doors[1].Route == 0x25);
64 ASSERT(doors[2].Route == 0x25);
65 ASSERT(doors[3].Route == 0);
67 baz();
69 ASSERT(doors[0].Route == 0);
70 ASSERT(doors[1].Route == 0x24);
71 ASSERT(doors[2].Route == 0x24);
72 ASSERT(doors[3].Route == 0);