]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/torture/dfp-default-init-1.c
tree.cc: Fix optimization of DFP default initialization
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / torture / dfp-default-init-1.c
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 zero_bytes;
23 TYPE x;
24
25 struct s { TYPE a, b; };
26 struct s s_default_init;
27 struct s s_empty_init = {};
28 struct s s_first_int = { 0 };
29 struct s s_both_int = { 0, 0 };
30 struct s sx;
31
32 const TYPE a_default_init[10];
33 const TYPE a_empty_init[10] = {};
34 const TYPE a_first_int[10] = { 0 };
35 const TYPE a_two_int[10] = { 0, 0 };
36
37 #define CHECK_ZERO_BYTES(expr) \
38 do \
39 { \
40 if (memcmp (expr, &zero_bytes, sizeof zero_bytes) != 0) \
41 abort (); \
42 TYPE tmp = *expr; \
43 if (memcmp (&tmp, &zero_bytes, sizeof zero_bytes) != 0) \
44 abort (); \
45 } \
46 while (0)
47
48 #define CHECK_INT_BYTES(expr) \
49 do \
50 { \
51 if (memcmp (expr, &zero_int, sizeof zero_int) != 0) \
52 abort (); \
53 TYPE tmp = *expr; \
54 if (memcmp (&tmp, &zero_int, sizeof zero_int) != 0) \
55 abort (); \
56 } \
57 while (0)
58
59 int
60 main (void)
61 {
62 memset (&zero_bytes, 0, sizeof zero_bytes);
63 if (memcmp (&zero_bytes, &zero_int, sizeof zero_int) == 0)
64 abort ();
65 CHECK_ZERO_BYTES (&zero_fp);
66 CHECK_ZERO_BYTES (&default_init);
67 CHECK_ZERO_BYTES (&s_default_init.a);
68 CHECK_ZERO_BYTES (&s_default_init.b);
69 CHECK_ZERO_BYTES (&s_empty_init.a);
70 CHECK_ZERO_BYTES (&s_empty_init.b);
71 CHECK_INT_BYTES (&s_first_int.a);
72 CHECK_ZERO_BYTES (&s_first_int.b);
73 CHECK_INT_BYTES (&s_both_int.a);
74 CHECK_INT_BYTES (&s_both_int.b);
75 CHECK_ZERO_BYTES (&a_default_init[0]);
76 CHECK_ZERO_BYTES (&a_default_init[1]);
77 CHECK_ZERO_BYTES (&a_default_init[2]);
78 CHECK_ZERO_BYTES (&a_default_init[9]);
79 CHECK_ZERO_BYTES (&a_empty_init[0]);
80 CHECK_ZERO_BYTES (&a_empty_init[1]);
81 CHECK_ZERO_BYTES (&a_empty_init[2]);
82 CHECK_ZERO_BYTES (&a_empty_init[9]);
83 CHECK_INT_BYTES (&a_first_int[0]);
84 CHECK_ZERO_BYTES (&a_first_int[1]);
85 CHECK_ZERO_BYTES (&a_first_int[2]);
86 CHECK_ZERO_BYTES (&a_first_int[9]);
87 CHECK_INT_BYTES (&a_two_int[0]);
88 CHECK_INT_BYTES (&a_two_int[1]);
89 CHECK_ZERO_BYTES (&a_two_int[2]);
90 CHECK_ZERO_BYTES (&a_two_int[9]);
91 struct s s2 = {};
92 CHECK_ZERO_BYTES (&s2.a);
93 CHECK_ZERO_BYTES (&s2.b);
94 struct s s3 = { 0 };
95 CHECK_INT_BYTES (&s3.a);
96 CHECK_ZERO_BYTES (&s3.b);
97 struct s s4 = { 0, 0 };
98 CHECK_INT_BYTES (&s4.a);
99 CHECK_INT_BYTES (&s4.b);
100 struct s s5 = { 0 };
101 sx = s5;
102 CHECK_INT_BYTES (&sx.a);
103 CHECK_ZERO_BYTES (&sx.b);
104 x = default_init;
105 CHECK_ZERO_BYTES (&x);
106 x = zero_int;
107 CHECK_INT_BYTES (&x);
108 x = s_default_init.a;
109 CHECK_ZERO_BYTES (&x);
110 x = s_default_init.b;
111 CHECK_ZERO_BYTES (&x);
112 exit (0);
113 }