brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · 200123a Raw
133 lines · cpp
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 3int thrower() {4  throw 42;5}6 7class ignored {};8class ignored2 {};9namespace std {10class bad_alloc {};11} // namespace std12 13void parallel() {14#pragma omp parallel15  thrower();16  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: an exception thrown inside of the OpenMP 'parallel' region is not caught in that same region17}18 19void ignore() {20#pragma omp parallel21  throw ignored();22}23 24void ignore2() {25#pragma omp parallel26  throw ignored2();27}28 29void standalone_directive() {30#pragma omp taskwait31  throw ignored(); // not structured block32}33 34void ignore_alloc() {35#pragma omp parallel36  throw std::bad_alloc();37}38 39void parallel_caught() {40#pragma omp parallel41  {42    try {43      thrower();44    } catch (...) {45    }46  }47}48 49void for_header(const int a) {50  // Only the body of the loop counts.51#pragma omp for52  for (int i = 0; i < thrower(); i++)53    ;54}55 56void forloop(const int a) {57#pragma omp for58  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 region61}62 63void parallel_forloop(const int a) {64#pragma omp parallel65  {66#pragma omp for67    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 region71    // CHECK-MESSAGES: :[[@LINE-3]]:7: warning: an exception thrown inside of the OpenMP 'for' region is not caught in that same region72  }73}74 75void parallel_forloop_caught(const int a) {76#pragma omp parallel77  {78#pragma omp for79    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 region87  }88}89 90void parallel_caught_forloop(const int a) {91#pragma omp parallel92  {93#pragma omp for94    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 region101  }102}103 104void parallel_outercaught_forloop(const int a) {105#pragma omp parallel106  {107    try {108#pragma omp for109      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 region115  }116}117 118void parallel_outercaught_forloop_caught(const int a) {119#pragma omp parallel120  {121    try {122#pragma omp for123      for (int i = 0; i < a; i++) {124        try {125          thrower();126        } catch (...) {127        }128      }129    } catch (...) {130    }131  }132}133