1 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck %s
2 
3 // PR10415
4 __asm__ ("foo1");
5 __asm__ ("foo2");
6 __asm__ ("foo3");
7 // CHECK: module asm "foo1"
8 // CHECK-NEXT: module asm "foo2"
9 // CHECK-NEXT: module asm "foo3"
10 
11 void t1(int len) {
12   __asm__ volatile("" : "=&r"(len), "+&r"(len));
13 }
14 
15 void t2(unsigned long long t)  {
16   __asm__ volatile("" : "+m"(t));
17 }
18 
19 void t3(unsigned char *src, unsigned long long temp) {
20   __asm__ volatile("" : "+m"(temp), "+r"(src));
21 }
22 
23 void t4() {
24   unsigned long long a;
25   struct reg { unsigned long long a, b; } b;
26 
27   __asm__ volatile ("":: "m"(a), "m"(b));
28 }
29 
30 // PR3417
31 void t5(int i) {
32   asm("nop" : "=r"(i) : "0"(t5));
33 }
34 
35 // PR3641
36 void t6(void) {
37   __asm__ volatile("" : : "i" (t6));
38 }
39 
40 void t7(int a) {
41   __asm__ volatile("T7 NAMED: %[input]" : "+r"(a): [input] "i" (4));
42   // CHECK: @t7(i32
43   // CHECK: T7 NAMED: $1
44 }
45 
46 void t8() {
47   __asm__ volatile("T8 NAMED MODIFIER: %c[input]" :: [input] "i" (4));
48   // CHECK: @t8()
49   // CHECK: T8 NAMED MODIFIER: ${0:c}
50 }
51 
52 // PR3682
53 unsigned t9(unsigned int a) {
54   asm("bswap %0 %1" : "+r" (a));
55   return a;
56 }
57 
58 // PR3908
59 void t10(int r) {
60   __asm__("PR3908 %[lf] %[xx] %[li] %[r]" : [r] "+r" (r) : [lf] "mx" (0), [li] "mr" (0), [xx] "x" ((double)(0)));
61 
62 // CHECK: @t10(
63 // CHECK:PR3908 $1 $3 $2 $0
64 }
65 
66 
67 // PR3373
68 unsigned t11(signed char input) {
69   unsigned  output;
70   __asm__("xyz"
71           : "=a" (output)
72           : "0" (input));
73   return output;
74 }
75 
76 // PR3373
77 unsigned char t12(unsigned input) {
78   unsigned char output;
79   __asm__("xyz"
80           : "=a" (output)
81           : "0" (input));
82   return output;
83 }
84 
85 unsigned char t13(unsigned input) {
86   unsigned char output;
87   __asm__("xyz %1"
88           : "=a" (output)
89           : "0" (input));
90   return output;
91 }
92 
93 struct large {
94   int x[1000];
95 };
96 
97 unsigned long t15(int x, struct large *P) {
98   __asm__("xyz "
99           : "=r" (x)
100           : "m" (*P), "0" (x));
101   return x;
102 }
103 
104 
105 
106 
107 // bitfield destination of an asm.
108 struct S {
109   int a : 4;
110 };
111 
112 void t14(struct S *P) {
113   __asm__("abc %0" : "=r"(P->a) );
114 }
115 
116 
117 // PR4938
118 int t16() {
119   int a,b;
120   asm ( "nop;"
121        :"=%c" (a)
122        : "r" (b)
123        );
124   return 0;
125 }
126 
127 // PR6475
128 void t17() {
129   int i;
130   __asm__ ( "nop": "=m"(i));
131 
132 // CHECK: @t17()
133 // CHECK: call void asm "nop", "=*m,
134 }
135 
136 // <rdar://problem/6841383>
137 int t18(unsigned data) {
138   int a, b;
139 
140   asm("xyz" :"=a"(a), "=d"(b) : "a"(data));
141   return a + b;
142 // CHECK: t18(i32
143 // CHECK: = call {{.*}}asm "xyz"
144 // CHECK-NEXT: extractvalue
145 // CHECK-NEXT: extractvalue
146 }
147 
148 
149 // PR6780
150 int t19(unsigned data) {
151   int a, b;
152 
153   asm("x{abc|def|ghi}z" :"=r"(a): "r"(data));
154   return a + b;
155   // CHECK: t19(i32
156   // CHECK: = call {{.*}}asm "x$(abc$|def$|ghi$)z"
157 }
158 
159 
160 // PR6845 - Mismatching source/dest fp types.
161 double t20(double x) {
162   register long double result;
163   __asm __volatile ("frndint"  : "=t" (result) : "0" (x));
164   return result;
165 
166   // CHECK: @t20
167   // CHECK: fpext double {{.*}} to x86_fp80
168   // CHECK-NEXT: call x86_fp80 asm sideeffect "frndint"
169   // CHECK: fptrunc x86_fp80 {{.*}} to double
170 }
171 
172 float t21(long double x) {
173   register float result;
174   __asm __volatile ("frndint"  : "=t" (result) : "0" (x));
175   return result;
176   // CHECK: @t21
177   // CHECK: call x86_fp80 asm sideeffect "frndint"
178   // CHECK-NEXT: fptrunc x86_fp80 {{.*}} to float
179 }
180 
181 // <rdar://problem/8348447> - accept 'l' constraint
182 unsigned char t22(unsigned char a, unsigned char b) {
183   unsigned int la = a;
184   unsigned int lb = b;
185   unsigned int bigres;
186   unsigned char res;
187   __asm__ ("0:\n1:\n" : [bigres] "=la"(bigres) : [la] "0"(la), [lb] "c"(lb) :
188                         "edx", "cc");
189   res = bigres;
190   return res;
191 }
192 
193 // <rdar://problem/8348447> - accept 'l' constraint
194 unsigned char t23(unsigned char a, unsigned char b) {
195   unsigned int la = a;
196   unsigned int lb = b;
197   unsigned char res;
198   __asm__ ("0:\n1:\n" : [res] "=la"(res) : [la] "0"(la), [lb] "c"(lb) :
199                         "edx", "cc");
200   return res;
201 }
202 
203 void *t24(char c) {
204   void *addr;
205   // CHECK: @t24
206   // CHECK: zext i8 {{.*}} to i32
207   // CHECK-NEXT: call i8* asm "foobar"
208   __asm__ ("foobar" : "=a" (addr) : "0" (c));
209   return addr;
210 }
211 
212 
213 // PR10299 - fpsr, fpcr
214 void test(void)
215 {
216   __asm__ __volatile__(					   \
217 		       "finit"				   \
218 		       :				   \
219 		       :				   \
220 		       :"st","st(1)","st(2)","st(3)",	   \
221 			"st(4)","st(5)","st(6)","st(7)",   \
222 			"fpsr","fpcr"			   \
223 							   );
224 }
225