1 // RUN: %clang_cc1 -std=c++11 -verify %s
2 
3 // Note that this puts the expected lines before the directives to work around
4 // limitations in the -verify mode.
5 
test(int * List,int Length)6 void test(int *List, int Length) {
7   int i = 0;
8 
9 #pragma unroll
10   while (i + 1 < Length) {
11     List[i] = i;
12   }
13 
14 #pragma nounroll
15   while (i < Length) {
16     List[i] = i;
17   }
18 
19 #pragma unroll 4
20   while (i - 1 < Length) {
21     List[i] = i;
22   }
23 
24 #pragma unroll(8)
25   while (i - 2 < Length) {
26     List[i] = i;
27   }
28 
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) {
33     List[i] = i;
34   }
35 
36 /* expected-warning {{extra tokens at end of '#pragma nounroll'}} */ #pragma nounroll 1
37   while (i-7 < Length) {
38     List[i] = i;
39   }
40 
41 /* expected-error {{expected ')'}} */ #pragma unroll(()
42 /* expected-error {{expected expression}} */ #pragma unroll -
43 /* expected-error {{invalid value '0'; must be positive}} */ #pragma unroll(0)
44 /* expected-error {{invalid value '0'; must be positive}} */ #pragma unroll 0
45 /* expected-error {{value '3000000000' is too large}} */ #pragma unroll(3000000000)
46 /* expected-error {{value '3000000000' is too large}} */ #pragma unroll 3000000000
47   while (i-8 < Length) {
48     List[i] = i;
49   }
50 
51 #pragma unroll
52 /* expected-error {{expected a for, while, or do-while loop to follow '#pragma unroll'}} */ int j = Length;
53 #pragma unroll 4
54 /* expected-error {{expected a for, while, or do-while loop to follow '#pragma unroll'}} */ int k = Length;
55 #pragma nounroll
56 /* expected-error {{expected a for, while, or do-while loop to follow '#pragma nounroll'}} */ int l = Length;
57 
58   switch (i) {
59   case 1:
60 #pragma unroll
61 /* expected-error {{expected a for, while, or do-while loop to follow '#pragma unroll'}} */ [[fallthrough]];
62   case 2:
63     for (int i = 0; i < 10; ++i);
64     break;
65   }
66 
67 #pragma unroll 4
68 /* expected-error {{incompatible directives 'unroll(disable)' and '#pragma unroll(4)'}} */ #pragma clang loop unroll(disable)
69   while (i-10 < Length) {
70     List[i] = i;
71   }
72 
73 #pragma unroll(4)
74 /* expected-error {{incompatible directives 'unroll(full)' and '#pragma unroll(4)'}} */ #pragma clang loop unroll(full)
75   while (i-11 < Length) {
76     List[i] = i;
77   }
78 
79 #pragma unroll(4)
80 /* expected-error {{incompatible directives 'unroll(enable)' and '#pragma unroll(4)'}} */ #pragma clang loop unroll(enable)
81   while (i-11 < Length) {
82     List[i] = i;
83   }
84 
85 #pragma unroll(4)
86 /* expected-error {{incompatible directives '#pragma unroll' and '#pragma unroll(4)'}} */ #pragma unroll
87   while (i-11 < Length) {
88     List[i] = i;
89   }
90 
91 #pragma clang loop unroll_count(4)
92 /* expected-error {{incompatible directives '#pragma nounroll' and 'unroll_count(4)'}} */ #pragma nounroll
93   while (i-12 < Length) {
94     List[i] = i;
95   }
96 
97 #pragma nounroll
98 /* expected-error {{duplicate directives '#pragma nounroll' and '#pragma nounroll'}} */ #pragma nounroll
99   while (i-13 < Length) {
100     List[i] = i;
101   }
102 
103 #pragma unroll
104 /* expected-error {{duplicate directives '#pragma unroll' and '#pragma unroll'}} */ #pragma unroll
105   while (i-14 < Length) {
106     List[i] = i;
107   }
108 
109 #pragma unroll
110 /* expected-error {{duplicate directives '#pragma unroll' and 'unroll(full)'}} */ #pragma clang loop unroll(full)
111   while (i-15 < Length) {
112     List[i] = i;
113   }
114 
115 #pragma unroll 4
116 /* expected-error {{duplicate directives '#pragma unroll(4)' and '#pragma unroll(4)'}} */ #pragma unroll(4)
117   while (i-16 < Length) {
118     List[i] = i;
119   }
120 
121 #pragma unroll
122 /* expected-error {{expected statement}} */ }
123