asm.c revision 651f13cea278ec967336033dd032faef0e9fc2ec
1// RUN: %clang_cc1 %s -Wno-private-extern -triple i386-pc-linux-gnu -verify -fsyntax-only 2 3void f() { 4 int i; 5 6 asm ("foo\n" : : "a" (i + 2)); 7 asm ("foo\n" : : "a" (f())); // expected-error {{invalid type 'void' in asm input}} 8 9 asm ("foo\n" : "=a" (f())); // expected-error {{invalid lvalue in asm output}} 10 asm ("foo\n" : "=a" (i + 2)); // expected-error {{invalid lvalue in asm output}} 11 12 asm ("foo\n" : [symbolic_name] "=a" (i) : "[symbolic_name]" (i)); 13 asm ("foo\n" : "=a" (i) : "[" (i)); // expected-error {{invalid input constraint '[' in asm}} 14 asm ("foo\n" : "=a" (i) : "[foo" (i)); // expected-error {{invalid input constraint '[foo' in asm}} 15 asm ("foo\n" : "=a" (i) : "[symbolic_name]" (i)); // expected-error {{invalid input constraint '[symbolic_name]' in asm}} 16 17 asm ("foo\n" : : "" (i)); // expected-error {{invalid input constraint '' in asm}} 18 asm ("foo\n" : "=a" (i) : "" (i)); // expected-error {{invalid input constraint '' in asm}} 19} 20 21void clobbers() { 22 asm ("nop" : : : "ax", "#ax", "%ax"); 23 asm ("nop" : : : "eax", "rax", "ah", "al"); 24 asm ("nop" : : : "0", "%0", "#0"); 25 asm ("nop" : : : "foo"); // expected-error {{unknown register name 'foo' in asm}} 26 asm ("nop" : : : "52"); 27 asm ("nop" : : : "104"); // expected-error {{unknown register name '104' in asm}} 28 asm ("nop" : : : "-1"); // expected-error {{unknown register name '-1' in asm}} 29 asm ("nop" : : : "+1"); // expected-error {{unknown register name '+1' in asm}} 30} 31 32// rdar://6094010 33void test3() { 34 int x; 35 asm(L"foo" : "=r"(x)); // expected-error {{wide string}} 36 asm("foo" : L"=r"(x)); // expected-error {{wide string}} 37} 38 39// <rdar://problem/6156893> 40void test4(const volatile void *addr) 41{ 42 asm ("nop" : : "r"(*addr)); // expected-error {{invalid type 'const volatile void' in asm input for constraint 'r'}} 43 asm ("nop" : : "m"(*addr)); 44 45 asm ("nop" : : "r"(test4(addr))); // expected-error {{invalid type 'void' in asm input for constraint 'r'}} 46 asm ("nop" : : "m"(test4(addr))); // expected-error {{invalid lvalue in asm input for constraint 'm'}} 47 48 asm ("nop" : : "m"(f())); // expected-error {{invalid lvalue in asm input for constraint 'm'}} 49} 50 51// <rdar://problem/6512595> 52void test5() { 53 asm("nop" : : "X" (8)); 54} 55 56// PR3385 57void test6(long i) { 58 asm("nop" : : "er"(i)); 59} 60 61void asm_string_tests(int i) { 62 asm("%!"); // simple asm string, %! is not an error. 63 asm("%!" : ); // expected-error {{invalid % escape in inline assembly string}} 64 asm("xyz %" : ); // expected-error {{invalid % escape in inline assembly string}} 65 66 asm ("%[somename]" :: [somename] "i"(4)); // ok 67 asm ("%[somename]" :: "i"(4)); // expected-error {{unknown symbolic operand name in inline assembly string}} 68 asm ("%[somename" :: "i"(4)); // expected-error {{unterminated symbolic operand name in inline assembly string}} 69 asm ("%[]" :: "i"(4)); // expected-error {{empty symbolic operand name in inline assembly string}} 70 71 // PR3258 72 asm("%9" :: "i"(4)); // expected-error {{invalid operand number in inline asm string}} 73 asm("%1" : "+r"(i)); // ok, referring to input. 74} 75 76// PR4077 77int test7(unsigned long long b) { 78 int a; 79 asm volatile("foo %0 %1" : "=a" (a) :"0" (b)); // expected-error {{input with type 'unsigned long long' matching output with type 'int'}} 80 return a; 81} 82 83// <rdar://problem/7574870> 84asm volatile (""); // expected-warning {{meaningless 'volatile' on asm outside function}} 85 86// PR3904 87void test8(int i) { 88 // A number in an input constraint can't point to a read-write constraint. 89 asm("" : "+r" (i), "=r"(i) : "0" (i)); // expected-error{{invalid input constraint '0' in asm}} 90} 91 92// PR3905 93void test9(int i) { 94 asm("" : [foo] "=r" (i), "=r"(i) : "1[foo]"(i)); // expected-error{{invalid input constraint '1[foo]' in asm}} 95 asm("" : [foo] "=r" (i), "=r"(i) : "[foo]1"(i)); // expected-error{{invalid input constraint '[foo]1' in asm}} 96} 97 98register int g asm("dx"); // expected-error{{global register variables are not supported}} 99 100void 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} 111 112// This is just an assert because of the boolean conversion. 113// Feel free to change the assembly to something sensible if it causes a problem. 114// rdar://problem/9414925 115void test11(void) { 116 _Bool b; 117 asm volatile ("movb %%gs:%P2,%b0" : "=q"(b) : "0"(0), "i"(5L)); 118} 119 120void test12(void) { 121 register int cc __asm ("cc"); // expected-error{{unknown register name 'cc' in asm}} 122} 123 124// PR10223 125void test13(void) { 126 void *esp; 127 __asm__ volatile ("mov %%esp, %o" : "=r"(esp) : : ); // expected-error {{invalid % escape in inline assembly string}} 128} 129 130// <rdar://problem/12700799> 131struct S; // expected-note 2 {{forward declaration of 'struct S'}} 132void test14(struct S *s) { 133 __asm("": : "a"(*s)); // expected-error {{dereference of pointer to incomplete type 'struct S'}} 134 __asm("": "=a" (*s) :); // expected-error {{dereference of pointer to incomplete type 'struct S'}} 135} 136 137// PR15759. 138double test15() { 139 double ret = 0; 140 __asm("0.0":"="(ret)); // expected-error {{invalid output constraint '=' in asm}} 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":"=,g"(ret)); // no-error 149 __asm("0.0":"=g"(ret)); // no-error 150 return ret; 151} 152