Issue 71572
Summary [OpenMP] No warnings emitted when an exception is thrown in a lambda inside a target region
Labels openmp
Assignees
Reporter AntonRydahl
    I have found a bug that most likely has been introduced by myself. In the early summer we changed the way exceptions are handled in OpenMP offloading. Before, we would error out if the target code contained exception handling, and now we emit the code for the try statement and emit a trap instruction for the throw _expression_. In addition, we print warnings.

For exception handling directly embedded in target regions, and for functions declared target, we get warnings as expected. For instance, compiling the following example
```C++
void foo(double * a){
    try {
 throw 3;
    }
    catch (int e) {
        *a = e;
 }
}
#pragma omp declare target indirect to(foo)

int main(int, char**) {
  #pragma omp target
  {
    double ab = 1;
 foo(&ab);
  }
  return 0;
}
```
gives the warnings
```
warning: target 'amdgcn-amd-amdhsa' does not support exception handling; 'throw' is assumed to be never reached [-Wopenmp-target-exception]
    3 |         throw 3;
      | ^
warning: target 'amdgcn-amd-amdhsa' does not support exception handling; 'catch' block is ignored [-Wopenmp-target-exception]
    2 |     try {
```
However, the following example does not produce a warning:
```C++
int main(int, char**) {
  // lambda that throws an exception
  auto lam = [](double& n){
    try {
        throw 3;
 }
    catch (int e) {
        n = e;
    }
  };

 #pragma omp target
  {
    double ab = 1;
    lam(ab);
  }
 return 0;
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to