xref: /llvm-project/clang/test/Sema/inline-asm-validate-m68k.c (revision 7335cd05137076c69ce4716ac8f30a99fc95c406)
1 // REQUIRES: m68k-registered-target
2 // RUN: %clang_cc1 -triple m68k -fsyntax-only -verify %s -DINVALID
3 // RUN: %clang_cc1 -triple m68k -fsyntax-only -verify %s
4 
5 #ifdef INVALID
6 
7 // Invalid constraint usages that can be blocked by frontend
8 
I()9 void I() {
10   static const int BelowMin = 0;
11   static const int AboveMax = 9;
12   asm ("" :: "I"(BelowMin)); // expected-error{{value '0' out of range for constraint 'I'}}
13   asm ("" :: "I"(AboveMax)); // expected-error{{value '9' out of range for constraint 'I'}}
14 }
15 
J()16 void J() {
17   static const int BelowMin = -0x8001;
18   static const int AboveMax = 0x8000;
19   asm ("" :: "J"(BelowMin)); // expected-error{{value '-32769' out of range for constraint 'J'}}
20   asm ("" :: "J"(AboveMax)); // expected-error{{value '32768' out of range for constraint 'J'}}
21 }
22 
L()23 void L() {
24   static const int BelowMin = -9;
25   static const int AboveMax = 0;
26   asm ("" :: "L"(BelowMin)); // expected-error{{value '-9' out of range for constraint 'L'}}
27   asm ("" :: "L"(AboveMax)); // expected-error{{value '0' out of range for constraint 'L'}}
28 }
29 
N()30 void N() {
31   static const int BelowMin = 23;
32   static const int AboveMax = 32;
33   asm ("" :: "N"(BelowMin)); // expected-error{{value '23' out of range for constraint 'N'}}
34   asm ("" :: "N"(AboveMax)); // expected-error{{value '32' out of range for constraint 'N'}}
35 }
36 
O()37 void O() {
38   // Valid only if it's 16
39   static const int IncorrectVal = 18;
40   asm ("" :: "O"(IncorrectVal)); // expected-error{{value '18' out of range for constraint 'O'}}
41 }
42 
P()43 void P() {
44   static const int BelowMin = 7;
45   static const int AboveMax = 16;
46   asm ("" :: "P"(BelowMin)); // expected-error{{value '7' out of range for constraint 'P'}}
47   asm ("" :: "P"(AboveMax)); // expected-error{{value '16' out of range for constraint 'P'}}
48 }
49 
C0()50 void C0() {
51   // Valid only if it's 0
52   static const int IncorrectVal = 1;
53   asm ("" :: "C0"(IncorrectVal)); // expected-error{{value '1' out of range for constraint 'C0'}}
54 }
55 
56 #else
57 // Valid constraint usages.
58 // Note that these constraints can not be fully validated by frontend.
59 // So we're only testing the availability of their letters here.
60 // expected-no-diagnostics
61 
K()62 void K() {
63   asm ("" :: "K"(0x80));
64 }
65 
M()66 void M() {
67   asm ("" :: "M"(0x100));
68 }
Ci()69 void Ci() {
70   asm ("" :: "Ci"(0));
71 }
72 
Cj()73 void Cj() {
74   asm ("" :: "Cj"(0x8000));
75 }
76 
77 // Register constraints
a(int x)78 void a(int x) {
79   asm ("" :: "a"(x));
80 }
81 
d(int x)82 void d(int x) {
83   asm ("" :: "d"(x));
84 }
85 
86 // Memory constraints
mem()87 void mem() {
88   int x;
89   asm ("" :: "m"(x));
90   asm ("" :: "Q"(x));
91   asm ("" :: "U"(x));
92 }
93 #endif
94 
95