| 1 |
/* 'std::bad_cast' exception in OpenACC compute region. */ |
| 2 |
|
| 3 |
/* { dg-require-effective-target exceptions } |
| 4 |
{ dg-additional-options -fexceptions } */ |
| 5 |
/* { dg-additional-options -fdump-tree-optimized-raw } |
| 6 |
{ dg-additional-options -foffload-options=-fdump-tree-optimized-raw } */ |
| 7 |
|
| 8 |
/* See also '../libgomp.c++/target-exceptions-bad_cast-1.C'. */ |
| 9 |
|
| 10 |
/* See also '../../../gcc/testsuite/g++.target/gcn/exceptions-bad_cast-1.C', |
| 11 |
'../../../gcc/testsuite/g++.target/nvptx/exceptions-bad_cast-1.C'. */ |
| 12 |
|
| 13 |
#include <iostream> |
| 14 |
|
| 15 |
struct C1 |
| 16 |
{ |
| 17 |
virtual void f() |
| 18 |
{} |
| 19 |
}; |
| 20 |
|
| 21 |
struct C2 : C1 |
| 22 |
{ |
| 23 |
}; |
| 24 |
|
| 25 |
int main() |
| 26 |
{ |
| 27 |
std::cerr << "CheCKpOInT\n"; |
| 28 |
#pragma omp target |
| 29 |
#pragma acc serial |
| 30 |
/* { dg-bogus {using 'vector_length \(32\)', ignoring 1} {} { target openacc_nvidia_accel_selected xfail *-*-* } .-1 } */ |
| 31 |
{ |
| 32 |
C1 c1; |
| 33 |
[[maybe_unused]] |
| 34 |
C2 &c2 = dynamic_cast<C2 &>(c1); |
| 35 |
/* 'std::bad_cast' is thrown. */ |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
/* { dg-output {CheCKpOInT[\r\n]+} } |
| 40 |
|
| 41 |
{ dg-final { scan-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 optimized } } |
| 42 |
{ dg-final { scan-offload-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 optimized } } |
| 43 |
For host execution, we print something like: |
| 44 |
terminate called after throwing an instance of 'std::bad_cast' |
| 45 |
what(): std::bad_cast |
| 46 |
Aborted (core dumped) |
| 47 |
{ dg-output {.*std::bad_cast} { target openacc_host_selected } } |
| 48 |
For GCN, nvptx offload execution, we don't print anything, but just 'abort'. |
| 49 |
|
| 50 |
TODO For GCN, nvptx offload execution, this currently doesn't 'abort' due to |
| 51 |
the 'std::bad_cast' exception, but rather due to SIGSEGV in 'dynamic_cast'; |
| 52 |
PR119692. |
| 53 |
|
| 54 |
{ dg-shouldfail {'std::bad_cast' exception} } */ |
| 55 |
/* There are configurations where we 'WARNING: program timed out.' while in |
| 56 |
'dynamic_cast', see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119692#c6>. |
| 57 |
{ dg-timeout 10 { target offload_device } } ... to make sure that happens quickly. */ |