| 1 | // RUN: %check_clang_tidy %s openmp-exception-escape %t -- -extra-arg=-fopenmp=libomp -extra-arg=-fexceptions -config="{CheckOptions: {openmp-exception-escape.IgnoredExceptions: 'ignored, ignored2'}}" -- |
| 2 | |
| 3 | int thrower() { |
| 4 | throw 42; |
| 5 | } |
| 6 | |
| 7 | class ignored {}; |
| 8 | class ignored2 {}; |
| 9 | namespace std { |
| 10 | class bad_alloc {}; |
| 11 | } // namespace std |
| 12 | |
| 13 | void parallel() { |
| 14 | #pragma omp parallel |
| 15 | thrower(); |
| 16 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: an exception thrown inside of the OpenMP 'parallel' region is not caught in that same region |
| 17 | } |
| 18 | |
| 19 | void ignore() { |
| 20 | #pragma omp parallel |
| 21 | throw ignored(); |
| 22 | } |
| 23 | |
| 24 | void ignore2() { |
| 25 | #pragma omp parallel |
| 26 | throw ignored2(); |
| 27 | } |
| 28 | |
| 29 | void standalone_directive() { |
| 30 | #pragma omp taskwait |
| 31 | throw ignored(); // not structured block |
| 32 | } |
| 33 | |
| 34 | void ignore_alloc() { |
| 35 | #pragma omp parallel |
| 36 | throw std::bad_alloc(); |
| 37 | } |
| 38 | |
| 39 | void parallel_caught() { |
| 40 | #pragma omp parallel |
| 41 | { |
| 42 | try { |
| 43 | thrower(); |
| 44 | } catch (...) { |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | void (const int a) { |
| 50 | // Only the body of the loop counts. |
| 51 | #pragma omp for |
| 52 | for (int i = 0; i < thrower(); i++) |
| 53 | ; |
| 54 | } |
| 55 | |
| 56 | void forloop(const int a) { |
| 57 | #pragma omp for |
| 58 | for (int i = 0; i < a; i++) |
| 59 | thrower(); |
| 60 | // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception thrown inside of the OpenMP 'for' region is not caught in that same region |
| 61 | } |
| 62 | |
| 63 | void parallel_forloop(const int a) { |
| 64 | #pragma omp parallel |
| 65 | { |
| 66 | #pragma omp for |
| 67 | for (int i = 0; i < a; i++) |
| 68 | thrower(); |
| 69 | thrower(); |
| 70 | // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: an exception thrown inside of the OpenMP 'parallel' region is not caught in that same region |
| 71 | // CHECK-MESSAGES: :[[@LINE-3]]:7: warning: an exception thrown inside of the OpenMP 'for' region is not caught in that same region |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | void parallel_forloop_caught(const int a) { |
| 76 | #pragma omp parallel |
| 77 | { |
| 78 | #pragma omp for |
| 79 | for (int i = 0; i < a; i++) { |
| 80 | try { |
| 81 | thrower(); |
| 82 | } catch (...) { |
| 83 | } |
| 84 | } |
| 85 | thrower(); |
| 86 | // CHECK-MESSAGES: :[[@LINE-9]]:3: warning: an exception thrown inside of the OpenMP 'parallel' region is not caught in that same region |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | void parallel_caught_forloop(const int a) { |
| 91 | #pragma omp parallel |
| 92 | { |
| 93 | #pragma omp for |
| 94 | for (int i = 0; i < a; i++) |
| 95 | thrower(); |
| 96 | try { |
| 97 | thrower(); |
| 98 | } catch (...) { |
| 99 | } |
| 100 | // CHECK-MESSAGES: :[[@LINE-5]]:7: warning: an exception thrown inside of the OpenMP 'for' region is not caught in that same region |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | void parallel_outercaught_forloop(const int a) { |
| 105 | #pragma omp parallel |
| 106 | { |
| 107 | try { |
| 108 | #pragma omp for |
| 109 | for (int i = 0; i < a; i++) |
| 110 | thrower(); |
| 111 | thrower(); |
| 112 | } catch (...) { |
| 113 | } |
| 114 | // CHECK-MESSAGES: :[[@LINE-4]]:9: warning: an exception thrown inside of the OpenMP 'for' region is not caught in that same region |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | void parallel_outercaught_forloop_caught(const int a) { |
| 119 | #pragma omp parallel |
| 120 | { |
| 121 | try { |
| 122 | #pragma omp for |
| 123 | for (int i = 0; i < a; i++) { |
| 124 | try { |
| 125 | thrower(); |
| 126 | } catch (...) { |
| 127 | } |
| 128 | } |
| 129 | } catch (...) { |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |