https://gcc.gnu.org/g:00cde164eeb834958ae8f9eec0c7c9cc3ac697a1

commit r15-9465-g00cde164eeb834958ae8f9eec0c7c9cc3ac697a1
Author: Thomas Schwinge <tschwi...@baylibre.com>
Date:   Thu Mar 27 14:46:20 2025 +0100

    Add 'std::bad_cast' exception, caught test cases for GCN, nvptx target and 
OpenACC, OpenMP 'target' offloading
    
            gcc/testsuite/
            * g++.target/gcn/exceptions-bad_cast-2.C: New.
            * g++.target/nvptx/exceptions-bad_cast-2.C: Likewise.
            libgomp/
            * testsuite/libgomp.c++/target-exceptions-bad_cast-2.C: New.
            * 
testsuite/libgomp.c++/target-exceptions-bad_cast-2-offload-sorry-GCN.C: 
Likewise.
            * 
testsuite/libgomp.c++/target-exceptions-bad_cast-2-offload-sorry-nvptx.C: 
Likewise.
            * testsuite/libgomp.oacc-c++/exceptions-bad_cast-2.C: Likewise.
            * 
testsuite/libgomp.oacc-c++/exceptions-bad_cast-2-offload-sorry-GCN.C: Likewise.
            * 
testsuite/libgomp.oacc-c++/exceptions-bad_cast-2-offload-sorry-nvptx.C: 
Likewise.

Diff:
---
 .../g++.target/gcn/exceptions-bad_cast-2.C         | 12 ++++++
 .../g++.target/nvptx/exceptions-bad_cast-2.C       | 12 ++++++
 ...arget-exceptions-bad_cast-2-offload-sorry-GCN.C | 18 ++++++++
 ...get-exceptions-bad_cast-2-offload-sorry-nvptx.C | 18 ++++++++
 .../libgomp.c++/target-exceptions-bad_cast-2.C     | 14 +++++++
 .../exceptions-bad_cast-2-offload-sorry-GCN.C      | 17 ++++++++
 .../exceptions-bad_cast-2-offload-sorry-nvptx.C    | 19 +++++++++
 .../libgomp.oacc-c++/exceptions-bad_cast-2.C       | 48 ++++++++++++++++++++++
 8 files changed, 158 insertions(+)

diff --git a/gcc/testsuite/g++.target/gcn/exceptions-bad_cast-2.C 
b/gcc/testsuite/g++.target/gcn/exceptions-bad_cast-2.C
new file mode 100644
index 000000000000..ffe9e19a281e
--- /dev/null
+++ b/gcc/testsuite/g++.target/gcn/exceptions-bad_cast-2.C
@@ -0,0 +1,12 @@
+/* 'std::bad_cast' exception, caught.  */
+
+/* Via the magic string "-std=*++" indicate that testing one (the default) C++ 
standard is sufficient.  */
+/* { dg-additional-options -fexceptions } */
+/* { dg-additional-options -fdump-tree-optimized-raw } */
+
+#include 
"../../../../libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-2.C"
+
+/* { dg-final { scan-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 
optimized } }
+   Compilation fails:
+   { dg-regexp {[^\r\n]+: In function 'int main\(\)':[\r\n]+(?:[^\r\n]+: 
sorry, unimplemented: exception handling not supported[\r\n]+)+} }
+   (Note, using 'dg-regexp' instead of 'dg-message', as the former runs before 
the auto-mark-UNSUPPORTED.)  */
diff --git a/gcc/testsuite/g++.target/nvptx/exceptions-bad_cast-2.C 
b/gcc/testsuite/g++.target/nvptx/exceptions-bad_cast-2.C
new file mode 100644
index 000000000000..ffe9e19a281e
--- /dev/null
+++ b/gcc/testsuite/g++.target/nvptx/exceptions-bad_cast-2.C
@@ -0,0 +1,12 @@
+/* 'std::bad_cast' exception, caught.  */
+
+/* Via the magic string "-std=*++" indicate that testing one (the default) C++ 
standard is sufficient.  */
+/* { dg-additional-options -fexceptions } */
+/* { dg-additional-options -fdump-tree-optimized-raw } */
+
+#include 
"../../../../libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-2.C"
+
+/* { dg-final { scan-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 
optimized } }
+   Compilation fails:
+   { dg-regexp {[^\r\n]+: In function 'int main\(\)':[\r\n]+(?:[^\r\n]+: 
sorry, unimplemented: exception handling not supported[\r\n]+)+} }
+   (Note, using 'dg-regexp' instead of 'dg-message', as the former runs before 
the auto-mark-UNSUPPORTED.)  */
diff --git 
a/libgomp/testsuite/libgomp.c++/target-exceptions-bad_cast-2-offload-sorry-GCN.C
 
b/libgomp/testsuite/libgomp.c++/target-exceptions-bad_cast-2-offload-sorry-GCN.C
new file mode 100644
index 000000000000..ed670a80fb63
--- /dev/null
+++ 
b/libgomp/testsuite/libgomp.c++/target-exceptions-bad_cast-2-offload-sorry-GCN.C
@@ -0,0 +1,18 @@
+/* 'std::bad_cast' exception in OpenMP 'target' region, caught.  */
+
+/* As this test case involves an expected offload compilation failure, we have 
to handle each offload target individually.
+   { dg-do link { target offload_target_amdgcn } }
+   { dg-additional-options -foffload=amdgcn-amdhsa } */
+/* { dg-require-effective-target exceptions }
+   { dg-additional-options -fexceptions } */
+/* { dg-additional-options -fdump-tree-optimized-raw }
+   { dg-additional-options -foffload-options=-fdump-tree-optimized-raw } */
+
+#include "target-exceptions-bad_cast-2.C"
+
+/* { dg-final { scan-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 
optimized } }
+   { dg-final { only_for_offload_target amdgcn-amdhsa 
scan-offload-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 optimized } }
+   Offload compilation fails:
+   { dg-regexp {[^\r\n]+: In function 'main[^']+':[\r\n]+(?:[^\r\n]+: sorry, 
unimplemented: exception handling not supported[\r\n]+)+} }
+   (Note, using 'dg-regexp' instead of 'dg-message', as the former runs before 
the auto-mark-UNSUPPORTED.)
+   { dg-excess-errors {'mkoffload' failure etc.} } */
diff --git 
a/libgomp/testsuite/libgomp.c++/target-exceptions-bad_cast-2-offload-sorry-nvptx.C
 
b/libgomp/testsuite/libgomp.c++/target-exceptions-bad_cast-2-offload-sorry-nvptx.C
new file mode 100644
index 000000000000..84506304f121
--- /dev/null
+++ 
b/libgomp/testsuite/libgomp.c++/target-exceptions-bad_cast-2-offload-sorry-nvptx.C
@@ -0,0 +1,18 @@
+/* 'std::bad_cast' exception in OpenMP 'target' region, caught.  */
+
+/* As this test case involves an expected offload compilation failure, we have 
to handle each offload target individually.
+   { dg-do link { target offload_target_nvptx } }
+   { dg-additional-options -foffload=nvptx-none } */
+/* { dg-require-effective-target exceptions }
+   { dg-additional-options -fexceptions } */
+/* { dg-additional-options -fdump-tree-optimized-raw }
+   { dg-additional-options -foffload-options=-fdump-tree-optimized-raw } */
+
+#include "target-exceptions-bad_cast-2.C"
+
+/* { dg-final { scan-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 
optimized } }
+   { dg-final { only_for_offload_target nvptx-none 
scan-offload-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 optimized } }
+   Offload compilation fails:
+   { dg-regexp {[^\r\n]+: In function 'main[^']+':[\r\n]+(?:[^\r\n]+: sorry, 
unimplemented: exception handling not supported[\r\n]+)+} }
+   (Note, using 'dg-regexp' instead of 'dg-message', as the former runs before 
the auto-mark-UNSUPPORTED.)
+   { dg-excess-errors {'mkoffload' failure etc.} } */
diff --git a/libgomp/testsuite/libgomp.c++/target-exceptions-bad_cast-2.C 
b/libgomp/testsuite/libgomp.c++/target-exceptions-bad_cast-2.C
new file mode 100644
index 000000000000..26decf60055d
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c++/target-exceptions-bad_cast-2.C
@@ -0,0 +1,14 @@
+/* 'std::bad_cast' exception in OpenMP 'target' region, caught.  */
+
+/* { dg-require-effective-target exceptions }
+   { dg-additional-options -fexceptions } */
+/* { dg-additional-options -foffload=disable }
+   Offloading compilation not yet supported; see
+   'target-exceptions-bad_cast-2-offload-sorry-GCN.C',
+   'target-exceptions-bad_cast-2-offload-sorry-nvptx.C'.  */
+/* { dg-additional-options -fdump-tree-optimized-raw } */
+
+#include "../libgomp.oacc-c++/exceptions-bad_cast-2.C"
+
+/* { dg-final { scan-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 
optimized } }
+   { dg-output {caught 'std::bad_cast'[\r\n]+} } */
diff --git 
a/libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-2-offload-sorry-GCN.C 
b/libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-2-offload-sorry-GCN.C
new file mode 100644
index 000000000000..ba6812f9b078
--- /dev/null
+++ 
b/libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-2-offload-sorry-GCN.C
@@ -0,0 +1,17 @@
+/* 'std::bad_cast' exception in OpenACC compute region, caught.  */
+
+/* As this test case involves an expected offload compilation failure, we have 
to handle each offload target individually.
+   { dg-do link { target openacc_radeon_accel_selected } } */
+/* { dg-require-effective-target exceptions }
+   { dg-additional-options -fexceptions } */
+/* { dg-additional-options -fdump-tree-optimized-raw }
+   { dg-additional-options -foffload-options=-fdump-tree-optimized-raw } */
+
+#include "exceptions-bad_cast-2.C"
+
+/* { dg-final { scan-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 
optimized } }
+   { dg-final { only_for_offload_target amdgcn-amdhsa 
scan-offload-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 optimized } }
+   Offload compilation fails:
+   { dg-regexp {[^\r\n]+: In function 'main[^']+':[\r\n]+(?:[^\r\n]+: sorry, 
unimplemented: exception handling not supported[\r\n]+)+} }
+   (Note, using 'dg-regexp' instead of 'dg-message', as the former runs before 
the auto-mark-UNSUPPORTED.)
+   { dg-excess-errors {'mkoffload' failure etc.} } */
diff --git 
a/libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-2-offload-sorry-nvptx.C
 
b/libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-2-offload-sorry-nvptx.C
new file mode 100644
index 000000000000..563f31727ad3
--- /dev/null
+++ 
b/libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-2-offload-sorry-nvptx.C
@@ -0,0 +1,19 @@
+/* 'std::bad_cast' exception in OpenACC compute region, caught.  */
+
+/* As this test case involves an expected offload compilation failure, we have 
to handle each offload target individually.
+   { dg-do link { target openacc_nvidia_accel_selected } } */
+/* { dg-require-effective-target exceptions }
+   { dg-additional-options -fexceptions } */
+/* { dg-additional-options -fdump-tree-optimized-raw }
+   { dg-additional-options -foffload-options=-fdump-tree-optimized-raw } */
+
+#include "exceptions-bad_cast-2.C"
+
+/* { dg-bogus {using 'vector_length \(32\)', ignoring 1} {} { target 
openacc_nvidia_accel_selected xfail *-*-* } 0 } */
+
+/* { dg-final { scan-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 
optimized } }
+   { dg-final { only_for_offload_target nvptx-none 
scan-offload-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 optimized } }
+   Offload compilation fails:
+   { dg-regexp {[^\r\n]+: In function 'main[^']+':[\r\n]+(?:[^\r\n]+: sorry, 
unimplemented: exception handling not supported[\r\n]+)+} }
+   (Note, using 'dg-regexp' instead of 'dg-message', as the former runs before 
the auto-mark-UNSUPPORTED.)
+   { dg-excess-errors {'mkoffload' failure etc.} } */
diff --git a/libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-2.C 
b/libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-2.C
new file mode 100644
index 000000000000..5f79d63f3826
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-2.C
@@ -0,0 +1,48 @@
+/* 'std::bad_cast' exception in OpenACC compute region, caught.  */
+
+/* { dg-require-effective-target exceptions }
+   { dg-additional-options -fexceptions } */
+/* { dg-skip-if {} { ! openacc_host_selected } }
+   Offloading compilation not yet supported; see
+   'exceptions-bad_cast-2-offload-sorry-GCN.C',
+   'exceptions-bad_cast-2-offload-sorry-nvptx.C'.  */
+/* { dg-additional-options -fdump-tree-optimized-raw } */
+
+/* See also '../libgomp.c++/target-exceptions-bad_cast-2.C'.  */
+
+/* See also '../../../gcc/testsuite/g++.target/gcn/exceptions-bad_cast-2.C',
+   '../../../gcc/testsuite/g++.target/nvptx/exceptions-bad_cast-2.C'.  */
+
+#include <typeinfo>
+
+struct C1
+{
+  virtual void f()
+  {}
+};
+
+struct C2 : C1
+{
+};
+
+int main()
+{
+#pragma omp target
+#pragma acc serial
+  {
+    C1 c1;
+    try
+      {
+       [[maybe_unused]]
+       C2 &c2 = dynamic_cast<C2 &>(c1);
+       /* 'std::bad_cast' is thrown.  */
+      }
+    catch (const std::bad_cast &e)
+      {
+       __builtin_printf("caught '%s'\n", e.what());
+      }
+  }
+}
+
+/* { dg-final { scan-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 
optimized } }
+   { dg-output {caught 'std::bad_cast'[\r\n]+} } */

Reply via email to