1 // RUN: %clang_cc1 %s -Wno-private-extern -triple i386-pc-linux-gnu -verify -fsyntax-only 2 3 4 5 void f() { 6 int i; 7 8 asm ("foo\n" : : "a" (i + 2)); 9 asm ("foo\n" : : "a" (f())); // expected-error {{invalid type 'void' in asm input}} 10 11 asm ("foo\n" : "=a" (f())); // expected-error {{invalid lvalue in asm output}} 12 asm ("foo\n" : "=a" (i + 2)); // expected-error {{invalid lvalue in asm output}} 13 14 asm ("foo\n" : [symbolic_name] "=a" (i) : "[symbolic_name]" (i)); 15 asm ("foo\n" : "=a" (i) : "[" (i)); // expected-error {{invalid input constraint '[' in asm}} 16 asm ("foo\n" : "=a" (i) : "[foo" (i)); // expected-error {{invalid input constraint '[foo' in asm}} 17 asm ("foo\n" : "=a" (i) : "[symbolic_name]" (i)); // expected-error {{invalid input constraint '[symbolic_name]' in asm}} 18 19 asm ("foo\n" : : "" (i)); // expected-error {{invalid input constraint '' in asm}} 20 asm ("foo\n" : "=a" (i) : "" (i)); // expected-error {{invalid input constraint '' in asm}} 21 } 22 23 void clobbers() { 24 asm ("nop" : : : "ax", "#ax", "%ax"); 25 asm ("nop" : : : "eax", "rax", "ah", "al"); 26 asm ("nop" : : : "0", "%0", "#0"); 27 asm ("nop" : : : "foo"); // expected-error {{unknown register name 'foo' in asm}} 28 asm ("nop" : : : "52"); 29 asm ("nop" : : : "104"); // expected-error {{unknown register name '104' in asm}} 30 asm ("nop" : : : "-1"); // expected-error {{unknown register name '-1' in asm}} 31 asm ("nop" : : : "+1"); // expected-error {{unknown register name '+1' in asm}} 32 } 33 34 // rdar://6094010 35 void test3() { 36 int x; 37 asm(L"foo" : "=r"(x)); // expected-error {{wide string}} 38 asm("foo" : L"=r"(x)); // expected-error {{wide string}} 39 } 40 41 // <rdar://problem/6156893> 42 void test4(const volatile void *addr) 43 { 44 asm ("nop" : : "r"(*addr)); // expected-error {{invalid type 'const volatile void' in asm input for constraint 'r'}} 45 asm ("nop" : : "m"(*addr)); 46 47 asm ("nop" : : "r"(test4(addr))); // expected-error {{invalid type 'void' in asm input for constraint 'r'}} 48 asm ("nop" : : "m"(test4(addr))); // expected-error {{invalid lvalue in asm input for constraint 'm'}} 49 50 asm ("nop" : : "m"(f())); // expected-error {{invalid lvalue in asm input for constraint 'm'}} 51 } 52 53 // <rdar://problem/6512595> 54 void test5() { 55 asm("nop" : : "X" (8)); 56 } 57 58 // PR3385 59 void test6(long i) { 60 asm("nop" : : "er"(i)); 61 } 62 63 void asm_string_tests(int i) { 64 asm("%!"); // simple asm string, %! is not an error. 65 asm("%!" : ); // expected-error {{invalid % escape in inline assembly string}} 66 asm("xyz %" : ); // expected-error {{invalid % escape in inline assembly string}} 67 68 asm ("%[somename]" :: [somename] "i"(4)); // ok 69 asm ("%[somename]" :: "i"(4)); // expected-error {{unknown symbolic operand name in inline assembly string}} 70 asm ("%[somename" :: "i"(4)); // expected-error {{unterminated symbolic operand name in inline assembly string}} 71 asm ("%[]" :: "i"(4)); // expected-error {{empty symbolic operand name in inline assembly string}} 72 73 // PR3258 74 asm("%9" :: "i"(4)); // expected-error {{invalid operand number in inline asm string}} 75 asm("%1" : "+r"(i)); // ok, referring to input. 76 } 77 78 // PR4077 79 int test7(unsigned long long b) { 80 int a; 81 asm volatile("foo %0 %1" : "=a" (a) :"0" (b)); // expected-error {{input with type 'unsigned long long' matching output with type 'int'}} 82 return a; 83 } 84 85 // <rdar://problem/7574870> 86 asm volatile (""); // expected-warning {{meaningless 'volatile' on asm outside function}} 87 88 // PR3904 89 void test8(int i) { 90 // A number in an input constraint can't point to a read-write constraint. 91 asm("" : "+r" (i), "=r"(i) : "0" (i)); // expected-error{{invalid input constraint '0' in asm}} 92 } 93 94 // PR3905 95 void test9(int i) { 96 asm("" : [foo] "=r" (i), "=r"(i) : "1[foo]"(i)); // expected-error{{invalid input constraint '1[foo]' in asm}} 97 asm("" : [foo] "=r" (i), "=r"(i) : "[foo]1"(i)); // expected-error{{invalid input constraint '[foo]1' in asm}} 98 } 99 100 void test10(void){ 101 static int g asm ("g_asm") = 0; 102 extern int gg asm ("gg_asm"); 103 __private_extern__ int ggg asm ("ggg_asm"); 104 105 int a asm ("a_asm"); // expected-warning{{ignored asm label 'a_asm' on automatic variable}} 106 auto int aa asm ("aa_asm"); // expected-warning{{ignored asm label 'aa_asm' on automatic variable}} 107 108 register int r asm ("cx"); 109 register int rr asm ("rr_asm"); // expected-error{{unknown register name 'rr_asm' in asm}} 110 register int rrr asm ("%"); // expected-error{{unknown register name '%' in asm}} 111 } 112 113 // This is just an assert because of the boolean conversion. 114 // Feel free to change the assembly to something sensible if it causes a problem. 115 // rdar://problem/9414925 116 void test11(void) { 117 _Bool b; 118 asm volatile ("movb %%gs:%P2,%b0" : "=q"(b) : "0"(0), "i"(5L)); 119 } 120 121 void test12(void) { 122 register int cc __asm ("cc"); // expected-error{{unknown register name 'cc' in asm}} 123 } 124 125 // PR10223 126 void test13(void) { 127 void *esp; 128 __asm__ volatile ("mov %%esp, %o" : "=r"(esp) : : ); // expected-error {{invalid % escape in inline assembly string}} 129 } 130 131 // <rdar://problem/12700799> 132 struct S; // expected-note 2 {{forward declaration of 'struct S'}} 133 void test14(struct S *s) { 134 __asm("": : "a"(*s)); // expected-error {{dereference of pointer to incomplete type 'struct S'}} 135 __asm("": "=a" (*s) :); // expected-error {{dereference of pointer to incomplete type 'struct S'}} 136 } 137 138 // PR15759. 139 double test15() { 140 double ret = 0; 141 __asm("0.0":"="(ret)); // expected-error {{invalid output constraint '=' in asm}} 142 __asm("0.0":"=&"(ret)); // expected-error {{invalid output constraint '=&' in asm}} 143 __asm("0.0":"+?"(ret)); // expected-error {{invalid output constraint '+?' in asm}} 144 __asm("0.0":"+!"(ret)); // expected-error {{invalid output constraint '+!' in asm}} 145 __asm("0.0":"+#"(ret)); // expected-error {{invalid output constraint '+#' in asm}} 146 __asm("0.0":"+*"(ret)); // expected-error {{invalid output constraint '+*' in asm}} 147 __asm("0.0":"=%"(ret)); // expected-error {{invalid output constraint '=%' in asm}} 148 __asm("0.0":"=,="(ret)); // expected-error {{invalid output constraint '=,=' in asm}} 149 __asm("0.0":"=,g"(ret)); // no-error 150 __asm("0.0":"=g"(ret)); // no-error 151 return ret; 152 } 153 154 // PR19837 155 struct foo { 156 int a; 157 char b; 158 }; 159 register struct foo bar asm("sp"); // expected-error {{bad type for named register variable}} 160 register float baz asm("sp"); // expected-error {{bad type for named register variable}} 161 162 double f_output_constraint(void) { 163 double result; 164 __asm("foo1": "=f" (result)); // expected-error {{invalid output constraint '=f' in asm}} 165 return result; 166 } 167 168 void fn1() { 169 int l; 170 __asm__("" 171 : [l] "=r"(l) 172 : "[l],m"(l)); // expected-error {{asm constraint has an unexpected number of alternatives: 1 vs 2}} 173 } 174 175 void fn2() { 176 int l; 177 __asm__("" 178 : "+&m"(l)); // expected-error {{invalid output constraint '+&m' in asm}} 179 } 180 181 void fn3() { 182 int l; 183 __asm__("" 184 : "+#r"(l)); // expected-error {{invalid output constraint '+#r' in asm}} 185 } 186 187 void fn4() { 188 int l; 189 __asm__("" 190 : "=r"(l) 191 : "m#"(l)); 192 } 193 194 void fn5() { 195 int l; 196 __asm__("" 197 : [g] "+r"(l) 198 : "[g]"(l)); // expected-error {{invalid input constraint '[g]' in asm}} 199 } 200 201 void fn6() { 202 int a; 203 __asm__("" 204 : "=rm"(a), "=rm"(a) 205 : "11m"(a)) // expected-error {{invalid input constraint '11m' in asm}} 206 } 207