Debian Codegraph @

gcc/testsuite/gcc.target/avr/torture/pr118878.c

raw
1 /* { dg-do run { target { ! avr_tiny } } } */
2 /* { dg-additional-options { -std=c99 } } */
3
4 #ifdef __AVR_HAVE_LPMX__
5
6 /* From include <avr/pgmspace.h> */
7
8 typedef __UINT8_TYPE__ uint8_t;
9 typedef __UINT16_TYPE__ uint16_t;
10 typedef __UINT32_TYPE__ uint32_t;
11 typedef uint32_t uint_farptr_t;
12
13 #define pgm_read_dword_far(__addr) __ELPM_dword (__addr)
14
15 #define __ELPM_dword(addr) \
16 (__extension__({ \
17 uint_farptr_t __addr32 = (addr); \
18 uint32_t __result; \
19 __ELPM__4 (__result, __addr32, uint32_t); \
20 __result; }))
21
22 /* Has no ELPM: Fallback to LPM. */
23 #define __ELPM__4(r,a,T) const T *__a = (const T*)(uint16_t) a; __LPM__4(r,__a)
24
25 #define __LPM__4(res,addr) \
26 __asm volatile ("lpm %A0,%a1+" "\n\t" \
27 "lpm %B0,%a1+" "\n\t" \
28 "lpm %C0,%a1+" "\n\t" \
29 "lpm %D0,%a1+" : "=r" (res), "+z" (addr))
30
31 #define PROGMEM __attribute__((__progmem__))
32
33 #define pgm_get_far_address(var) \
34 (__extension__({ uint_farptr_t __tmp; \
35 __asm__ ("ldi %A0, lo8(%1)" "\n\t" \
36 "ldi %B0, hi8(%1)" "\n\t" \
37 "ldi %C0, hh8(%1)" "\n\t" \
38 "clr %D0" : "=d" (__tmp) : "i" (&(var)) ); __tmp; }))
39
40 /*********************************************/
41
42 #define VAL 0x01050711
43
44 PROGMEM
45 const uint32_t data[] = { VAL, 2 * VAL, 7 * VAL };
46
47 uint32_t get_val (uint8_t i)
48 {
49 uint32_t v = VAL;
50 if (i == 1) v *= 2;
51 if (i == 2) v *= 7;
52 return v;
53 }
54
55 __attribute__((noinline,noclone))
56 void test (uint8_t i)
57 {
58 if (pgm_read_dword_far (pgm_get_far_address (data[0])) != get_val (0))
59 __builtin_exit (__LINE__);
60
61 uint_farptr_t pf = pgm_get_far_address (data[0]) + i * sizeof (uint32_t);
62 if (pgm_read_dword_far (pf) != get_val (i))
63 __builtin_exit (__LINE__);
64 }
65
66 int main (void)
67 {
68 test (1);
69 test (2);
70 return 0;
71 }
72
73 #else
74 int main (void)
75 {
76 return 0;
77 }
78 #endif