1 // RUN: %clang_cc1 -std=c++11 -verify %s
3 // Note that this puts the expected lines before the directives to work around
4 // limitations in the -verify mode.
6 void test(int *List
, int Length
) {
10 while (i
+ 1 < Length
) {
20 while (i
- 1 < Length
) {
25 while (i
- 2 < Length
) {
29 /* expected-error {{expected ')'}} */ #pragma unroll(4
30 /* expected-error {{missing argument; expected an integer value}} */ #pragma unroll()
31 /* expected-warning {{extra tokens at end of '#pragma unroll'}} */ #pragma unroll 1 2
32 while (i
-6 < Length
) {
36 /* expected-warning {{extra tokens at end of '#pragma nounroll'}} */ #pragma nounroll 1
37 while (i
-7 < Length
) {
41 /* expected-error {{expected ')'}} */ #pragma unroll(()
42 /* expected-error {{expected expression}} */ #pragma unroll -
43 /* The values of 0 and 1 block any unrolling of the loop. */ #pragma unroll 0
44 /* expected-error {{value '3000000000' is too large}} */ #pragma unroll(3000000000)
45 /* expected-error {{value '3000000000' is too large}} */ #pragma unroll 3000000000
46 while (i
-8 < Length
) {
50 /* The values of 0 and 1 block any unrolling of the loop. */ #pragma unroll(0)
51 while (i
-8 < Length
) {
56 /* expected-error {{expected a for, while, or do-while loop to follow '#pragma unroll'}} */ int j
= Length
;
58 /* expected-error {{expected a for, while, or do-while loop to follow '#pragma unroll'}} */ int k
= Length
;
60 /* expected-error {{expected a for, while, or do-while loop to follow '#pragma nounroll'}} */ int l
= Length
;
65 /* expected-error {{expected a for, while, or do-while loop to follow '#pragma unroll'}} */ [[fallthrough
]];
67 for (int i
= 0; i
< 10; ++i
);
72 /* expected-error {{incompatible directives 'unroll(disable)' and '#pragma unroll(4)'}} */ #pragma clang loop unroll(disable)
73 while (i
-10 < Length
) {
78 /* expected-error {{incompatible directives 'unroll(full)' and '#pragma unroll(4)'}} */ #pragma clang loop unroll(full)
79 while (i
-11 < Length
) {
84 /* expected-error {{incompatible directives 'unroll(enable)' and '#pragma unroll(4)'}} */ #pragma clang loop unroll(enable)
85 while (i
-11 < Length
) {
90 /* expected-error {{incompatible directives '#pragma unroll' and '#pragma unroll(4)'}} */ #pragma unroll
91 while (i
-11 < Length
) {
95 #pragma clang loop unroll_count(4)
96 /* expected-error {{incompatible directives '#pragma nounroll' and 'unroll_count(4)'}} */ #pragma nounroll
97 while (i
-12 < Length
) {
102 /* expected-error {{duplicate directives '#pragma nounroll' and '#pragma nounroll'}} */ #pragma nounroll
103 while (i
-13 < Length
) {
108 /* expected-error {{duplicate directives '#pragma unroll' and '#pragma unroll'}} */ #pragma unroll
109 while (i
-14 < Length
) {
114 /* expected-error {{duplicate directives '#pragma unroll' and 'unroll(full)'}} */ #pragma clang loop unroll(full)
115 while (i
-15 < Length
) {
120 /* expected-error {{duplicate directives '#pragma unroll(4)' and '#pragma unroll(4)'}} */ #pragma unroll(4)
121 while (i
-16 < Length
) {
126 /* expected-error {{expected statement}} */ }
128 using size_t = unsigned long long;
131 int FailToBuild(int n
) {
132 constexpr int N
= 100;
133 auto init
= [=]() { return Flag
? n
: 0UL; };
134 auto cond
= [=](size_t ix
) { return Flag
? ix
!= 0 : ix
< 10; };
135 auto iter
= [=](size_t ix
) {
136 return Flag
? ix
& ~(1ULL << __builtin_clzll(ix
)) : ix
+ 1;
138 #pragma unroll Flag ? 0 : N // Ok, allow 0.
139 for (size_t ix
= init(); cond(ix
); ix
= iter(ix
)) {
142 #pragma GCC unroll Flag ? 0 : N // Ok, allow 0.
143 for (size_t ix
= init(); cond(ix
); ix
= iter(ix
)) {
150 return FailToBuild
<true>(n
);
154 return FailToBuild
<false>(n
);