struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug-2820.c
blob2099800c5969be484d27503e4acc0a51182f5d21
1 /* bug-2820.c
2 Redundancy elimination ignored the difference between integer and floating-point arithmetic operations.
3 */
5 #include <testfwk.h>
7 #include <stdint.h>
9 typedef union
11 int32_t i;
12 float f;
13 } intflt;
15 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
16 void sum(int8_t tp, intflt *if1, intflt *if2)
18 if(tp)
19 (*if1).f *= (*if2).f;
20 else
21 (*if1).i *= (*if2).i;
24 void sum2(int8_t tp, intflt *if1, intflt *if2)
26 if(tp)
27 (*if1).f += (*if2).f;
28 else
29 (*if1).i += (*if2).i;
31 #endif
33 void testBug(void)
35 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
36 intflt data;
38 data.i = -23;
39 sum(0, &data, &data);
40 ASSERT(data.i == -23 * -23);
42 data.f = -23.0f;
43 sum(1, &data, &data);
44 ASSERT(data.f == -23.0f * -23.0f);
46 data.i = -23;
47 sum2(0, &data, &data);
48 ASSERT(data.i == -23 + -23);
50 data.f = -23.0f;
51 sum2(1, &data, &data);
52 ASSERT(data.f == -23.0f + -23.0f);
53 #endif