1 |
689 |
jeremybenn |
/* Test precedence and associativity in expressions. */
|
2 |
|
|
/* Origin: Joseph Myers <joseph@codesourcery.com> */
|
3 |
|
|
/* { dg-do compile } */
|
4 |
|
|
/* { dg-options "" } */
|
5 |
|
|
|
6 |
|
|
struct s { int *a; } *p, q, *r[2], *g();
|
7 |
|
|
int *i[2];
|
8 |
|
|
int j[2];
|
9 |
|
|
_Complex double c[2];
|
10 |
|
|
|
11 |
|
|
void
|
12 |
|
|
f (void)
|
13 |
|
|
{
|
14 |
|
|
#define ASSERT(expr) do { char x[(expr) ? 1 : -1]; } while (0)
|
15 |
|
|
/* Postfix and unary operators and casts. */
|
16 |
|
|
*p++;
|
17 |
|
|
*p--;
|
18 |
|
|
*p->a;
|
19 |
|
|
*q.a;
|
20 |
|
|
*r[1];
|
21 |
|
|
(*g()).a;
|
22 |
|
|
++i[0];
|
23 |
|
|
--i[0];
|
24 |
|
|
+j[0];
|
25 |
|
|
-j[0];
|
26 |
|
|
~j[0];
|
27 |
|
|
!j[0];
|
28 |
|
|
__real__ c[1];
|
29 |
|
|
__imag__ c[1];
|
30 |
|
|
ASSERT ((sizeof p++) == (sizeof p));
|
31 |
|
|
ASSERT ((sizeof (int) + 1) == ((sizeof (int)) + 1));
|
32 |
|
|
ASSERT ((__alignof p++) == (__alignof p));
|
33 |
|
|
ASSERT ((__alignof (int) + 1) == ((__alignof (int)) + 1));
|
34 |
|
|
ASSERT ((sizeof __extension__ 1 + 1) == ((sizeof 1) + 1));
|
35 |
|
|
/* Binary operators. */
|
36 |
|
|
ASSERT (((_Bool) 1 * 2) == 2);
|
37 |
|
|
ASSERT (((_Bool) 8 / 4) == 0);
|
38 |
|
|
ASSERT (((_Bool) 8 % 4) == 1);
|
39 |
|
|
#define ASSERT_BIN(C1, O1, C2, O2, C3, V1, V2, V3) \
|
40 |
|
|
do { \
|
41 |
|
|
ASSERT ((C1 O1 C2 O2 C3) == V1); \
|
42 |
|
|
ASSERT (((C1 O1 C2) O2 C3) == V2); \
|
43 |
|
|
ASSERT ((C1 O1 (C2 O2 C3)) == V3); \
|
44 |
|
|
} while (0);
|
45 |
|
|
ASSERT_BIN (1, *, 2, *, 3, 6, 6, 6);
|
46 |
|
|
ASSERT_BIN (2, *, 2, /, 3, 1, 1, 0);
|
47 |
|
|
ASSERT_BIN (2, *, 2, %, 3, 1, 1, 4);
|
48 |
|
|
ASSERT_BIN (2, /, 2, *, 3, 3, 3, 0);
|
49 |
|
|
ASSERT_BIN (2, /, 2, /, 2, 0, 0, 2);
|
50 |
|
|
ASSERT_BIN (2, /, 4, %, 3, 0, 0, 2);
|
51 |
|
|
ASSERT_BIN (2, %, 2, *, 3, 0, 0, 2);
|
52 |
|
|
ASSERT_BIN (2, %, 9, /, 3, 0, 0, 2);
|
53 |
|
|
ASSERT_BIN (2, %, 4, %, 3, 2, 2, 0);
|
54 |
|
|
ASSERT_BIN (2, *, 3, +, 4, 10, 10, 14);
|
55 |
|
|
ASSERT_BIN (2, *, 3, -, 4, 2, 2, -2);
|
56 |
|
|
ASSERT_BIN (2, /, 3, +, 4, 4, 4, 0);
|
57 |
|
|
ASSERT_BIN (2, /, 3, -, 4, -4, -4, -2);
|
58 |
|
|
ASSERT_BIN (2, %, 3, +, 4, 6, 6, 2);
|
59 |
|
|
ASSERT_BIN (2, %, 3, -, 4, -2, -2, 0);
|
60 |
|
|
ASSERT_BIN (2, +, 3, *, 4, 14, 20, 14);
|
61 |
|
|
ASSERT_BIN (2, +, 3, /, 4, 2, 1, 2);
|
62 |
|
|
ASSERT_BIN (2, +, 3, %, 4, 5, 1, 5);
|
63 |
|
|
ASSERT_BIN (2, -, 3, *, 4, -10, -4, -10);
|
64 |
|
|
ASSERT_BIN (2, -, 3, /, 4, 2, 0, 2);
|
65 |
|
|
ASSERT_BIN (2, -, 4, %, 4, 2, -2, 2);
|
66 |
|
|
ASSERT_BIN (2, +, 3, +, 4, 9, 9, 9);
|
67 |
|
|
ASSERT_BIN (2, +, 3, -, 4, 1, 1, 1);
|
68 |
|
|
ASSERT_BIN (2, -, 3, +, 4, 3, 3, -5);
|
69 |
|
|
ASSERT_BIN (2, -, 3, -, 4, -5, -5, 3);
|
70 |
|
|
ASSERT_BIN (3, +, 2, <<, 4, 80, 80, 35);
|
71 |
|
|
ASSERT_BIN (3, +, 2, >>, 4, 0, 0, 3);
|
72 |
|
|
ASSERT_BIN (3, -, 2, <<, 4, 16, 16, -29);
|
73 |
|
|
ASSERT_BIN (3, -, 2, >>, 4, 0, 0, 3);
|
74 |
|
|
ASSERT_BIN (2, <<, 4, +, 3, 256, 35, 256);
|
75 |
|
|
ASSERT_BIN (2, <<, 4, -, 3, 4, 29, 4);
|
76 |
|
|
ASSERT_BIN (2, >>, 4, +, 3, 0, 3, 0);
|
77 |
|
|
ASSERT_BIN (2, >>, 4, -, 3, 1, -3, 1);
|
78 |
|
|
ASSERT_BIN (4L, <<, 2L, <<, 3L, 128L, 128L, 262144L);
|
79 |
|
|
ASSERT_BIN (4L, <<, 2L, >>, 3L, 2L, 2L, 4L);
|
80 |
|
|
ASSERT_BIN (4L, >>, 2L, <<, 3L, 8L, 8L, 0L);
|
81 |
|
|
ASSERT_BIN (4L, >>, 2L, >>, 3L, 0L, 0L, 4L);
|
82 |
|
|
ASSERT_BIN (2, <<, 5, <, 4, 0, 0, 2);
|
83 |
|
|
ASSERT_BIN (2, <<, 5, >, 4, 1, 1, 4);
|
84 |
|
|
ASSERT_BIN (2, <<, 5, <=, 4, 0, 0, 2);
|
85 |
|
|
ASSERT_BIN (2, <<, 5, >=, 4, 1, 1, 4);
|
86 |
|
|
ASSERT_BIN (2, >>, 5, <, 4, 1, 1, 2);
|
87 |
|
|
ASSERT_BIN (2, >>, 5, >, 4, 0, 0, 1);
|
88 |
|
|
ASSERT_BIN (2, >>, 5, <=, 4, 1, 1, 2);
|
89 |
|
|
ASSERT_BIN (2, >>, 5, >=, 4, 0, 0, 1);
|
90 |
|
|
ASSERT_BIN (4, <, 3, <<, 2, 1, 0, 1);
|
91 |
|
|
ASSERT_BIN (4, <, 20, >>, 2, 1, 0, 1);
|
92 |
|
|
ASSERT_BIN (4, >, 3, <<, 2, 0, 4, 0);
|
93 |
|
|
ASSERT_BIN (4, >, 3, >>, 2, 1, 0, 1);
|
94 |
|
|
ASSERT_BIN (4, <=, 3, <<, 2, 1, 0, 1);
|
95 |
|
|
ASSERT_BIN (4, <=, 20, >>, 2, 1, 0, 1);
|
96 |
|
|
ASSERT_BIN (4, >=, 3, <<, 2, 0, 4, 0);
|
97 |
|
|
ASSERT_BIN (4, >=, 3, >>, 2, 1, 0, 1);
|
98 |
|
|
ASSERT_BIN (1, <, 2, <, 3, 1, 1, 0);
|
99 |
|
|
ASSERT_BIN (1, <, 2, >, 0, 1, 1, 0);
|
100 |
|
|
ASSERT_BIN (1, <, 2, <=, 3, 1, 1, 0);
|
101 |
|
|
ASSERT_BIN (0, <, 4, >=, 3, 0, 0, 1);
|
102 |
|
|
ASSERT_BIN (1, >, 2, <, 3, 1, 1, 0);
|
103 |
|
|
ASSERT_BIN (1, >, 2, >, 3, 0, 0, 1);
|
104 |
|
|
ASSERT_BIN (1, >, 2, <=, 3, 1, 1, 0);
|
105 |
|
|
ASSERT_BIN (1, >, 2, >=, 3, 0, 0, 1);
|
106 |
|
|
ASSERT_BIN (3, <=, 2, <, 3, 1, 1, 0);
|
107 |
|
|
ASSERT_BIN (2, <=, 3, >, 0, 1, 1, 0);
|
108 |
|
|
ASSERT_BIN (2, <=, 3, <=, 4, 1, 1, 0);
|
109 |
|
|
ASSERT_BIN (2, <=, 3, >=, 1, 1, 1, 0);
|
110 |
|
|
ASSERT_BIN (0, >=, 2, <, 3, 1, 1, 0);
|
111 |
|
|
ASSERT_BIN (1, >=, 2, >, 3, 0, 0, 1);
|
112 |
|
|
ASSERT_BIN (0, >=, 2, <=, 3, 1, 1, 0);
|
113 |
|
|
ASSERT_BIN (1, >=, 2, >=, 3, 0, 0, 1);
|
114 |
|
|
ASSERT_BIN (-1, <, 2, ==, 3, 0, 0, 1);
|
115 |
|
|
ASSERT_BIN (1, <, 2, !=, 3, 1, 1, 0);
|
116 |
|
|
ASSERT_BIN (1, >, 2, ==, 3, 0, 0, 1);
|
117 |
|
|
ASSERT_BIN (1, >, 2, !=, 3, 1, 1, 0);
|
118 |
|
|
ASSERT_BIN (0, <=, 2, ==, 3, 0, 0, 1);
|
119 |
|
|
ASSERT_BIN (2, <=, 2, !=, 3, 1, 1, 0);
|
120 |
|
|
ASSERT_BIN (1, >=, 2, ==, 3, 0, 0, 1);
|
121 |
|
|
ASSERT_BIN (0, >=, 2, !=, 3, 1, 1, 0);
|
122 |
|
|
ASSERT_BIN (1, ==, 3, <, 2, 0, 1, 0);
|
123 |
|
|
ASSERT_BIN (1, ==, 3, >, 2, 1, 0, 1);
|
124 |
|
|
ASSERT_BIN (1, ==, 3, <=, 2, 0, 1, 0);
|
125 |
|
|
ASSERT_BIN (1, ==, 3, >=, 2, 1, 0, 1);
|
126 |
|
|
ASSERT_BIN (1, !=, 2, <, 3, 0, 1, 0);
|
127 |
|
|
ASSERT_BIN (1, !=, 2, >, 3, 1, 0, 1);
|
128 |
|
|
ASSERT_BIN (1, !=, 2, <=, 3, 0, 1, 0);
|
129 |
|
|
ASSERT_BIN (1, !=, 2, >=, 3, 1, 0, 1);
|
130 |
|
|
ASSERT_BIN (1, ==, 2, ==, 0, 1, 1, 0);
|
131 |
|
|
ASSERT_BIN (1, ==, 2, !=, 0, 0, 0, 1);
|
132 |
|
|
ASSERT_BIN (1, !=, 2, ==, 3, 0, 0, 1);
|
133 |
|
|
ASSERT_BIN (1, !=, 2, !=, 3, 1, 1, 0);
|
134 |
|
|
ASSERT_BIN (0, ==, 2, &, 1, 0, 0, 1);
|
135 |
|
|
ASSERT_BIN (0, !=, 2, &, 1, 1, 1, 0);
|
136 |
|
|
ASSERT_BIN (1, &, 2, ==, 0, 0, 1, 0);
|
137 |
|
|
ASSERT_BIN (1, &, 2, !=, 0, 1, 0, 1);
|
138 |
|
|
ASSERT_BIN (1, &, 2, ^, 3, 3, 3, 1);
|
139 |
|
|
ASSERT_BIN (3, ^, 2, &, 1, 3, 1, 3);
|
140 |
|
|
ASSERT_BIN (3, ^, 2, |, 1, 1, 1, 0);
|
141 |
|
|
ASSERT_BIN (3, |, 2, ^, 1, 3, 2, 3);
|
142 |
|
|
ASSERT_BIN (2, |, 0, &&, 2, 1, 1, 2);
|
143 |
|
|
ASSERT_BIN (2, &&, 0, |, 2, 1, 2, 1);
|
144 |
|
|
ASSERT_BIN (0, &&, 0, ||, 1, 1, 1, 0);
|
145 |
|
|
ASSERT_BIN (1, ||, 0, &&, 0, 1, 0, 1);
|
146 |
|
|
/* Conditional expressions. */
|
147 |
|
|
ASSERT ((1 || 2 ? 3 : 4) == 3);
|
148 |
|
|
ASSERT ((1 || (2 ? 3 : 4)) == 1);
|
149 |
|
|
/* Assignment expressions. */
|
150 |
|
|
p = p = p;
|
151 |
|
|
/* Expressions. */
|
152 |
|
|
p, p = p;
|
153 |
|
|
}
|