blob: cc25fd89b0c256ae4842efb04b295bd2a5ce720b [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc %s -arch=i386 -verify -fsyntax-only
Anders Carlsson04728b72007-11-23 19:43:50 +00002
Chris Lattnereab8cfb2009-03-11 00:06:36 +00003void f() {
Anders Carlsson04728b72007-11-23 19:43:50 +00004 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 Carlsson42e1ee02009-01-18 01:56:57 +000011
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 Carlsson04728b72007-11-23 19:43:50 +000016}
Anders Carlsson6fa90862007-11-25 00:25:21 +000017
Chris Lattnereab8cfb2009-03-11 00:06:36 +000018void clobbers() {
Anders Carlsson6fa90862007-11-25 00:25:21 +000019 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 Lattner6bc52112008-07-23 06:46:56 +000028
29// rdar://6094010
30void 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 Carlssond9fca6e2009-01-20 20:49:22 +000036// <rdar://problem/6156893>
37void 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 Carlssone6ea2792009-01-21 06:27:20 +000045 asm ("nop" : : "m"(f())); // expected-error {{invalid lvalue in asm input for constraint 'm'}}
46}
47
48// <rdar://problem/6512595>
Chris Lattner3182db12009-03-10 23:51:40 +000049void test5() {
Anders Carlssone6ea2792009-01-21 06:27:20 +000050 asm("nop" : : "X" (8));
Anders Carlssond9fca6e2009-01-20 20:49:22 +000051}
Anders Carlsson79bc64c2009-01-24 18:03:09 +000052
53// PR3385
Chris Lattner3182db12009-03-10 23:51:40 +000054void test6(long i) {
Anders Carlsson79bc64c2009-01-24 18:03:09 +000055 asm("nop" : : "er"(i));
Anders Carlsson03eb5432009-01-27 20:38:24 +000056}
Chris Lattner3182db12009-03-10 23:51:40 +000057
Chris Lattner85759272009-03-11 00:23:13 +000058void asm_string_tests(int i) {
Chris Lattner3182db12009-03-10 23:51:40 +000059 asm("%!"); // simple asm string, %! is not an error.
60 asm("%!" : ); // expected-error {{invalid % escape in inline assembly string}}
Chris Lattnereab8cfb2009-03-11 00:06:36 +000061 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 Lattner85759272009-03-11 00:23:13 +000067
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 Lattner3182db12009-03-10 23:51:40 +000071}
Chris Lattner49ac8812009-04-26 18:22:24 +000072
73// PR4077
74int test7(unsigned long long b) {
75 int a;
Chris Lattnerf69fcae2009-05-03 07:04:21 +000076 asm volatile("foo %0 %1" : "=a" (a) :"0" (b)); // expected-error {{input with type 'unsigned long long' matching output with type 'int'}}
Chris Lattner49ac8812009-04-26 18:22:24 +000077 return a;
78}