inline-asm-validate-x86.c 4.5 KB

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