blob: df593d79fa17ceb84c1289e4bf959720dcfc89b6 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o %t
Chris Lattner10ca96a2009-03-10 06:33:24 +00002void t1(int len) {
Anders Carlsson9f2505b2009-01-11 21:23:27 +00003 __asm__ volatile("" : "=&r"(len), "+&r"(len));
Anders Carlsson2763b3a2009-01-11 19:46:50 +00004}
Anders Carlsson9f2505b2009-01-11 21:23:27 +00005
Chris Lattner10ca96a2009-03-10 06:33:24 +00006void t2(unsigned long long t) {
Anders Carlsson9f2505b2009-01-11 21:23:27 +00007 __asm__ volatile("" : "+m"(t));
8}
9
Chris Lattner10ca96a2009-03-10 06:33:24 +000010void t3(unsigned char *src, unsigned long long temp) {
Anders Carlsson9f2505b2009-01-11 21:23:27 +000011 __asm__ volatile("" : "+m"(temp), "+r"(src));
12}
13
Chris Lattner10ca96a2009-03-10 06:33:24 +000014void t4() {
Anders Carlssonebaae2a2009-01-12 02:22:13 +000015 unsigned long long a;
16 struct reg { unsigned long long a, b; } b;
17
Mike Stump1eb44332009-09-09 15:08:12 +000018 __asm__ volatile ("":: "m"(a), "m"(b));
Anders Carlssonebaae2a2009-01-12 02:22:13 +000019}
Anders Carlsson9f2505b2009-01-11 21:23:27 +000020
Anders Carlsson03eb5432009-01-27 20:38:24 +000021// PR3417
Chris Lattner10ca96a2009-03-10 06:33:24 +000022void t5(int i) {
Anders Carlsson03eb5432009-01-27 20:38:24 +000023 asm("nop" : "=r"(i) : "0"(t5));
24}
Anders Carlsson60329792009-02-22 02:11:23 +000025
26// PR3641
Chris Lattner10ca96a2009-03-10 06:33:24 +000027void t6(void) {
Anders Carlsson60329792009-02-22 02:11:23 +000028 __asm__ volatile("" : : "i" (t6));
29}
Chris Lattner10ca96a2009-03-10 06:33:24 +000030
Daniel Dunbar4fcfde42009-11-08 01:45:36 +000031// RUN: grep "T7 NAMED: \$1" %t
Chris Lattner10ca96a2009-03-10 06:33:24 +000032void t7(int a) {
33 __asm__ volatile("T7 NAMED: %[input]" : "+r"(a): [input] "i" (4));
Chris Lattner02af9742009-03-10 06:38:02 +000034}
35
Daniel Dunbar4fcfde42009-11-08 01:45:36 +000036// RUN: grep "T8 NAMED MODIFIER: \${0:c}" %t
Chris Lattner02af9742009-03-10 06:38:02 +000037void t8() {
38 __asm__ volatile("T8 NAMED MODIFIER: %c[input]" :: [input] "i" (4));
39}
Chris Lattner88beebe2009-03-10 06:42:37 +000040
41// PR3682
42unsigned t9(unsigned int a) {
43 asm("bswap %0 %1" : "+r" (a));
44 return a;
45}
Anders Carlssonec91dab2009-04-03 05:57:08 +000046
47// PR3908
48// RUN: grep "PR3908 \$1 \$3 \$2 \$0" %t
49void t10(int r) {
50 __asm__("PR3908 %[lf] %[xx] %[li] %[r]" : [r] "+r" (r) : [lf] "mx" (0), [li] "mr" (0), [xx] "x" ((double)(0)));
51}
Chris Lattner4df4ee02009-05-03 07:27:51 +000052
53
54// PR3373
55unsigned t11(signed char input) {
56 unsigned output;
57 __asm__("xyz"
58 : "=a" (output)
59 : "0" (input));
60 return output;
61}
Chris Lattnerede9d902009-05-03 07:53:25 +000062
Chris Lattnera077b5c2009-05-03 08:21:20 +000063// PR3373
64unsigned char t12(unsigned input) {
65 unsigned char output;
66 __asm__("xyz"
67 : "=a" (output)
68 : "0" (input));
69 return output;
70}
Chris Lattnerede9d902009-05-03 07:53:25 +000071
Chris Lattner3351f112009-05-03 08:32:32 +000072unsigned char t13(unsigned input) {
73 unsigned char output;
74 __asm__("xyz %1"
75 : "=a" (output)
76 : "0" (input));
77 return output;
78}
Chris Lattnerede9d902009-05-03 07:53:25 +000079
Chris Lattner0bdaa5b2009-05-03 09:05:53 +000080struct large {
81 int x[1000];
82};
83
84unsigned long t15(int x, struct large *P) {
85 __asm__("xyz "
86 : "=r" (x)
87 : "m" (*P), "0" (x));
88 return x;
89}
90
91
92
Chris Lattner3351f112009-05-03 08:32:32 +000093
94// bitfield destination of an asm.
Chris Lattnerede9d902009-05-03 07:53:25 +000095struct S {
96 int a : 4;
97};
98
Chris Lattner3351f112009-05-03 08:32:32 +000099void t14(struct S *P) {
Chris Lattnerede9d902009-05-03 07:53:25 +0000100 __asm__("abc %0" : "=r"(P->a) );
101}
Chris Lattner3351f112009-05-03 08:32:32 +0000102
103
Chris Lattner40539832009-10-13 04:32:07 +0000104// PR4938
105int t16() {
106 int a,b;
107 asm ( "nop;"
108 :"=%c" (a)
109 : "r" (b)
110 );
111 return 0;
112}