| 1 | // RUN: %check_clang_tidy %s openmp-use-default-none %t -- -- -fopenmp=libomp -fopenmp-version=51 |
| 2 | // RUN: %check_clang_tidy -std=c11 %s openmp-use-default-none %t -- -- -x c -fopenmp=libomp -fopenmp-version=51 |
| 3 | |
| 4 | //----------------------------------------------------------------------------// |
| 5 | // Null cases. |
| 6 | //----------------------------------------------------------------------------// |
| 7 | |
| 8 | // 'for' directive can not have 'default' clause, no diagnostics. |
| 9 | void n0(const int a) { |
| 10 | #pragma omp for |
| 11 | for (int b = 0; b < a; b++) |
| 12 | ; |
| 13 | } |
| 14 | |
| 15 | //----------------------------------------------------------------------------// |
| 16 | // Single-directive positive cases. |
| 17 | //----------------------------------------------------------------------------// |
| 18 | |
| 19 | // 'parallel' directive. |
| 20 | |
| 21 | // 'parallel' directive can have 'default' clause, but said clause is not |
| 22 | // specified, diagnosed. |
| 23 | void p0_0(void) { |
| 24 | #pragma omp parallel |
| 25 | ; |
| 26 | // CHECK-NOTES: :[[@LINE-2]]:1: warning: OpenMP directive 'parallel' does not specify 'default' clause, consider specifying 'default(none)' clause |
| 27 | } |
| 28 | |
| 29 | // 'parallel' directive can have 'default' clause, and said clause specified, |
| 30 | // with 'none' kind, all good. |
| 31 | void p0_1(void) { |
| 32 | #pragma omp parallel default(none) |
| 33 | ; |
| 34 | } |
| 35 | |
| 36 | // 'parallel' directive can have 'default' clause, and said clause specified, |
| 37 | // but with 'shared' kind, which is not 'none', diagnose. |
| 38 | void p0_2(void) { |
| 39 | #pragma omp parallel default(shared) |
| 40 | ; |
| 41 | // CHECK-NOTES: :[[@LINE-2]]:1: warning: OpenMP directive 'parallel' specifies 'default(shared)' clause, consider using 'default(none)' clause instead |
| 42 | // CHECK-NOTES: :[[@LINE-3]]:22: note: existing 'default' clause specified here |
| 43 | } |
| 44 | |
| 45 | // 'parallel' directive can have 'default' clause, and said clause specified, |
| 46 | // but with 'firstprivate' kind, which is not 'none', diagnose. |
| 47 | void p0_3(void) { |
| 48 | #pragma omp parallel default(firstprivate) |
| 49 | ; |
| 50 | // CHECK-NOTES: :[[@LINE-2]]:1: warning: OpenMP directive 'parallel' specifies 'default(firstprivate)' clause, consider using 'default(none)' clause instead |
| 51 | // CHECK-NOTES: :[[@LINE-3]]:22: note: existing 'default' clause specified here |
| 52 | } |
| 53 | |
| 54 | // 'task' directive. |
| 55 | |
| 56 | // 'task' directive can have 'default' clause, but said clause is not |
| 57 | // specified, diagnosed. |
| 58 | void p1_0(void) { |
| 59 | #pragma omp task |
| 60 | ; |
| 61 | // CHECK-NOTES: :[[@LINE-2]]:1: warning: OpenMP directive 'task' does not specify 'default' clause, consider specifying 'default(none)' clause |
| 62 | } |
| 63 | |
| 64 | // 'task' directive can have 'default' clause, and said clause specified, |
| 65 | // with 'none' kind, all good. |
| 66 | void p1_1(void) { |
| 67 | #pragma omp task default(none) |
| 68 | ; |
| 69 | } |
| 70 | |
| 71 | // 'task' directive can have 'default' clause, and said clause specified, |
| 72 | // but with 'shared' kind, which is not 'none', diagnose. |
| 73 | void p1_2(void) { |
| 74 | #pragma omp task default(shared) |
| 75 | ; |
| 76 | // CHECK-NOTES: :[[@LINE-2]]:1: warning: OpenMP directive 'task' specifies 'default(shared)' clause, consider using 'default(none)' clause instead |
| 77 | // CHECK-NOTES: :[[@LINE-3]]:18: note: existing 'default' clause specified here |
| 78 | } |
| 79 | |
| 80 | // 'task' directive can have 'default' clause, and said clause specified, |
| 81 | // but with 'firstprivate' kind, which is not 'none', diagnose. |
| 82 | void p1_3(void) { |
| 83 | #pragma omp task default(firstprivate) |
| 84 | ; |
| 85 | // CHECK-NOTES: :[[@LINE-2]]:1: warning: OpenMP directive 'task' specifies 'default(firstprivate)' clause, consider using 'default(none)' clause instead |
| 86 | // CHECK-NOTES: :[[@LINE-3]]:18: note: existing 'default' clause specified here |
| 87 | } |
| 88 | |
| 89 | // 'teams' directive. (has to be inside of 'target' directive) |
| 90 | |
| 91 | // 'teams' directive can have 'default' clause, but said clause is not |
| 92 | // specified, diagnosed. |
| 93 | void p2_0(void) { |
| 94 | #pragma omp target |
| 95 | #pragma omp teams |
| 96 | ; |
| 97 | // CHECK-NOTES: :[[@LINE-2]]:1: warning: OpenMP directive 'teams' does not specify 'default' clause, consider specifying 'default(none)' clause |
| 98 | } |
| 99 | |
| 100 | // 'teams' directive can have 'default' clause, and said clause specified, |
| 101 | // with 'none' kind, all good. |
| 102 | void p2_1(void) { |
| 103 | #pragma omp target |
| 104 | #pragma omp teams default(none) |
| 105 | ; |
| 106 | } |
| 107 | |
| 108 | // 'teams' directive can have 'default' clause, and said clause specified, |
| 109 | // but with 'shared' kind, which is not 'none', diagnose. |
| 110 | void p2_2(void) { |
| 111 | #pragma omp target |
| 112 | #pragma omp teams default(shared) |
| 113 | ; |
| 114 | // CHECK-NOTES: :[[@LINE-2]]:1: warning: OpenMP directive 'teams' specifies 'default(shared)' clause, consider using 'default(none)' clause instead |
| 115 | // CHECK-NOTES: :[[@LINE-3]]:19: note: existing 'default' clause specified here |
| 116 | } |
| 117 | |
| 118 | // 'teams' directive can have 'default' clause, and said clause specified, |
| 119 | // but with 'firstprivate' kind, which is not 'none', diagnose. |
| 120 | void p2_3(void) { |
| 121 | #pragma omp target |
| 122 | #pragma omp teams default(firstprivate) |
| 123 | ; |
| 124 | // CHECK-NOTES: :[[@LINE-2]]:1: warning: OpenMP directive 'teams' specifies 'default(firstprivate)' clause, consider using 'default(none)' clause instead |
| 125 | // CHECK-NOTES: :[[@LINE-3]]:19: note: existing 'default' clause specified here |
| 126 | } |
| 127 | |
| 128 | // 'taskloop' directive. |
| 129 | |
| 130 | // 'taskloop' directive can have 'default' clause, but said clause is not |
| 131 | // specified, diagnosed. |
| 132 | void p3_0(const int a) { |
| 133 | #pragma omp taskloop |
| 134 | for (int b = 0; b < a; b++) |
| 135 | ; |
| 136 | // CHECK-NOTES: :[[@LINE-3]]:1: warning: OpenMP directive 'taskloop' does not specify 'default' clause, consider specifying 'default(none)' clause |
| 137 | } |
| 138 | |
| 139 | // 'taskloop' directive can have 'default' clause, and said clause specified, |
| 140 | // with 'none' kind, all good. |
| 141 | void p3_1(const int a) { |
| 142 | #pragma omp taskloop default(none) shared(a) |
| 143 | for (int b = 0; b < a; b++) |
| 144 | ; |
| 145 | } |
| 146 | |
| 147 | // 'taskloop' directive can have 'default' clause, and said clause specified, |
| 148 | // but with 'shared' kind, which is not 'none', diagnose. |
| 149 | void p3_2(const int a) { |
| 150 | #pragma omp taskloop default(shared) |
| 151 | for (int b = 0; b < a; b++) |
| 152 | ; |
| 153 | // CHECK-NOTES: :[[@LINE-3]]:1: warning: OpenMP directive 'taskloop' specifies 'default(shared)' clause, consider using 'default(none)' clause instead |
| 154 | // CHECK-NOTES: :[[@LINE-4]]:22: note: existing 'default' clause specified here |
| 155 | } |
| 156 | |
| 157 | // 'taskloop' directive can have 'default' clause, and said clause specified, |
| 158 | // but with 'firstprivate' kind, which is not 'none', diagnose. |
| 159 | void p3_3(const int a) { |
| 160 | #pragma omp taskloop default(firstprivate) |
| 161 | for (int b = 0; b < a; b++) |
| 162 | ; |
| 163 | // CHECK-NOTES: :[[@LINE-3]]:1: warning: OpenMP directive 'taskloop' specifies 'default(firstprivate)' clause, consider using 'default(none)' clause instead |
| 164 | // CHECK-NOTES: :[[@LINE-4]]:22: note: existing 'default' clause specified here |
| 165 | } |
| 166 | |
| 167 | //----------------------------------------------------------------------------// |
| 168 | // Combined directives. |
| 169 | // Let's not test every single possible permutation/combination of directives, |
| 170 | // but just *one* combined directive. The rest will be the same. |
| 171 | //----------------------------------------------------------------------------// |
| 172 | |
| 173 | // 'parallel' directive can have 'default' clause, but said clause is not |
| 174 | // specified, diagnosed. |
| 175 | void p4_0(const int a) { |
| 176 | #pragma omp parallel for |
| 177 | for (int b = 0; b < a; b++) |
| 178 | ; |
| 179 | // CHECK-NOTES: :[[@LINE-3]]:1: warning: OpenMP directive 'parallel for' does not specify 'default' clause, consider specifying 'default(none)' clause |
| 180 | } |
| 181 | |
| 182 | // 'parallel' directive can have 'default' clause, and said clause specified, |
| 183 | // with 'none' kind, all good. |
| 184 | void p4_1(const int a) { |
| 185 | #pragma omp parallel for default(none) shared(a) |
| 186 | for (int b = 0; b < a; b++) |
| 187 | ; |
| 188 | } |
| 189 | |
| 190 | // 'parallel' directive can have 'default' clause, and said clause specified, |
| 191 | // but with 'shared' kind, which is not 'none', diagnose. |
| 192 | void p4_2(const int a) { |
| 193 | #pragma omp parallel for default(shared) |
| 194 | for (int b = 0; b < a; b++) |
| 195 | ; |
| 196 | // CHECK-NOTES: :[[@LINE-3]]:1: warning: OpenMP directive 'parallel for' specifies 'default(shared)' clause, consider using 'default(none)' clause instead |
| 197 | // CHECK-NOTES: :[[@LINE-4]]:26: note: existing 'default' clause specified here |
| 198 | } |
| 199 | |
| 200 | // 'parallel' directive can have 'default' clause, and said clause specified, |
| 201 | // but with 'firstprivate' kind, which is not 'none', diagnose. |
| 202 | void p4_3(const int a) { |
| 203 | #pragma omp parallel for default(firstprivate) |
| 204 | for (int b = 0; b < a; b++) |
| 205 | ; |
| 206 | // CHECK-NOTES: :[[@LINE-3]]:1: warning: OpenMP directive 'parallel for' specifies 'default(firstprivate)' clause, consider using 'default(none)' clause instead |
| 207 | // CHECK-NOTES: :[[@LINE-4]]:26: note: existing 'default' clause specified here |
| 208 | } |
| 209 | |