blob: ea478841c4d908772cfe32156ecbb41c3f790341 [file] [log] [blame]
Mike Stump7f79f9b2009-05-29 15:46:01 +00001// RUN: clang-cc -Wno-unused-value -emit-llvm < %s -o %t &&
2// RUN: grep volatile %t | count 145 &&
3// 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;
17#include <stdio.h>
18
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 // ============================================================
83 // Test cases we get wrong.
84
85 // ============================================================
86 // Test cases where we intentionally differ from gcc, due to suspected bugs in
87 // gcc.
88
89 // Not a use. gcc forgets to do the assignment.
90 ((a=a),a);
91
92 // Not a use. gcc gets this wrong, it doesn't emit the copy!
93 // (void)(a=a);
94
95 // Not a use. gcc got this wrong in 4.2 and omitted the side effects
96 // entirely, but it is fixed in 4.4.0.
97 __imag (i = j);
98
99#ifndef __cplusplus
100 // A use of the real part
101 (float)(ci=ci);
102 // Not a use, bug? gcc treats this as not a use, that's probably a bug due to
103 // tree folding ignoring volatile.
104 (int)(ci=ci);
105#endif
106
107 // A use.
108 (float)(i=i);
109 // A use. gcc treats this as not a use, that's probably a bug due to tree
110 // folding ignoring volatile.
111 (int)(i=i);
112
113 // A use.
114 -(i=j);
115 // A use. gcc treats this a not a use, that's probably a bug due to tree
116 // folding ignoring volatile.
117 +(i=k);
118
119 // A use. gcc treats this a not a use, that's probably a bug due to tree
120 // folding ignoring volatile.
121 __real (ci=ci);
122
123 // A use.
124 i + 0;
125 // A use.
126 (i=j) + i;
127 // A use. gcc treats this as not a use, that's probably a bug due to tree
128 // folding ignoring volatile.
129 (i=j) + 0;
130
131#ifdef __cplusplus
132 (i,j)=k;
133 (j=k,i)=i;
134 struct { int x; } s, s1;
135 printf("s is at %p\n", &s);
136 printf("s is at %p\n", &(s = s1));
137 printf("s.x is at %p\n", &((s = s1).x));
138#endif
139}