1// RUN: %check_clang_tidy %s altera-id-dependent-backward-branch %t -- -header-filter=.* "--" -cl-std=CL1.2 -c
2
3void error() {
4 // ==== Conditional Expressions ====
5 int accumulator = 0;
6 for (int i = 0; i < get_local_id(0); i++) {
7 // CHECK-NOTES: :[[@LINE-1]]:19: warning: backward branch (for loop) is ID-dependent due to ID function call and may cause performance degradation [altera-id-dependent-backward-branch]
8 accumulator++;
9 }
10
11 int j = 0;
12 while (j < get_local_id(0)) {
13 // CHECK-NOTES: :[[@LINE-1]]:10: warning: backward branch (while loop) is ID-dependent due to ID function call and may cause performance degradation [altera-id-dependent-backward-branch]
14 accumulator++;
15 }
16
17 do {
18 accumulator++;
19 } while (j < get_local_id(0));
20 // CHECK-NOTES: :[[@LINE-1]]:12: warning: backward branch (do loop) is ID-dependent due to ID function call and may cause performance degradation [altera-id-dependent-backward-branch]
21
22 // ==== Assignments ====
23 int ThreadID = get_local_id(0);
24
25 while (j < ThreadID) {
26 // CHECK-NOTES: :[[@LINE-1]]:10: warning: backward branch (while loop) is ID-dependent due to variable reference to 'ThreadID' and may cause performance degradation [altera-id-dependent-backward-branch]
27 // CHECK-NOTES: :[[@LINE-4]]:3: note: assignment of ID-dependent variable ThreadID
28 accumulator++;
29 }
30
31 do {
32 accumulator++;
33 } while (j < ThreadID);
34 // CHECK-NOTES: :[[@LINE-1]]:12: warning: backward branch (do loop) is ID-dependent due to variable reference to 'ThreadID' and may cause performance degradation [altera-id-dependent-backward-branch]
35 // CHECK-NOTES: :[[@LINE-12]]:3: note: assignment of ID-dependent variable ThreadID
36
37 struct { int IDDepField; } Example;
38 Example.IDDepField = get_local_id(0);
39
40 for (int i = 0; i < Example.IDDepField; i++) {
41 // CHECK-NOTES: :[[@LINE-1]]:19: warning: backward branch (for loop) is ID-dependent due to member reference to 'IDDepField' and may cause performance degradation [altera-id-dependent-backward-branch]
42 // CHECK-NOTES: :[[@LINE-4]]:3: note: assignment of ID-dependent field IDDepField
43 accumulator++;
44 }
45
46 while (j < Example.IDDepField) {
47 // CHECK-NOTES: :[[@LINE-1]]:10: warning: backward branch (while loop) is ID-dependent due to member reference to 'IDDepField' and may cause performance degradation [altera-id-dependent-backward-branch]
48 // CHECK-NOTES: :[[@LINE-10]]:3: note: assignment of ID-dependent field IDDepField
49 accumulator++;
50 }
51
52 do {
53 accumulator++;
54 } while (j < Example.IDDepField);
55 // CHECK-NOTES: :[[@LINE-1]]:12: warning: backward branch (do loop) is ID-dependent due to member reference to 'IDDepField' and may cause performance degradation [altera-id-dependent-backward-branch]
56 // CHECK-NOTES: :[[@LINE-18]]:3: note: assignment of ID-dependent field IDDepField
57
58 // ==== Inferred Assignments ====
59 int ThreadID2 = ThreadID * 2;
60
61 for (int i = 0; i < ThreadID2; i++) {
62 // CHECK-NOTES: :[[@LINE-1]]:19: warning: backward branch (for loop) is ID-dependent due to variable reference to 'ThreadID2' and may cause performance degradation [altera-id-dependent-backward-branch]
63 // CHECK-NOTES: :[[@LINE-4]]:3: note: inferred assignment of ID-dependent value from ID-dependent variable ThreadID
64 accumulator++;
65 }
66
67 // ==== Unused Inferred Assignments ====
68 int UnusedThreadID = Example.IDDepField; // OK: not used in any loops
69
70 struct { int IDDepField; } UnusedStruct;
71 UnusedStruct.IDDepField = ThreadID * 2; // OK: not used in any loops
72}
73
74void success() {
75 int accumulator = 0;
76
77 for (int i = 0; i < 1000; i++) {
78 if (i < get_local_id(0)) {
79 accumulator++;
80 }
81 }
82}
83

source code of clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp