Debian Codegraph @

libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-2.C

raw
1 /* 'std::bad_cast' exception in OpenACC compute region, caught. */
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 /* { dg-bogus {_ZTISt8bad_cast} PR119734 { target openacc_nvidia_accel_selected xfail *-*-* } 0 }
8 { dg-excess-errors {'mkoffload' failure etc.} { xfail openacc_nvidia_accel_selected } } */
9
10 /* See also '../libgomp.c++/target-exceptions-bad_cast-2.C'. */
11
12 /* See also '../../../gcc/testsuite/g++.target/gcn/exceptions-bad_cast-2.C',
13 '../../../gcc/testsuite/g++.target/nvptx/exceptions-bad_cast-2.C'. */
14
15 #include <iostream>
16 #include <typeinfo>
17
18 struct C1
19 {
20 virtual void f()
21 {}
22 };
23
24 struct C2 : C1
25 {
26 };
27
28 int main()
29 {
30 std::cerr << "CheCKpOInT\n";
31 #pragma omp target
32 #pragma acc serial
33 {
34 C1 c1;
35 try
36 {
37 [[maybe_unused]]
38 C2 &c2 = dynamic_cast<C2 &>(c1);
39 /* 'std::bad_cast' is thrown. */
40 }
41 catch (const std::bad_cast &e)
42 {
43 __builtin_printf("caught '%s'\n", e.what());
44 }
45 }
46 }
47
48 /* { dg-output {CheCKpOInT[\r\n]+} }
49
50 { dg-final { scan-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 optimized } }
51 { dg-final { scan-offload-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 optimized } }
52 { dg-output {.*caught 'std::bad_cast'[\r\n]+} { target openacc_host_selected } }
53 For GCN, nvptx offload execution, we don't print anything, but just 'abort'.
54
55 TODO For GCN, nvptx offload execution, this currently doesn't 'abort' due to
56 the 'std::bad_cast' exception, but rather due to SIGSEGV in 'dynamic_cast';
57 PR119692.
58
59 For GCN, nvptx offload execution, there is no 'catch'ing; any exception is fatal.
60 { dg-shouldfail {'std::bad_cast' exception} { ! openacc_host_selected } } */
61 /* There are configurations where we 'WARNING: program timed out.' while in
62 'dynamic_cast', see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119692#c6>.
63 { dg-timeout 10 { target offload_device } } ... to make sure that happens quickly. */