pragma-unroll.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // RUN: %clang_cc1 -std=c++11 -verify %s
  2. // Note that this puts the expected lines before the directives to work around
  3. // limitations in the -verify mode.
  4. void test(int *List, int Length) {
  5. int i = 0;
  6. #pragma unroll
  7. while (i + 1 < Length) {
  8. List[i] = i;
  9. }
  10. #pragma nounroll
  11. while (i < Length) {
  12. List[i] = i;
  13. }
  14. #pragma unroll 4
  15. while (i - 1 < Length) {
  16. List[i] = i;
  17. }
  18. #pragma unroll(8)
  19. while (i - 2 < Length) {
  20. List[i] = i;
  21. }
  22. /* expected-error {{expected ')'}} */ #pragma unroll(4
  23. /* expected-error {{missing argument; expected an integer value}} */ #pragma unroll()
  24. /* expected-warning {{extra tokens at end of '#pragma unroll'}} */ #pragma unroll 1 2
  25. while (i-6 < Length) {
  26. List[i] = i;
  27. }
  28. /* expected-warning {{extra tokens at end of '#pragma nounroll'}} */ #pragma nounroll 1
  29. while (i-7 < Length) {
  30. List[i] = i;
  31. }
  32. /* expected-error {{expected ')'}} */ #pragma unroll(()
  33. /* expected-error {{expected expression}} */ #pragma unroll -
  34. /* expected-error {{invalid value '0'; must be positive}} */ #pragma unroll(0)
  35. /* expected-error {{invalid value '0'; must be positive}} */ #pragma unroll 0
  36. /* expected-error {{value '3000000000' is too large}} */ #pragma unroll(3000000000)
  37. /* expected-error {{value '3000000000' is too large}} */ #pragma unroll 3000000000
  38. while (i-8 < Length) {
  39. List[i] = i;
  40. }
  41. #pragma unroll
  42. /* expected-error {{expected a for, while, or do-while loop to follow '#pragma unroll'}} */ int j = Length;
  43. #pragma unroll 4
  44. /* expected-error {{expected a for, while, or do-while loop to follow '#pragma unroll'}} */ int k = Length;
  45. #pragma nounroll
  46. /* expected-error {{expected a for, while, or do-while loop to follow '#pragma nounroll'}} */ int l = Length;
  47. /* expected-error {{incompatible directives 'unroll(disable)' and '#pragma unroll(4)'}} */ #pragma unroll 4
  48. #pragma clang loop unroll(disable)
  49. while (i-10 < Length) {
  50. List[i] = i;
  51. }
  52. /* expected-error {{incompatible directives 'unroll(full)' and '#pragma unroll(4)'}} */ #pragma unroll(4)
  53. #pragma clang loop unroll(full)
  54. while (i-11 < Length) {
  55. List[i] = i;
  56. }
  57. /* expected-error {{incompatible directives '#pragma unroll' and '#pragma unroll(4)'}} */ #pragma unroll(4)
  58. #pragma unroll
  59. while (i-11 < Length) {
  60. List[i] = i;
  61. }
  62. /* expected-error {{incompatible directives '#pragma nounroll' and 'unroll_count(4)'}} */ #pragma clang loop unroll_count(4)
  63. #pragma nounroll
  64. while (i-12 < Length) {
  65. List[i] = i;
  66. }
  67. /* expected-error {{duplicate directives '#pragma nounroll' and '#pragma nounroll'}} */ #pragma nounroll
  68. #pragma nounroll
  69. while (i-13 < Length) {
  70. List[i] = i;
  71. }
  72. /* expected-error {{duplicate directives '#pragma unroll' and '#pragma unroll'}} */ #pragma unroll
  73. #pragma unroll
  74. while (i-14 < Length) {
  75. List[i] = i;
  76. }
  77. /* expected-error {{duplicate directives 'unroll(full)' and '#pragma unroll'}} */ #pragma unroll
  78. #pragma clang loop unroll(full)
  79. while (i-15 < Length) {
  80. List[i] = i;
  81. }
  82. /* expected-error {{duplicate directives '#pragma unroll(4)' and '#pragma unroll(4)'}} */ #pragma unroll 4
  83. #pragma unroll(4)
  84. while (i-16 < Length) {
  85. List[i] = i;
  86. }
  87. #pragma unroll
  88. /* expected-error {{expected statement}} */ }