xref: /llvm-project/clang/test/Sema/inline-asm-validate-aarch64.c (revision d4de4c3eafa9b70c255a4d6d5a14dccff79d10e9)
1 // RUN: %clang_cc1 -triple aarch64 -fsyntax-only -verify -DVERIFY %s
2 // RUN: %clang_cc1 -triple arm64-apple-darwin -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
3 
4 typedef unsigned char uint8_t;
5 
6 #ifdef VERIFY
test_s(int i)7 void test_s(int i) {
8   asm("" :: "s"(i)); // expected-error{{invalid input constraint 's' in asm}}
9 
10   /// Codegen error
11   asm("" :: "S"(i));
12   asm("" :: "S"(test_s(i))); // expected-error{{invalid type 'void' in asm input for constraint 'S'}}
13 }
14 #else
constraint_r(uint8_t * addr)15 uint8_t constraint_r(uint8_t *addr) {
16   uint8_t byte;
17 
18   __asm__ volatile("ldrb %0, [%1]" : "=r" (byte) : "r" (addr) : "memory");
19 // CHECK: warning: value size does not match register size specified by the constraint and modifier
20 // CHECK: note: use constraint modifier "w"
21 // CHECK: fix-it:{{.*}}:{[[#@LINE-3]]:26-[[#@LINE-3]]:28}:"%w0"
22 
23   return byte;
24 }
25 
constraint_r_symbolic(uint8_t * addr)26 uint8_t constraint_r_symbolic(uint8_t *addr) {
27   uint8_t byte;
28 
29   __asm__ volatile("ldrb %[s0], [%[s1]]" : [s0] "=r" (byte) : [s1] "r" (addr) : "memory");
30 // CHECK: warning: value size does not match register size specified by the constraint and modifier
31 // CHECK: note: use constraint modifier "w"
32 // CHECK: fix-it:{{.*}}:{[[#@LINE-3]]:26-[[#@LINE-3]]:31}:"%w[s0]"
33 
34   return byte;
35 }
36 
37 #define PERCENT "%"
38 
constraint_r_symbolic_macro(uint8_t * addr)39 uint8_t constraint_r_symbolic_macro(uint8_t *addr) {
40   uint8_t byte;
41 
42   __asm__ volatile("ldrb "PERCENT"[s0], [%[s1]]" : [s0] "=r" (byte) : [s1] "r" (addr) : "memory");
43 // CHECK: warning: value size does not match register size specified by the constraint and modifier
44 // CHECK: note: use constraint modifier "w"
45 // CHECK-NOT: fix-it
46 
47   return byte;
48 }
49 
50 // CHECK: warning: value size does not match register size specified by the constraint and modifier
51 // CHECK: asm ("%w0 %w1 %2" : "+r" (one) : "r" (wide_two));
52 // CHECK: note: use constraint modifier "w"
53 
read_write_modifier0(int one,int two)54 void read_write_modifier0(int one, int two) {
55   long wide_two = two;
56   asm ("%w0 %w1 %2" : "+r" (one) : "r" (wide_two));
57 // CHECK: fix-it:{{.*}}:{[[#@LINE-1]]:17-[[#@LINE-1]]:19}:"%w2"
58 }
59 
60 // CHECK-NOT: warning:
read_write_modifier1(int one,int two)61 void read_write_modifier1(int one, int two) {
62   long wide_two = two;
63   asm ("%w0 %1" : "+r" (one), "+r" (wide_two));
64 }
65 #endif
66