1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -Wno-unused %s
12 a
+ ++a
; // expected-warning {{unsequenced modification and access to 'a'}}
13 a
= ++a
; // expected-warning {{multiple unsequenced modifications to 'a'}}
14 a
+ a
++; // expected-warning {{unsequenced modification and access to 'a'}}
15 a
= a
++; // expected-warning {{multiple unsequenced modifications to 'a'}}
17 ++a
+ ++a
; // expected-warning {{multiple unsequenced modifications}}
18 a
++ + a
++; // expected-warning {{multiple unsequenced modifications}}
19 a
= xs
[++a
]; // expected-warning {{multiple unsequenced modifications}}
20 a
= xs
[a
++]; // expected-warning {{multiple unsequenced modifications}}
21 a
= (++a
, ++a
); // expected-warning {{multiple unsequenced modifications}}
22 a
= (a
++, ++a
); // expected-warning {{multiple unsequenced modifications}}
23 a
= (a
++, a
++); // expected-warning {{multiple unsequenced modifications}}
25 f(a
= 0, a
); // expected-warning {{unsequenced modification and access}}
26 f(a
, a
+= 0); // expected-warning {{unsequenced modification and access}}
27 f(a
= 0, a
= 0); // expected-warning {{multiple unsequenced modifications}}
30 a
= f(++a
, a
++); // expected-warning {{multiple unsequenced modifications}}
32 ++a
+ f(++a
, 0); // expected-warning {{multiple unsequenced modifications}}
33 f(++a
, 0) + ++a
; // expected-warning {{multiple unsequenced modifications}}
34 a
++ + f(a
++, 0); // expected-warning {{multiple unsequenced modifications}}
35 f(a
++, 0) + a
++; // expected-warning {{multiple unsequenced modifications}}
37 a
= ++a
; // expected-warning {{multiple unsequenced modifications}}
38 a
+= ++a
; // expected-warning {{unsequenced modification and access}}
40 A agg1
= { a
++, a
++ }; // expected-warning {{multiple unsequenced modifications}}
41 A agg2
= { a
++ + a
, a
++ }; // expected-warning {{unsequenced modification and access}}
43 (xs
[2] && (a
= 0)) + a
; // expected-warning {{unsequenced modification and access to 'a'}}
44 (0 && (a
= 0)) + a
; // ok
45 (1 && (a
= 0)) + a
; // expected-warning {{unsequenced modification and access}}
47 (xs
[3] || (a
= 0)) + a
; // expected-warning {{unsequenced modification and access to 'a'}}
48 (0 || (a
= 0)) + a
; // expected-warning {{unsequenced modification and access}}
49 (1 || (a
= 0)) + a
; // ok
51 (xs
[4] ? a
: ++a
) + a
; // expected-warning {{unsequenced modification and access to 'a'}}
52 (0 ? a
: ++a
) + a
; // expected-warning {{unsequenced modification and access}}
53 (1 ? a
: ++a
) + a
; // ok
54 (xs
[5] ? ++a
: ++a
) + a
; // expected-warning {{unsequenced modification and access to 'a'}}
56 (++a
, xs
[6] ? ++a
: 0) + a
; // expected-warning {{unsequenced modification and access}}
58 // Here, the read of the fourth 'a' might happen before or after the write to
60 a
+= (a
++, a
) + a
; // expected-warning {{unsequenced modification and access}}
67 (q
= &agg2
)->y
= q
->x
; // expected-warning {{unsequenced modification and access to 'q'}}
69 // This has undefined behavior if a == 0; otherwise, the side-effect of the
70 // increment is sequenced before the value computation of 'f(a, a)', which is
71 // sequenced before the value computation of the '&&', which is sequenced
72 // before the assignment. We treat the sequencing in '&&' as being
76 // This has undefined behavior if a != 0.
77 (a
&& a
++) + a
; // expected-warning {{unsequenced modification and access to 'a'}}
79 // FIXME: Find a way to avoid warning here.
80 (xs
[7] && ++a
) * (!xs
[7] && ++a
); // expected-warning {{multiple unsequenced modifications to 'a'}}
82 xs
[0] = (a
= 1, a
); // ok
84 xs
[8] ? ++a
+ a
++ : 0; // expected-warning {{multiple unsequenced modifications}}
85 xs
[8] ? 0 : ++a
+ a
++; // expected-warning {{multiple unsequenced modifications}}
86 xs
[8] ? ++a
: a
++; // ok
88 xs
[8] && (++a
+ a
++); // expected-warning {{multiple unsequenced modifications}}
89 xs
[8] || (++a
+ a
++); // expected-warning {{multiple unsequenced modifications}}
91 (__builtin_classify_type(++a
) ? 1 : 0) + ++a
; // ok
92 (__builtin_constant_p(++a
) ? 1 : 0) + ++a
; // ok
93 (__builtin_expect(++a
, 0) ? 1 : 0) + ++a
; // expected-warning {{multiple unsequenced modifications}}
94 _Generic(++a
, default: 0) + ++a
; // ok
95 sizeof(++a
) + ++a
; // ok
96 _Alignof(++a
) + ++a
; // expected-warning {{extension}}
98 __builtin_constant_p(f(++a
, 0)) ? f(f(++a
, 0), f(++a
, 0)) : 0;
100 if (0) ++a
+ ++a
; // ok, unreachable
103 void g(const char *p
, int n
) {
104 // This resembles code produced by some macros in glibc's <string.h>.
105 __builtin_constant_p(p
) && __builtin_constant_p(++n
) && (++n
+ ++n
);