struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-pr47538.c
blobfdce56228a697e3427222c41182323b69d373ef7
1 /*
2 pr47538.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma std_c99
9 #pragma disable_warning 93
10 #endif
12 #include <string.h>
14 /* PR tree-optimization/47538 */
16 struct S
18 double a, b, *c;
19 unsigned long d;
22 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
23 void
24 foo (struct S *x, const struct S *y)
26 const unsigned long n = y->d + 1;
27 const double m = 0.25 * (y->b - y->a);
28 x->a = y->a;
29 x->b = y->b;
30 if (n == 1)
32 x->c[0] = 0.;
34 else if (n == 2)
36 x->c[1] = m * y->c[0];
37 x->c[0] = 2.0 * x->c[1];
39 else
41 double o = 0.0, p = 1.0;
42 unsigned long i;
44 for (i = 1; i <= n - 2; i++)
46 x->c[i] = m * (y->c[i - 1] - y->c[i + 1]) / (double) i;
47 o += p * x->c[i];
48 p = -p;
50 x->c[n - 1] = m * y->c[n - 2] / (n - 1.0);
51 o += p * x->c[n - 1];
52 x->c[0] = 2.0 * o;
55 #endif
57 void
58 testTortureExecute (void)
60 #if !(defined(__SDCC_mcs51) && defined(__SDCC_MODEL_SMALL)) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
61 struct S x, y;
62 double c[4] = { 10, 20, 30, 40 }, d[4], e[4] = { 118, 118, 118, 118 };
64 y.a = 10;
65 y.b = 6;
66 y.c = c;
67 x.c = d;
68 y.d = 3;
69 memcpy (d, e, sizeof d);
70 foo (&x, &y);
71 if (d[0] != 0 || d[1] != 20 || d[2] != 10 || d[3] != -10)
72 ASSERT (0);
73 y.d = 2;
74 memcpy (d, e, sizeof d);
75 foo (&x, &y);
76 if (d[0] != 60 || d[1] != 20 || d[2] != -10 || d[3] != 118)
77 ASSERT (0);
78 y.d = 1;
79 memcpy (d, e, sizeof d);
80 foo (&x, &y);
81 if (d[0] != -20 || d[1] != -10 || d[2] != 118 || d[3] != 118)
82 ASSERT (0);
83 y.d = 0;
84 memcpy (d, e, sizeof d);
85 foo (&x, &y);
86 if (d[0] != 0 || d[1] != 118 || d[2] != 118 || d[3] != 118)
87 ASSERT (0);
88 return;
89 #endif