xref: /llvm-project/clang/test/Sema/inline-asm-validate-riscv.c (revision 10a55caccf4e2d397f94c1455b93d774591be45f)
1 // RUN: %clang_cc1 -triple riscv32 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -triple riscv64 -fsyntax-only -verify %s
3 
I(int i)4 void I(int i) {
5   static const int BelowMin = -2049;
6   static const int AboveMax = 2048;
7   asm volatile ("" :: "I"(BelowMin)); // expected-error{{value '-2049' out of range for constraint 'I'}}
8   asm volatile ("" :: "I"(AboveMax)); // expected-error{{value '2048' out of range for constraint 'I'}}
9 }
10 
J(int j)11 void J(int j) {
12   static const int BelowMin = -1;
13   static const int AboveMax = 1;
14   asm volatile ("" :: "J"(BelowMin)); // expected-error{{value '-1' out of range for constraint 'J'}}
15   asm volatile ("" :: "J"(AboveMax)); // expected-error{{value '1' out of range for constraint 'J'}}
16 }
17 
K(int k)18 void K(int k) {
19   static const int BelowMin = -1;
20   static const int AboveMax = 32;
21   asm volatile ("" :: "K"(BelowMin)); // expected-error{{value '-1' out of range for constraint 'K'}}
22   asm volatile ("" :: "K"(AboveMax)); // expected-error{{value '32' out of range for constraint 'K'}}
23 }
24 
test_s(int i)25 void test_s(int i) {
26   asm("" :: "s"(test_s(0))); // expected-error{{invalid type 'void' in asm input for constraint 's'}}
27   /// Codegen error
28   asm("" :: "s"(i));
29 
30   asm("" :: "S"(test_s(0))); // expected-error{{invalid type 'void' in asm input for constraint 'S'}}
31 }
32 
test_clobber_conflict(void)33 void test_clobber_conflict(void) {
34   register long x10 asm("x10");
35   asm volatile("" :: "r"(x10) : "x10"); // expected-error {{conflicts with asm clobber list}}
36   asm volatile("" :: "r"(x10) : "a0"); // expected-error {{conflicts with asm clobber list}}
37   asm volatile("" : "=r"(x10) :: "x10"); // expected-error {{conflicts with asm clobber list}}
38   asm volatile("" : "=r"(x10) :: "a0"); // expected-error {{conflicts with asm clobber list}}
39 }
40