Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / bitfields-dead-loop.c.in
blob759ecb3dd9838f893a183befce1e9e348e77d90d
1 /** Test for "dead-loops" over bitfield or bit tests in a byte.
2 struct: 0, 1
3 varType: 0, 1, 2, 3, 4, 5, 6
4 */
6 #pragma disable_warning 88
8 // Disable for ds390: bug #3211
9 // Absolute addressing has some issues for pdk. And if those are fixed, there might be alack of memory, still.
10 // mcs51 creates invalid assembler. Don't know if that is a bug or just a bad choice for ABS_ADDR1 and ABS_ADDR2 below.
11 #if defined(__SDCC_ds390) || defined(__SDCC_pdk14) || defined(__SDCC_pdk15) || defined(__SDCC_mcs51)
12 #define DUMMY_CASE
13 #endif
15 // These tests assume the bitfields are allocated in LSB to MSB order
16 // but some hosts allocate them in MSB to LSB order. Disable the
17 // tests on these hosts
18 #if defined(PORT_HOST) && (defined(__ppc__) || defined(__PPC__) || defined(__sparc) || defined(__sparc64__))
19 #define DUMMY_CASE
20 #endif
22 #include <testfwk.h>
23 #ifdef __sun__
24 #include <inttypes.h>
25 #else
26 #include <stdint.h>
27 #endif
29 #define VAR_TYPE ({varType})
30 #define TYPE_IS_STRUCT ({struct})
33 typedef struct
35 unsigned int bit0 : 1;
36 unsigned int bit1 : 1;
37 unsigned int bit2 : 1;
38 unsigned int bit3 : 1;
39 unsigned int high : 4;
40 }struct_8bits;
42 #if TYPE_IS_STRUCT
43 #define TYPE struct_8bits
44 #else
45 #define TYPE uint8_t
46 #endif
48 #if defined(__SDCC_pic16)
49 #define ABS_ADDR1 0x0200
50 #define ABS_ADDR2 0x0204
51 #elif defined(__SDCC_pic14)
52 #define ABS_ADDR1 0x0100
53 #define ABS_ADDR2 0x0104
54 #elif defined(__SDCC_stm8)
55 #define ABS_ADDR1 0x1000
56 #define ABS_ADDR2 0x1004
57 #elif defined(__SDCC_f8)
58 #define ABS_ADDR1 0x3000
59 #define ABS_ADDR2 0x3004
60 #else
61 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // TODO: Make test suitable for pdk
62 #if !defined(PORT_HOST) // Never do absolute address test with host
63 #define ABS_ADDR1 0xCA00
64 #define ABS_ADDR2 0xCA04
65 #endif
66 #endif
67 #endif
69 #if VAR_TYPE == 0
70 volatile TYPE volatileBits;
71 #elif VAR_TYPE == 1
72 #ifdef ABS_ADDR1
73 #define volatileBits (*(volatile TYPE*)ABS_ADDR1)
74 #else
75 #define DUMMY_CASE
76 #endif
77 #elif VAR_TYPE == 2
78 #ifdef ABS_ADDR2
79 #define volatileBits (*(volatile TYPE*)ABS_ADDR2)
80 #else
81 #define DUMMY_CASE
82 #endif
83 #elif VAR_TYPE == 3
84 #define VOLATILE_BITS_DEF volatile TYPE volatileBits
85 #elif VAR_TYPE == 4
86 #define VOLATILE_BITS_DEF static volatile TYPE volatileBits
87 #elif VAR_TYPE == 5
88 #ifdef ABS_ADDR1
89 #define VOLATILE_BITS_DEF static volatile TYPE __at(ABS_ADDR1) volatileBits
90 #else
91 #define DUMMY_CASE
92 #endif
93 #elif VAR_TYPE == 6
94 #ifdef ABS_ADDR2
95 #define VOLATILE_BITS_DEF static volatile TYPE __at(ABS_ADDR2) volatileBits
96 #define USE_ONLY_1_BYTE
97 #else
98 #define DUMMY_CASE
99 #endif
100 #else
101 #error "Unknown VAR_TYPE case"
102 #endif
104 #ifndef VOLATILE_BITS_DEF
105 #define VOLATILE_BITS_DEF
106 #endif
109 #ifndef DUMMY_CASE
111 #if TYPE_IS_STRUCT
112 #define AS_UINT8(x) (*(uint8_t *)&x)
113 void
114 loop_test_byte(void)
116 VOLATILE_BITS_DEF;
118 AS_UINT8(volatileBits) = 0x00;
119 while(AS_UINT8(volatileBits) != 0x00);
120 while(volatileBits.high != 0x00);
121 while(volatileBits.bit0);
122 while(volatileBits.bit1);
123 while(volatileBits.bit2);
124 while(volatileBits.bit3);
126 AS_UINT8(volatileBits) = 0xFF;
127 while(AS_UINT8(volatileBits) != 0xFF);
128 while(volatileBits.high != 0x0F);
129 while(!volatileBits.bit0);
130 while(!volatileBits.bit1);
131 while(!volatileBits.bit2);
132 while(!volatileBits.bit3);
134 AS_UINT8(volatileBits) = 0x01;
135 while(AS_UINT8(volatileBits) != 0x01);
136 while(volatileBits.high != 0x00);
137 while(!volatileBits.bit0);
138 while( volatileBits.bit1);
139 while( volatileBits.bit2);
140 while( volatileBits.bit3);
142 AS_UINT8(volatileBits) = 0x02;
143 while(AS_UINT8(volatileBits) != 0x02);
144 while(volatileBits.high != 0x00);
145 while( volatileBits.bit0);
146 while(!volatileBits.bit1);
147 while( volatileBits.bit2);
148 while( volatileBits.bit3);
150 AS_UINT8(volatileBits) = 0xF0;
151 while(AS_UINT8(volatileBits) != 0xF0);
152 while(volatileBits.high != 0x0F);
153 while(volatileBits.bit0);
154 while(volatileBits.bit1);
155 while(volatileBits.bit2);
156 while(volatileBits.bit3);
158 ASSERT(1);
160 #else
161 #define AS_UINT8(x) x
162 void
163 loop_test_byte(void)
165 VOLATILE_BITS_DEF;
167 volatileBits = 0x00;
168 while(volatileBits != 0x00);
169 while((volatileBits & 0xF0) != 0x00);
170 while((volatileBits & 0x01) != 0x00);
171 while((volatileBits & 0x02) != 0x00);
172 while((volatileBits & 0x04) != 0x00);
173 while((volatileBits & 0x08) != 0x00);
175 volatileBits = 0xFF;
176 while(volatileBits != 0xFF);
177 while((uint8_t)(volatileBits & 0xF0) != 0xF0);
178 while((uint8_t)(volatileBits & 0x01) != 0x01);
179 while((uint8_t)(volatileBits & 0x02) != 0x02);
180 while((uint8_t)(volatileBits & 0x04) != 0x04);
181 while((uint8_t)(volatileBits & 0x08) != 0x08);
183 volatileBits = 0x01;
184 while(volatileBits != 0x01);
185 while( (volatileBits & 0xF0) != 0x00);
186 while((uint8_t)(volatileBits & 0x01) != 0x01);
187 while( (volatileBits & 0x02) != 0x00);
188 while( (volatileBits & 0x04) != 0x00);
189 while( (volatileBits & 0x08) != 0x00);
191 volatileBits = 0x02;
192 while(volatileBits != 0x02);
193 while( (volatileBits & 0xF0) != 0x00);
194 while( (volatileBits & 0x01) != 0x00);
195 while((uint8_t)(volatileBits & 0x02) != 0x02);
196 while( (volatileBits & 0x04) != 0x00);
197 while( (volatileBits & 0x08) != 0x00);
199 volatileBits = 0xF0;
200 while(volatileBits != 0xF0);
201 while((uint8_t)(volatileBits & 0xF0) != 0xF0);
202 while( (volatileBits & 0x01) != 0x00);
203 while( (volatileBits & 0x02) != 0x00);
204 while( (volatileBits & 0x04) != 0x00);
205 while( (volatileBits & 0x08) != 0x00);
207 ASSERT(1);
209 #endif
211 #endif // DUMMY_CASE
213 static void
214 testBitfieldsDeadLoop(void)
216 #ifndef DUMMY_CASE
217 loop_test_byte();
218 #endif