llvm-project
340 строк · 16.1 Кб
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
6template <int V, int I>7void test_nontype_template_param(int *List, int Length) {8#pragma clang loop vectorize_width(V) interleave_count(I)9for (int i = 0; i < Length; i++) {10List[i] = i;11}12
13#pragma clang loop vectorize_width(V + 4) interleave_count(I + 4)14for (int i = 0; i < Length; i++) {15List[i] = i;16}17}
18
19template <int V>20void test_nontype_template_vectorize(int *List, int Length) {21/* expected-error {{invalid value '-1'; must be positive}} */ #pragma clang loop vectorize_width(V)22for (int i = 0; i < Length; i++) {23List[i] = i;24}25
26/* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop vectorize_width(V / 2)27for (int i = 0; i < Length; i++) {28List[i] += i;29}30}
31
32template <int I>33void test_nontype_template_interleave(int *List, int Length) {34/* expected-error {{invalid value '-1'; must be positive}} */ #pragma clang loop interleave_count(I)35for (int i = 0; i < Length; i++) {36List[i] = i;37}38
39/* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop interleave_count(2 % I)40for (int i = 0; i < Length; i++) {41List[i] = i;42}43}
44
45template <char V>46void test_nontype_template_char(int *List, int Length) {47/* expected-error {{invalid argument of type 'char'; expected an integer type}} */ #pragma clang loop vectorize_width(V)48for (int i = 0; i < Length; i++) {49List[i] = i;50}51}
52
53template <bool V>54void test_nontype_template_bool(int *List, int Length) {55/* expected-error {{invalid argument of type 'bool'; expected an integer type}} */ #pragma clang loop vectorize_width(V)56for (int i = 0; i < Length; i++) {57List[i] = i;58}59}
60
61template <int V, int I>62void test_nontype_template_badarg(int *List, int Length) {63/* expected-error {{use of undeclared identifier 'Vec'}} */ #pragma clang loop vectorize_width(Vec) interleave_count(I) /*64expected-note {{vectorize_width loop hint malformed; use vectorize_width(X, fixed) or vectorize_width(X, scalable) where X is an integer, or vectorize_width('fixed' or 'scalable')}} */
65/* expected-error {{use of undeclared identifier 'Int'}} */ #pragma clang loop vectorize_width(V) interleave_count(Int)66for (int i = 0; i < Length; i++) {67List[i] = i;68}69}
70
71template <typename T>72void test_type_template_vectorize(int *List, int Length) {73const T Value = -1;74/* expected-error {{invalid value '-1'; must be positive}} */ #pragma clang loop vectorize_width(Value)75for (int i = 0; i < Length; i++) {76List[i] = i;77}78
79/* expected-error {{invalid value '-1'; must be positive}} */ #pragma clang loop vectorize_width(Value, fixed)80for (int i = 0; i < Length; i++) {81List[i] = i;82}83}
84
85void test(int *List, int Length) { // expected-note {{declared here}}86int i = 0;87
88#pragma clang loop vectorize(enable)89#pragma clang loop interleave(enable)90#pragma clang loop vectorize_predicate(enable)91#pragma clang loop unroll(full)92while (i + 1 < Length) {93List[i] = i;94}95
96#pragma clang loop vectorize_width(4)97#pragma clang loop interleave_count(8)98#pragma clang loop unroll_count(16)99while (i < Length) {100List[i] = i;101}102
103#pragma clang loop vectorize(disable)104#pragma clang loop interleave(disable)105#pragma clang loop vectorize_predicate(disable)106#pragma clang loop unroll(disable)107while (i - 1 < Length) {108List[i] = i;109}110
111#pragma clang loop vectorize_width(4) interleave_count(8) unroll_count(16)112while (i - 2 < Length) {113List[i] = i;114}115
116#pragma clang loop interleave_count(16)117while (i - 3 < Length) {118List[i] = i;119}120
121int VList[Length]; // expected-warning {{variable length arrays in C++ are a Clang extension}} \122expected-note {{function parameter 'Length' with unknown value cannot be used in a constant expression}}
123#pragma clang loop vectorize(disable) interleave(disable) unroll(disable) vectorize_predicate(disable)124for (int j : VList) {125VList[j] = List[j];126}127
128#pragma clang loop distribute(enable)129for (int j : VList) {130VList[j] = List[j];131}132
133#pragma clang loop distribute(disable)134for (int j : VList) {135VList[j] = List[j];136}137
138test_nontype_template_param<4, 8>(List, Length);139
140/* expected-error {{expected '('}} */ #pragma clang loop vectorize141/* expected-error {{expected '('}} */ #pragma clang loop interleave142/* expected-error {{expected '('}} */ #pragma clang loop vectorize_predicate143/* expected-error {{expected '('}} */ #pragma clang loop unroll144/* expected-error {{expected '('}} */ #pragma clang loop distribute145
146/* expected-error {{expected ')'}} */ #pragma clang loop vectorize(enable147/* expected-error {{expected ')'}} */ #pragma clang loop interleave(enable148/* expected-error {{expected ')'}} */ #pragma clang loop vectorize_predicate(enable149/* expected-error {{expected ')'}} */ #pragma clang loop unroll(full150/* expected-error {{expected ')'}} */ #pragma clang loop distribute(enable151
152/* expected-error {{expected ')'}} */ #pragma clang loop vectorize_width(4153/* expected-error {{expected ')'}} */ #pragma clang loop interleave_count(4154/* expected-error {{expected ')'}} */ #pragma clang loop unroll_count(4155
156/* expected-error {{missing argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop vectorize()157/* expected-error {{missing argument; expected an integer value}} */ #pragma clang loop interleave_count()158/* expected-error {{missing argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll()159/* expected-error {{missing argument; expected 'enable' or 'disable'}} */ #pragma clang loop distribute()160
161/* expected-error {{missing option; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_initiation_interval, vectorize_predicate, or distribute}} */ #pragma clang loop162/* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword163/* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword(enable)164/* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop vectorize(enable) badkeyword(4)165/* expected-warning {{extra tokens at end of '#pragma clang loop'}} */ #pragma clang loop vectorize(enable) ,166while (i-4 < Length) {167List[i] = i;168}169
170/* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop vectorize_width(0)171/* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop interleave_count(0)172/* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop unroll_count(0)173
174/* expected-error {{expression is not an integral constant expression}} expected-note {{division by zero}} */ #pragma clang loop vectorize_width(10 / 0)175/* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop interleave_count(10 / 5 - 2)176while (i-5 < Length) {177List[i] = i;178}179
180test_nontype_template_vectorize<4>(List, Length);181/* expected-note {{in instantiation of function template specialization}} */ test_nontype_template_vectorize<-1>(List, Length);182test_nontype_template_interleave<8>(List, Length);183/* expected-note {{in instantiation of function template specialization}} */ test_nontype_template_interleave<-1>(List, Length);184
185/* expected-note {{in instantiation of function template specialization}} */ test_nontype_template_char<'A'>(List, Length); // Loop hint arg cannot be a char.186/* expected-note {{in instantiation of function template specialization}} */ test_nontype_template_bool<true>(List, Length); // Or a bool.187/* expected-note {{in instantiation of function template specialization}} */ test_type_template_vectorize<int>(List, Length); // Or a template type.188
189/* expected-error {{value '3000000000' is too large}} */ #pragma clang loop vectorize_width(3000000000)190/* expected-error {{value '3000000000' is too large}} */ #pragma clang loop interleave_count(3000000000)191/* expected-error {{value '3000000000' is too large}} */ #pragma clang loop unroll_count(3000000000)192while (i-6 < Length) {193List[i] = i;194}195
196/* expected-warning {{extra tokens at end of '#pragma clang loop'}} */ #pragma clang loop vectorize_width(1 +) 1197/* expected-warning {{extra tokens at end of '#pragma clang loop'}} */ #pragma clang loop vectorize_width(1) +1198const int VV = 4;199/* expected-error {{expected expression}} */ #pragma clang loop vectorize_width(VV +/ 2) /*200expected-note {{vectorize_width loop hint malformed; use vectorize_width(X, fixed) or vectorize_width(X, scalable) where X is an integer, or vectorize_width('fixed' or 'scalable')}} */
201/* expected-error {{use of undeclared identifier 'undefined'}} */ #pragma clang loop vectorize_width(VV+undefined) /*202expected-note {{vectorize_width loop hint malformed; use vectorize_width(X, fixed) or vectorize_width(X, scalable) where X is an integer, or vectorize_width('fixed' or 'scalable')}} */
203/* expected-error {{expected ')'}} */ #pragma clang loop vectorize_width(1+(^*/2 * ()204/* expected-warning {{extra tokens at end of '#pragma clang loop' - ignored}} */ #pragma clang loop vectorize_width(1+(-0[0]))))))205
206/* expected-error {{use of undeclared identifier 'badvalue'}} */ #pragma clang loop vectorize_width(badvalue) /*207expected-note {{vectorize_width loop hint malformed; use vectorize_width(X, fixed) or vectorize_width(X, scalable) where X is an integer, or vectorize_width('fixed' or 'scalable')}} */
208/* expected-error {{use of undeclared identifier 'badvalue'}} */ #pragma clang loop interleave_count(badvalue)209/* expected-error {{use of undeclared identifier 'badvalue'}} */ #pragma clang loop unroll_count(badvalue)210while (i-6 < Length) {211List[i] = i;212}213
214/* expected-error {{invalid argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop vectorize(badidentifier)215/* expected-error {{invalid argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop interleave(badidentifier)216/* expected-error {{invalid argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll(badidentifier)217/* expected-error {{invalid argument; expected 'enable' or 'disable'}} */ #pragma clang loop distribute(badidentifier)218while (i-7 < Length) {219List[i] = i;220}221
222// PR20069 - Loop pragma arguments that are not identifiers or numeric
223// constants crash FE.
224/* expected-error {{expected ')'}} */ #pragma clang loop vectorize(()225/* expected-error {{invalid argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop interleave(*)226/* expected-error {{invalid argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll(=)227/* expected-error {{invalid argument; expected 'enable' or 'disable'}} */ #pragma clang loop distribute(+)228/* expected-error {{type name requires a specifier or qualifier}} expected-error {{expected expression}} */ #pragma clang loop vectorize_width(^) /* expected-note {{vectorize_width loop hint malformed; use vectorize_width(X, fixed) or vectorize_width(X, scalable) where X is an integer, or vectorize_width('fixed' or 'scalable')}} */229/* expected-error {{expected expression}} expected-error {{expected expression}} */ #pragma clang loop interleave_count(/)230/* expected-error {{expected expression}} expected-error {{expected expression}} */ #pragma clang loop unroll_count(==)231while (i-8 < Length) {232List[i] = i;233}234
235#pragma clang loop vectorize(enable)236/* expected-error {{expected a for, while, or do-while loop to follow '#pragma clang loop'}} */ int j = Length;237List[0] = List[1];238
239while (j-1 < Length) {240List[j] = j;241}242
243// FIXME: A bug in ParsedAttributes causes the order of the attributes to be
244// processed in reverse. Consequently, the errors occur on the first of pragma
245// of the next three tests rather than the last, and the order of the kinds
246// is also reversed.
247
248#pragma clang loop vectorize_width(4)249/* expected-error {{incompatible directives 'vectorize(disable)' and 'vectorize_width(4)'}} */ #pragma clang loop vectorize(disable)250#pragma clang loop interleave_count(4)251/* expected-error {{incompatible directives 'interleave(disable)' and 'interleave_count(4)'}} */ #pragma clang loop interleave(disable)252#pragma clang loop unroll_count(4)253/* expected-error {{incompatible directives 'unroll(disable)' and 'unroll_count(4)'}} */ #pragma clang loop unroll(disable)254while (i-8 < Length) {255List[i] = i;256}257
258#pragma clang loop vectorize(enable)259/* expected-error {{duplicate directives 'vectorize(enable)' and 'vectorize(disable)'}} */ #pragma clang loop vectorize(disable)260#pragma clang loop interleave(enable)261/* expected-error {{duplicate directives 'interleave(enable)' and 'interleave(disable)'}} */ #pragma clang loop interleave(disable)262#pragma clang loop vectorize_predicate(enable)263/* expected-error@+1 {{duplicate directives 'vectorize_predicate(enable)' and 'vectorize_predicate(disable)'}} */
264#pragma clang loop vectorize_predicate(disable)265#pragma clang loop unroll(full)266/* expected-error {{duplicate directives 'unroll(full)' and 'unroll(disable)'}} */ #pragma clang loop unroll(disable)267#pragma clang loop distribute(enable)268/* expected-error {{duplicate directives 'distribute(enable)' and 'distribute(disable)'}} */ #pragma clang loop distribute(disable)269while (i-9 < Length) {270List[i] = i;271}272
273#pragma clang loop vectorize(disable)274/* expected-error {{incompatible directives 'vectorize(disable)' and 'vectorize_width(4)'}} */ #pragma clang loop vectorize_width(4)275#pragma clang loop interleave(disable)276/* expected-error {{incompatible directives 'interleave(disable)' and 'interleave_count(4)'}} */ #pragma clang loop interleave_count(4)277#pragma clang loop unroll(disable)278/* expected-error {{incompatible directives 'unroll(disable)' and 'unroll_count(4)'}} */ #pragma clang loop unroll_count(4)279while (i-10 < Length) {280List[i] = i;281}282
283#pragma clang loop vectorize_width(8)284/* expected-error {{duplicate directives 'vectorize_width(8)' and 'vectorize_width(4)'}} */ #pragma clang loop vectorize_width(4)285#pragma clang loop interleave_count(8)286/* expected-error {{duplicate directives 'interleave_count(8)' and 'interleave_count(4)'}} */ #pragma clang loop interleave_count(4)287#pragma clang loop unroll_count(8)288/* expected-error {{duplicate directives 'unroll_count(8)' and 'unroll_count(4)'}} */ #pragma clang loop unroll_count(4)289while (i-11 < Length) {290List[i] = i;291}292
293#pragma clang loop unroll(full)294/* expected-error {{incompatible directives 'unroll(full)' and 'unroll_count(4)'}} */ #pragma clang loop unroll_count(4)295while (i-11 < Length) {296List[i] = i;297}298
299#pragma clang loop interleave(enable)300/* expected-error {{expected statement}} */ }301
302void foo(void) {303#pragma clang loop vectorize_predicate(enable)304/* expected-error {{expected statement}} */ }305
306void foo(int *List, int Length) {307int i;308#pragma clang loop vectorize(enable, extra)309/* expected-warning {{extra tokens at end of '#pragma clang loop vectorize' - ignored}}*/ while (i-6 < Length) {310List[i] = i;311}312
313#pragma clang loop interleave(enable, extra)314/* expected-warning {{extra tokens at end of '#pragma clang loop interleave' - ignored}}*/ while (i-6 < Length) {315List[i] = i;316}317
318#pragma clang loop unroll(enable, extra)319/* expected-warning {{extra tokens at end of '#pragma clang loop unroll' - ignored}}*/ while (i-6 < Length) {320List[i] = i;321}322
323#pragma clang loop vectorize_predicate(enable, extra)324/* expected-warning {{extra tokens at end of '#pragma clang loop vectorize_predicate' - ignored}}*/ while (i-6 < Length) {325List[i] = i;326}327
328#pragma clang loop pipeline(disable, extra)329/* expected-warning {{extra tokens at end of '#pragma clang loop pipeline' - ignored}}*/ while (i-6 < Length) {330List[i] = i;331}332
333/* expected-warning {{extra tokens at end of '#pragma clang loop vectorize_width' - ignored}}*/ #pragma clang loop vectorize_width(2, scalable, extra)334/* expected-warning {{extra tokens at end of '#pragma clang loop interleave_count' - ignored}}*/ #pragma clang loop interleave_count(2, extra)335/* expected-warning {{extra tokens at end of '#pragma clang loop unroll_count' - ignored}}*/ #pragma clang loop unroll_count(2, extra)336/* expected-warning {{extra tokens at end of '#pragma clang loop pipeline_initiation_interval' - ignored}}*/ #pragma clang loop pipeline_initiation_interval(2, extra)337while (i-6 < Length) {338List[i] = i;339}340}
341