struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug-2368.c
blob5bdc9a11bbaa82a318f04b8f6615d8b48afe0735
1 /* bug-2368.c
2 Wrong byte order in optimization of pointer assignment for stm8
3 */
5 #include <testfwk.h>
6 #include <stdint.h>
8 #ifdef __SDCC
9 #pragma std_c99
10 #endif
12 #if defined (__SDCC_stm8) || defined (__SDCC_z80) || defined(__SDCC_z80n) || defined (__SDCC_z180) || defined (__SDCC_r2k) || defined (__SDCC_r2ka) || defined (__SDCC_r3ka)
14 #define TEST_VAL 0x1234
16 #ifdef __SDCC_stm8 // data memory in lower half of 16-bit address space
17 #define loc ((volatile uint16_t *) 0x7fd)
18 #else // data memory in upper half of 16-bit address space
19 #define loc ((volatile uint16_t *) 0x87fd)
20 #endif
22 volatile uint16_t *p = loc;
24 void foo1 (void)
26 *p = TEST_VAL;
29 void foo2 (void)
31 *loc = TEST_VAL;
34 #endif
36 void testBug (void)
38 #if defined (__SDCC_stm8) || defined (__SDCC_z80) || defined(__SDCC_z80n) || defined (__SDCC_z180) || defined (__SDCC_r2k) || defined (__SDCC_r2ka) || defined (__SDCC_r3ka)
39 volatile uint16_t *q = loc;
41 foo1 ();
42 ASSERT (*loc == TEST_VAL);
43 ASSERT (*p == TEST_VAL);
44 ASSERT (*q == TEST_VAL);
46 foo2 ();
47 ASSERT (*loc == TEST_VAL);
48 ASSERT (*p == TEST_VAL);
49 ASSERT (*q == TEST_VAL);
51 *q = TEST_VAL;
52 ASSERT (*loc == TEST_VAL);
53 ASSERT (*p == TEST_VAL);
54 ASSERT (*q == TEST_VAL);
56 #endif