]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add 'std::bad_cast' exception, dead code test cases for GCN, nvptx target and OpenACC...
authorThomas Schwinge <tschwinge@baylibre.com>
Thu, 27 Mar 2025 13:46:20 +0000 (14:46 +0100)
committerThomas Schwinge <tschwinge@baylibre.com>
Mon, 14 Apr 2025 21:54:53 +0000 (23:54 +0200)
gcc/testsuite/
* g++.target/gcn/exceptions-bad_cast-3.C: New.
* g++.target/nvptx/exceptions-bad_cast-3.C: Likewise.
libgomp/
* testsuite/libgomp.c++/target-exceptions-bad_cast-3.C: New.
* testsuite/libgomp.oacc-c++/exceptions-bad_cast-3.C: Likewise.

gcc/testsuite/g++.target/gcn/exceptions-bad_cast-3.C [new file with mode: 0644]
gcc/testsuite/g++.target/nvptx/exceptions-bad_cast-3.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c++/target-exceptions-bad_cast-3.C [new file with mode: 0644]
libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-3.C [new file with mode: 0644]

diff --git a/gcc/testsuite/g++.target/gcn/exceptions-bad_cast-3.C b/gcc/testsuite/g++.target/gcn/exceptions-bad_cast-3.C
new file mode 100644 (file)
index 0000000..3d0118c
--- /dev/null
@@ -0,0 +1,10 @@
+/* 'std::bad_cast' exception, dead code.  */
+
+/* { dg-do run } */
+/* 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-3.C"
+
+/* { dg-final { scan-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 optimized } } */
diff --git a/gcc/testsuite/g++.target/nvptx/exceptions-bad_cast-3.C b/gcc/testsuite/g++.target/nvptx/exceptions-bad_cast-3.C
new file mode 100644 (file)
index 0000000..3d0118c
--- /dev/null
@@ -0,0 +1,10 @@
+/* 'std::bad_cast' exception, dead code.  */
+
+/* { dg-do run } */
+/* 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-3.C"
+
+/* { dg-final { scan-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 optimized } } */
diff --git a/libgomp/testsuite/libgomp.c++/target-exceptions-bad_cast-3.C b/libgomp/testsuite/libgomp.c++/target-exceptions-bad_cast-3.C
new file mode 100644 (file)
index 0000000..efed64f
--- /dev/null
@@ -0,0 +1,17 @@
+/* 'std::bad_cast' exception in OpenMP 'target' region, dead code.  */
+
+/* { dg-require-effective-target exceptions }
+   { dg-additional-options -fexceptions } */
+/* { dg-additional-options -DDEFAULT=defaultmap(to) }
+   ... to avoid wrong code for offloading execution; PR119692.
+   With this, the device code still isn't correct, but the defects are in dead code.
+   { dg-additional-options -fdump-tree-gimple } */
+/* { dg-additional-options -fdump-tree-optimized-raw }
+   { dg-additional-options -foffload-options=-fdump-tree-optimized-raw } */
+
+#include "../libgomp.oacc-c++/exceptions-bad_cast-3.C"
+
+/* { dg-final { scan-tree-dump-not {(?n)#pragma omp target .* defaultmap\(to\) map\(to:_ZTI2C2 \[len: [0-9]+\] \[runtime_implicit\]\) map\(to:_ZTI2C1 \[len: [0-9]+\] \[runtime_implicit\]\) map\(to:_ZTV2C1 \[len: [0-9]+\] \[runtime_implicit\]\)$} gimple { xfail *-*-* } } } */
+
+/* { dg-final { scan-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 optimized } }
+   { dg-final { scan-offload-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 optimized } } */
diff --git a/libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-3.C b/libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-3.C
new file mode 100644 (file)
index 0000000..4fa419f
--- /dev/null
@@ -0,0 +1,49 @@
+/* 'std::bad_cast' exception in OpenACC compute region, dead code.  */
+
+/* { dg-require-effective-target exceptions }
+   { dg-additional-options -fexceptions } */
+/* Wrong code for offloading execution.
+   { dg-skip-if PR119692 { ! openacc_host_selected } }
+   { dg-additional-options -fdump-tree-gimple } */
+/* { dg-additional-options -fdump-tree-optimized-raw } */
+
+/* See also '../libgomp.c++/target-exceptions-bad_cast-3.C'.  */
+
+/* See also '../../../gcc/testsuite/g++.target/gcn/exceptions-bad_cast-3.C',
+   '../../../gcc/testsuite/g++.target/nvptx/exceptions-bad_cast-3.C'.  */
+
+/* For PR119692 workarounds.  */
+#ifndef DEFAULT
+# define DEFAULT
+#endif
+
+struct C1
+{
+  virtual void f()
+  {}
+};
+
+struct C2 : C1
+{
+};
+
+int main()
+{
+#pragma omp target DEFAULT
+#pragma acc serial DEFAULT
+  {
+    C1 c1;
+    bool a = false;
+    asm volatile ("" : : "r" (&a) : "memory");
+    if (a)
+      {
+       [[maybe_unused]]
+       C2 &c2 = dynamic_cast<C2 &>(c1);
+       /* 'std::bad_cast' is thrown.  */
+      }
+  }
+}
+
+/* { dg-final { scan-tree-dump-not {(?n)#pragma omp target oacc_serial map\(tofrom:_ZTI2C2 \[len: [0-9]+\]\) map\(tofrom:_ZTI2C1 \[len: [0-9]+\]\) map\(tofrom:_ZTV2C1 \[len: [0-9]+\]\)$} gimple { xfail *-*-* } } } */
+
+/* { dg-final { scan-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 optimized } } */