| 1 | // RUN: %clang_cc1 -triple i686 -fsyntax-only -verify %s |
| 2 | // RUN: %clang_cc1 -triple x86_64 -fsyntax-only -verify -DAMD64 %s |
| 3 | |
| 4 | void I(int i, int j) { |
| 5 | static const int BelowMin = -1; |
| 6 | static const int AboveMax = 32; |
| 7 | __asm__("xorl %0,%2" |
| 8 | : "=r"(i) |
| 9 | : "0"(i), "I"(j)); // expected-error{{constraint 'I' expects an integer constant expression}} |
| 10 | __asm__("xorl %0,%2" |
| 11 | : "=r"(i) |
| 12 | : "0"(i), "I"(BelowMin)); // expected-error{{value '-1' out of range for constraint 'I'}} |
| 13 | __asm__("xorl %0,%2" |
| 14 | : "=r"(i) |
| 15 | : "0"(i), "I"(AboveMax)); // expected-error{{value '32' out of range for constraint 'I'}} |
| 16 | __asm__("xorl %0,%2" |
| 17 | : "=r"(i) |
| 18 | : "0"(i), "I"(16)); // expected-no-error |
| 19 | } |
| 20 | |
| 21 | void J(int i, int j) { |
| 22 | static const int BelowMin = -1; |
| 23 | static const int AboveMax = 64; |
| 24 | __asm__("xorl %0,%2" |
| 25 | : "=r"(i) |
| 26 | : "0"(i), "J"(j)); // expected-error{{constraint 'J' expects an integer constant expression}} |
| 27 | __asm__("xorl %0,%2" |
| 28 | : "=r"(i) |
| 29 | : "0"(i), "J"(BelowMin)); // expected-error{{value '-1' out of range for constraint 'J'}} |
| 30 | __asm__("xorl %0,%2" |
| 31 | : "=r"(i) |
| 32 | : "0"(i), "J"(AboveMax)); // expected-error{{value '64' out of range for constraint 'J'}} |
| 33 | __asm__("xorl %0,%2" |
| 34 | : "=r"(i) |
| 35 | : "0"(i), "J"(32)); // expected-no-error |
| 36 | } |
| 37 | |
| 38 | void K(int i, int j) { |
| 39 | static const int BelowMin = -129; |
| 40 | static const int AboveMax = 128; |
| 41 | __asm__("xorl %0,%2" |
| 42 | : "=r"(i) |
| 43 | : "0"(i), "K"(j)); // expected-error{{constraint 'K' expects an integer constant expression}} |
| 44 | __asm__("xorl %0,%2" |
| 45 | : "=r"(i) |
| 46 | : "0"(i), "K"(BelowMin)); // expected-error{{value '-129' out of range for constraint 'K'}} |
| 47 | __asm__("xorl %0,%2" |
| 48 | : "=r"(i) |
| 49 | : "0"(i), "K"(AboveMax)); // expected-error{{value '128' out of range for constraint 'K'}} |
| 50 | __asm__("xorl %0,%2" |
| 51 | : "=r"(i) |
| 52 | : "0"(i), "K"(96)); // expected-no-error |
| 53 | } |
| 54 | |
| 55 | void L(int i, int j) { |
| 56 | static const int Invalid1 = 1; |
| 57 | static const int Invalid2 = 42; |
| 58 | static const int Invalid3 = 0; |
| 59 | static const long long Invalid4 = 0x1000000ff; |
| 60 | static const int Valid1 = 0xff; |
| 61 | static const int Valid2 = 0xffff; |
| 62 | static const int Valid3 = 0xffffffff; |
| 63 | __asm__("xorl %0,%2" |
| 64 | : "=r"(i) |
| 65 | : "0"(i), "L"(j)); // expected-error{{constraint 'L' expects an integer constant expression}} |
| 66 | __asm__("xorl %0,%2" |
| 67 | : "=r"(i) |
| 68 | : "0"(i), "L"(Invalid1)); // expected-error{{value '1' out of range for constraint 'L'}} |
| 69 | __asm__("xorl %0,%2" |
| 70 | : "=r"(i) |
| 71 | : "0"(i), "L"(Invalid2)); // expected-error{{value '42' out of range for constraint 'L'}} |
| 72 | __asm__("xorl %0,%2" |
| 73 | : "=r"(i) |
| 74 | : "0"(i), "L"(Invalid3)); // expected-error{{value '0' out of range for constraint 'L'}} |
| 75 | __asm__("xorl %0,%2" |
| 76 | : "=r"(i) |
| 77 | : "0"(i), "L"(Invalid4)); // expected-error{{value '4294967551' out of range for constraint 'L'}} |
| 78 | __asm__("xorl %0,%2" |
| 79 | : "=r"(i) |
| 80 | : "0"(i), "L"(Valid1)); // expected-no-error |
| 81 | __asm__("xorl %0,%2" |
| 82 | : "=r"(i) |
| 83 | : "0"(i), "L"(Valid2)); // expected-no-error |
| 84 | __asm__("xorl %0,%2" |
| 85 | : "=r"(i) |
| 86 | : "0"(i), "L"(Valid3)); // expected-no-error |
| 87 | } |
| 88 | |
| 89 | void M(int i, int j) { |
| 90 | static const int BelowMin = -1; |
| 91 | static const int AboveMax = 4; |
| 92 | __asm__("xorl %0,%2" |
| 93 | : "=r"(i) |
| 94 | : "0"(i), "M"(j)); // expected-error{{constraint 'M' expects an integer constant expression}} |
| 95 | __asm__("xorl %0,%2" |
| 96 | : "=r"(i) |
| 97 | : "0"(i), "M"(BelowMin)); // expected-error{{value '-1' out of range for constraint 'M'}} |
| 98 | __asm__("xorl %0,%2" |
| 99 | : "=r"(i) |
| 100 | : "0"(i), "M"(AboveMax)); // expected-error{{value '4' out of range for constraint 'M'}} |
| 101 | __asm__("xorl %0,%2" |
| 102 | : "=r"(i) |
| 103 | : "0"(i), "M"(2)); // expected-no-error |
| 104 | } |
| 105 | |
| 106 | void N(int i, int j) { |
| 107 | static const int BelowMin = -1; |
| 108 | static const int AboveMax = 256; |
| 109 | __asm__("xorl %0,%2" |
| 110 | : "=r"(i) |
| 111 | : "0"(i), "N"(j)); // expected-error{{constraint 'N' expects an integer constant expression}} |
| 112 | __asm__("xorl %0,%2" |
| 113 | : "=r"(i) |
| 114 | : "0"(i), "N"(BelowMin)); // expected-error{{value '-1' out of range for constraint 'N'}} |
| 115 | __asm__("xorl %0,%2" |
| 116 | : "=r"(i) |
| 117 | : "0"(i), "N"(AboveMax)); // expected-error{{value '256' out of range for constraint 'N'}} |
| 118 | __asm__("xorl %0,%2" |
| 119 | : "=r"(i) |
| 120 | : "0"(i), "N"(128)); // expected-no-error |
| 121 | } |
| 122 | |
| 123 | void O(int i, int j) { |
| 124 | static const int BelowMin = -1; |
| 125 | static const int AboveMax = 128; |
| 126 | __asm__("xorl %0,%2" |
| 127 | : "=r"(i) |
| 128 | : "0"(i), "O"(j)); // expected-error{{constraint 'O' expects an integer constant expression}} |
| 129 | __asm__("xorl %0,%2" |
| 130 | : "=r"(i) |
| 131 | : "0"(i), "O"(BelowMin)); // expected-error{{value '-1' out of range for constraint 'O'}} |
| 132 | __asm__("xorl %0,%2" |
| 133 | : "=r"(i) |
| 134 | : "0"(i), "O"(AboveMax)); // expected-error{{value '128' out of range for constraint 'O'}} |
| 135 | __asm__("xorl %0,%2" |
| 136 | : "=r"(i) |
| 137 | : "0"(i), "O"(64)); // expected-no-error |
| 138 | } |
| 139 | |
| 140 | void pr40890(void) { |
| 141 | struct s { |
| 142 | int a, b; |
| 143 | }; |
| 144 | static struct s s; |
| 145 | // This null pointer can be used as an integer constant expression. |
| 146 | __asm__ __volatile__("\n#define S_A abcd%0\n" : : "n"(&((struct s*)0)->a)); |
| 147 | // This offset-from-null pointer can be used as an integer constant expression. |
| 148 | __asm__ __volatile__("\n#define S_B abcd%0\n" : : "n"(&((struct s*)0)->b)); |
| 149 | // This pointer cannot be used as an integer constant expression. |
| 150 | __asm__ __volatile__("\n#define GLOBAL_A abcd%0\n" : : "n"(&s.a)); // expected-error{{constraint 'n' expects an integer constant expression}} |
| 151 | // Floating-point is also not okay. |
| 152 | __asm__ __volatile__("\n#define PI abcd%0\n" : : "n"(3.14f)); // expected-error{{constraint 'n' expects an integer constant expression}} |
| 153 | #ifdef AMD64 |
| 154 | // This arbitrary pointer is fine. |
| 155 | __asm__ __volatile__("\n#define BEEF abcd%0\n" : : "n"((int*)0xdeadbeeeeeef)); |
| 156 | #endif |
| 157 | } |
| 158 | |