1 /* Test that default-initialized DFP values consistently have the least quantum
2 exponent. */
3 /* { dg-do run } */
4 /* { dg-require-effective-target dfp } */
5
6 extern void exit (int);
7 extern void abort (void);
8 void *memset (void *, int, __SIZE_TYPE__);
9 int memcmp (const void *, const void *, __SIZE_TYPE__);
10
11 #ifndef TYPE
12 #define TYPE _Decimal32
13 #endif
14
15 #ifndef ZEROFP
16 #define ZEROFP 0e-101DF
17 #endif
18
19 TYPE zero_int = 0;
20 TYPE zero_fp = ZEROFP;
21 TYPE default_init;
22 TYPE empty_init = {};
23 TYPE zero_bytes;
24 TYPE x;
25
26 struct s { TYPE a, b; };
27 struct s s_default_init;
28 struct s s_empty_init = {};
29 struct s s_first_int = { 0 };
30 struct s s_both_int = { 0, 0 };
31 struct s sx;
32
33 const TYPE a_default_init[10];
34 const TYPE a_empty_init[10] = {};
35 const TYPE a_first_int[10] = { 0 };
36 const TYPE a_two_int[10] = { 0, 0 };
37
38 #define CHECK_ZERO_BYTES(expr) \
39 do \
40 { \
41 if (memcmp (expr, &zero_bytes, sizeof zero_bytes) != 0) \
42 abort (); \
43 TYPE tmp = *expr; \
44 if (memcmp (&tmp, &zero_bytes, sizeof zero_bytes) != 0) \
45 abort (); \
46 } \
47 while (0)
48
49 #define CHECK_INT_BYTES(expr) \
50 do \
51 { \
52 if (memcmp (expr, &zero_int, sizeof zero_int) != 0) \
53 abort (); \
54 TYPE tmp = *expr; \
55 if (memcmp (&tmp, &zero_int, sizeof zero_int) != 0) \
56 abort (); \
57 } \
58 while (0)
59
60 int
61 main (void)
62 {
63 memset (&zero_bytes, 0, sizeof zero_bytes);
64 if (memcmp (&zero_bytes, &zero_int, sizeof zero_int) == 0)
65 abort ();
66 CHECK_ZERO_BYTES (&zero_fp);
67 CHECK_ZERO_BYTES (&default_init);
68 CHECK_ZERO_BYTES (&empty_init);
69 CHECK_ZERO_BYTES (&s_default_init.a);
70 CHECK_ZERO_BYTES (&s_default_init.b);
71 CHECK_ZERO_BYTES (&s_empty_init.a);
72 CHECK_ZERO_BYTES (&s_empty_init.b);
73 CHECK_INT_BYTES (&s_first_int.a);
74 CHECK_ZERO_BYTES (&s_first_int.b);
75 CHECK_INT_BYTES (&s_both_int.a);
76 CHECK_INT_BYTES (&s_both_int.b);
77 CHECK_ZERO_BYTES (&a_default_init[0]);
78 CHECK_ZERO_BYTES (&a_default_init[1]);
79 CHECK_ZERO_BYTES (&a_default_init[2]);
80 CHECK_ZERO_BYTES (&a_default_init[9]);
81 CHECK_ZERO_BYTES (&a_empty_init[0]);
82 CHECK_ZERO_BYTES (&a_empty_init[1]);
83 CHECK_ZERO_BYTES (&a_empty_init[2]);
84 CHECK_ZERO_BYTES (&a_empty_init[9]);
85 CHECK_INT_BYTES (&a_first_int[0]);
86 CHECK_ZERO_BYTES (&a_first_int[1]);
87 CHECK_ZERO_BYTES (&a_first_int[2]);
88 CHECK_ZERO_BYTES (&a_first_int[9]);
89 CHECK_INT_BYTES (&a_two_int[0]);
90 CHECK_INT_BYTES (&a_two_int[1]);
91 CHECK_ZERO_BYTES (&a_two_int[2]);
92 CHECK_ZERO_BYTES (&a_two_int[9]);
93 struct s s2 = {};
94 CHECK_ZERO_BYTES (&s2.a);
95 CHECK_ZERO_BYTES (&s2.b);
96 struct s s3 = { 0 };
97 CHECK_INT_BYTES (&s3.a);
98 CHECK_ZERO_BYTES (&s3.b);
99 struct s s4 = { 0, 0 };
100 CHECK_INT_BYTES (&s4.a);
101 CHECK_INT_BYTES (&s4.b);
102 struct s s5 = { 0 };
103 sx = s5;
104 CHECK_INT_BYTES (&sx.a);
105 CHECK_ZERO_BYTES (&sx.b);
106 x = default_init;
107 CHECK_ZERO_BYTES (&x);
108 x = zero_int;
109 CHECK_INT_BYTES (&x);
110 x = s_default_init.a;
111 CHECK_ZERO_BYTES (&x);
112 x = s_default_init.b;
113 CHECK_ZERO_BYTES (&x);
114 exit (0);
115 }