1 /* PR tree-optimization/56064 */
2 /* { dg-do run } */
3 /* { dg-options "-std=gnu99 -O2 -fno-builtin-memcpy" } */
4
5 extern void abort (void);
6 extern void *memcpy (void*, const void*, __SIZE_TYPE__);
7
8 #define f_pun_i(F, I, VAL) \
9 { \
10 I i1 = VAL; \
11 I i2 = VAL; \
12 F q1, q2; \
13 memcpy (&q1, &i1, sizeof (I)); \
14 __builtin_memcpy (&q2, &i2, sizeof (I)); \
15 if (q1 != q2) \
16 abort(); \
17 }
18
19 #define i_pun_f(I, F, VAL) \
20 { \
21 F q1 = VAL; \
22 F q2 = VAL; \
23 I i1, i2; \
24 memcpy (&i1, &q1, sizeof (I)); \
25 __builtin_memcpy (&i2, &q2, sizeof (I)); \
26 if (i1 != i2) \
27 abort(); \
28 }
29
30
31 void __attribute__((noinline))
test8(void)32 test8 (void)
33 {
34 #ifdef __INT8_TYPE__
35 if (sizeof (__INT8_TYPE__) == sizeof (short _Fract))
36 {
37 #define TEST(X) f_pun_i (short _Fract, __INT8_TYPE__, __INT8_C (X))
38 TEST (123);
39 TEST (-123);
40 #undef TEST
41
42 #define TEST(X) i_pun_f (__INT8_TYPE__, short _Fract, X ## hr)
43 TEST (0.1234);
44 TEST (-0.987);
45 #undef TEST
46 }
47 #endif /* __INT8_TYPE__ */
48 }
49
50
51 void __attribute__((noinline))
test16(void)52 test16 (void)
53 {
54 #ifdef __INT16_TYPE__
55
56 if (sizeof (__INT16_TYPE__) == sizeof (_Fract))
57 {
58 #define TEST(X) f_pun_i (_Fract, __INT16_TYPE__, __INT16_C (X))
59 TEST (0x4321);
60 TEST (-0x4321);
61 TEST (0x8000);
62 #undef TEST
63
64 #define TEST(X) i_pun_f (__INT16_TYPE__, _Fract, X ## r)
65 TEST (0.12345);
66 TEST (-0.98765);
67 #undef TEST
68 }
69 #endif /* __INT16_TYPE__ */
70 }
71
72
73 void __attribute__((noinline))
test32(void)74 test32 (void)
75 {
76 #ifdef __INT32_TYPE__
77 if (sizeof (__INT32_TYPE__) == sizeof (_Accum))
78 {
79 #define TEST(X) f_pun_i (_Accum, __INT32_TYPE__, __INT32_C (X))
80 TEST (0x76543219);
81 TEST (-0x76543219);
82 TEST (0x80000000);
83 #undef TEST
84
85 #define TEST(X) i_pun_f (__INT32_TYPE__, _Accum, X ## k)
86 TEST (123.456789);
87 TEST (-123.456789);
88 #undef TEST
89 }
90 #endif /* __INT32_TYPE__ */
91 }
92
93
94 void __attribute__((noinline))
test64(void)95 test64 (void)
96 {
97 #ifdef __INT64_TYPE__
98 if (sizeof (__INT64_TYPE__) == sizeof (long _Accum))
99 {
100 #define TEST(X) f_pun_i (long _Accum, __INT64_TYPE__, __INT64_C (X))
101 TEST (0x12345678abcdef01);
102 TEST (-0x12345678abcdef01);
103 TEST (0x8000000000000000);
104 #undef TEST
105
106 #define TEST(X) i_pun_f (__INT64_TYPE__, long _Accum, X ## lk)
107 TEST (123.456789);
108 TEST (-123.456789);
109 #undef TEST
110 }
111 #endif /* __INT64_TYPE__ */
112 }
113
main()114 int main()
115 {
116 test8();
117 test16();
118 test32();
119 test64();
120
121 return 0;
122 }
123