Eli Friedman | c219a15 | 2009-05-19 11:12:40 +0000 | [diff] [blame] | 1 | // RUN: clang-cc %s -triple i386-pc-linux-gnu -verify -fsyntax-only |
Anders Carlsson | 04728b7 | 2007-11-23 19:43:50 +0000 | [diff] [blame] | 2 | |
Chris Lattner | eab8cfb | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 3 | void f() { |
Anders Carlsson | 04728b7 | 2007-11-23 19:43:50 +0000 | [diff] [blame] | 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}} |
Anders Carlsson | 42e1ee0 | 2009-01-18 01:56:57 +0000 | [diff] [blame] | 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}} |
Anders Carlsson | 04728b7 | 2007-11-23 19:43:50 +0000 | [diff] [blame] | 16 | } |
Anders Carlsson | 6fa9086 | 2007-11-25 00:25:21 +0000 | [diff] [blame] | 17 | |
Chris Lattner | eab8cfb | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 18 | void clobbers() { |
Anders Carlsson | 6fa9086 | 2007-11-25 00:25:21 +0000 | [diff] [blame] | 19 | asm ("nop" : : : "ax", "#ax", "%ax"); |
| 20 | asm ("nop" : : : "eax", "rax", "ah", "al"); |
| 21 | asm ("nop" : : : "0", "%0", "#0"); |
| 22 | asm ("nop" : : : "foo"); // expected-error {{unknown register name 'foo' in asm}} |
| 23 | asm ("nop" : : : "52"); |
| 24 | asm ("nop" : : : "53"); // expected-error {{unknown register name '53' in asm}} |
| 25 | asm ("nop" : : : "-1"); // expected-error {{unknown register name '-1' in asm}} |
| 26 | asm ("nop" : : : "+1"); // expected-error {{unknown register name '+1' in asm}} |
| 27 | } |
Chris Lattner | 6bc5211 | 2008-07-23 06:46:56 +0000 | [diff] [blame] | 28 | |
| 29 | // rdar://6094010 |
| 30 | void test3() { |
| 31 | int x; |
| 32 | asm(L"foo" : "=r"(x)); // expected-error {{wide string}} |
| 33 | asm("foo" : L"=r"(x)); // expected-error {{wide string}} |
| 34 | } |
| 35 | |
Anders Carlsson | d9fca6e | 2009-01-20 20:49:22 +0000 | [diff] [blame] | 36 | // <rdar://problem/6156893> |
| 37 | void test4(const volatile void *addr) |
| 38 | { |
| 39 | asm ("nop" : : "r"(*addr)); // expected-error {{invalid type 'void const volatile' in asm input for constraint 'r'}} |
| 40 | asm ("nop" : : "m"(*addr)); |
| 41 | |
| 42 | asm ("nop" : : "r"(test4(addr))); // expected-error {{invalid type 'void' in asm input for constraint 'r'}} |
| 43 | asm ("nop" : : "m"(test4(addr))); // expected-error {{invalid lvalue in asm input for constraint 'm'}} |
| 44 | |
Anders Carlsson | e6ea279 | 2009-01-21 06:27:20 +0000 | [diff] [blame] | 45 | asm ("nop" : : "m"(f())); // expected-error {{invalid lvalue in asm input for constraint 'm'}} |
| 46 | } |
| 47 | |
| 48 | // <rdar://problem/6512595> |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 49 | void test5() { |
Anders Carlsson | e6ea279 | 2009-01-21 06:27:20 +0000 | [diff] [blame] | 50 | asm("nop" : : "X" (8)); |
Anders Carlsson | d9fca6e | 2009-01-20 20:49:22 +0000 | [diff] [blame] | 51 | } |
Anders Carlsson | 79bc64c | 2009-01-24 18:03:09 +0000 | [diff] [blame] | 52 | |
| 53 | // PR3385 |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 54 | void test6(long i) { |
Anders Carlsson | 79bc64c | 2009-01-24 18:03:09 +0000 | [diff] [blame] | 55 | asm("nop" : : "er"(i)); |
Anders Carlsson | 03eb543 | 2009-01-27 20:38:24 +0000 | [diff] [blame] | 56 | } |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 57 | |
Chris Lattner | 8575927 | 2009-03-11 00:23:13 +0000 | [diff] [blame] | 58 | void asm_string_tests(int i) { |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 59 | asm("%!"); // simple asm string, %! is not an error. |
| 60 | asm("%!" : ); // expected-error {{invalid % escape in inline assembly string}} |
Chris Lattner | eab8cfb | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 61 | asm("xyz %" : ); // expected-error {{invalid % escape in inline assembly string}} |
| 62 | |
| 63 | asm ("%[somename]" :: [somename] "i"(4)); // ok |
| 64 | asm ("%[somename]" :: "i"(4)); // expected-error {{unknown symbolic operand name in inline assembly string}} |
| 65 | asm ("%[somename" :: "i"(4)); // expected-error {{unterminated symbolic operand name in inline assembly string}} |
| 66 | asm ("%[]" :: "i"(4)); // expected-error {{empty symbolic operand name in inline assembly string}} |
Chris Lattner | 8575927 | 2009-03-11 00:23:13 +0000 | [diff] [blame] | 67 | |
| 68 | // PR3258 |
| 69 | asm("%9" :: "i"(4)); // expected-error {{invalid operand number in inline asm string}} |
| 70 | asm("%1" : "+r"(i)); // ok, referring to input. |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 71 | } |
Chris Lattner | 49ac881 | 2009-04-26 18:22:24 +0000 | [diff] [blame] | 72 | |
| 73 | // PR4077 |
| 74 | int test7(unsigned long long b) { |
| 75 | int a; |
Chris Lattner | f69fcae | 2009-05-03 07:04:21 +0000 | [diff] [blame] | 76 | asm volatile("foo %0 %1" : "=a" (a) :"0" (b)); // expected-error {{input with type 'unsigned long long' matching output with type 'int'}} |
Chris Lattner | 49ac881 | 2009-04-26 18:22:24 +0000 | [diff] [blame] | 77 | return a; |
| 78 | } |