blob: e0c672b41eaea413abea797a669cf4b71e13b1f0 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -Wno-unused-value -emit-llvm < %s -o %t
Daniel Dunbar4fcfde42009-11-08 01:45:36 +00002// RUN: grep volatile %t | count 145
Mike Stump7f79f9b2009-05-29 15:46:01 +00003// RUN: grep memcpy %t | count 4
4
5volatile int i, j, k;
6volatile int ar[5];
7volatile char c;
8volatile _Complex int ci;
9volatile struct S {
10#ifdef __cplusplus
11 void operator =(volatile struct S&o) volatile;
12#endif
13 int i;
14} a, b;
15
16//void operator =(volatile struct S&o1, volatile struct S&o2) volatile;
Daniel Dunbar23afaad2009-11-17 08:57:36 +000017int printf(const char *, ...);
Mike Stump7f79f9b2009-05-29 15:46:01 +000018
19int main() {
20 // A use.
21 i;
22 // A use of the real part
23 (float)(ci);
24 // A use.
25 (void)ci;
26 // A use.
27 (void)a;
28 // Not a use.
29 (void)(ci=ci);
30 // Not a use.
31 (void)(i=j);
32 ci+=ci;
33 (ci += ci) + ci;
34 asm("nop");
35 (i += j) + k;
36 asm("nop");
37 // A use
38 (i += j) + 1;
39 asm("nop");
40 ci+ci;
41 // A use.
42 __real i;
43 // A use.
44 +ci;
45 asm("nop");
46 // Not a use.
47 (void)(i=i);
48 (float)(i=i);
49 // A use.
50 (void)i;
51 i=i;
52 i=i=i;
53#ifndef __cplusplus
54 // Not a use.
55 (void)__builtin_choose_expr(0, i=i, j=j);
56#endif
57 // A use.
58 k ? (i=i) : (j=j);
59 (void)(i,(i=i));
60 i=i,i;
61 (i=j,k=j);
62 (i=j,k);
63 (i,j);
64 i=c=k;
65 i+=k;
66 // A use of both.
67 ci;
68#ifndef __cplusplus
69 // A use of _real.
70 (int)ci;
71 // A use of both.
72 (_Bool)ci;
73#endif
74 ci=ci;
75 ci=ci=ci;
76 __imag ci = __imag ci = __imag ci;
77 // Not a use.
78 __real (i = j);
79 // Not a use.
80 __imag i;
81
82 // ============================================================
Mike Stump46cd81f2009-05-29 16:24:13 +000083 // FIXME: Test cases we get wrong.
Mike Stump7f79f9b2009-05-29 15:46:01 +000084
Mike Stump2d3b36e2009-05-29 16:12:36 +000085 // A use. We load all of a into a copy of a, then load i. gcc forgets to do
86 // the assignment.
Mike Stump46cd81f2009-05-29 16:24:13 +000087 // (a = a).i;
Mike Stump2d3b36e2009-05-29 16:12:36 +000088
Mike Stump7f79f9b2009-05-29 15:46:01 +000089 // ============================================================
90 // Test cases where we intentionally differ from gcc, due to suspected bugs in
91 // gcc.
92
93 // Not a use. gcc forgets to do the assignment.
94 ((a=a),a);
95
96 // Not a use. gcc gets this wrong, it doesn't emit the copy!
97 // (void)(a=a);
98
99 // Not a use. gcc got this wrong in 4.2 and omitted the side effects
100 // entirely, but it is fixed in 4.4.0.
101 __imag (i = j);
102
103#ifndef __cplusplus
104 // A use of the real part
105 (float)(ci=ci);
106 // Not a use, bug? gcc treats this as not a use, that's probably a bug due to
107 // tree folding ignoring volatile.
108 (int)(ci=ci);
109#endif
110
111 // A use.
112 (float)(i=i);
113 // A use. gcc treats this as not a use, that's probably a bug due to tree
114 // folding ignoring volatile.
115 (int)(i=i);
116
117 // A use.
118 -(i=j);
119 // A use. gcc treats this a not a use, that's probably a bug due to tree
120 // folding ignoring volatile.
121 +(i=k);
122
123 // A use. gcc treats this a not a use, that's probably a bug due to tree
124 // folding ignoring volatile.
125 __real (ci=ci);
126
127 // A use.
128 i + 0;
129 // A use.
130 (i=j) + i;
131 // A use. gcc treats this as not a use, that's probably a bug due to tree
132 // folding ignoring volatile.
133 (i=j) + 0;
134
135#ifdef __cplusplus
136 (i,j)=k;
137 (j=k,i)=i;
138 struct { int x; } s, s1;
139 printf("s is at %p\n", &s);
140 printf("s is at %p\n", &(s = s1));
141 printf("s.x is at %p\n", &((s = s1).x));
142#endif
143}