gcc/testsuite/
        * g++.target/gcn/exceptions-throw-3.C: New.
        * g++.target/nvptx/exceptions-throw-3.C: Likewise.
        libgomp/
        * testsuite/libgomp.c++/target-exceptions-throw-3.C: New.
        * testsuite/libgomp.oacc-c++/exceptions-throw-3.C: Likewise.
---
 .../g++.target/gcn/exceptions-throw-3.C       | 11 +++++
 .../g++.target/nvptx/exceptions-throw-3.C     | 11 +++++
 .../libgomp.c++/target-exceptions-throw-3.C   | 19 ++++++++
 .../libgomp.oacc-c++/exceptions-throw-3.C     | 43 +++++++++++++++++++
 4 files changed, 84 insertions(+)
 create mode 100644 gcc/testsuite/g++.target/gcn/exceptions-throw-3.C
 create mode 100644 gcc/testsuite/g++.target/nvptx/exceptions-throw-3.C
 create mode 100644 libgomp/testsuite/libgomp.c++/target-exceptions-throw-3.C
 create mode 100644 libgomp/testsuite/libgomp.oacc-c++/exceptions-throw-3.C

diff --git a/gcc/testsuite/g++.target/gcn/exceptions-throw-3.C 
b/gcc/testsuite/g++.target/gcn/exceptions-throw-3.C
new file mode 100644
index 00000000000..5c1ad7a8fde
--- /dev/null
+++ b/gcc/testsuite/g++.target/gcn/exceptions-throw-3.C
@@ -0,0 +1,11 @@
+/* 'throw', 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-throw-3.C"
+
+/* { dg-final { scan-tree-dump-times {gimple_call <__cxa_allocate_exception, } 
1 optimized } }
+   { dg-final { scan-tree-dump-times {gimple_call <__cxa_throw, } 1 optimized 
} } */
diff --git a/gcc/testsuite/g++.target/nvptx/exceptions-throw-3.C 
b/gcc/testsuite/g++.target/nvptx/exceptions-throw-3.C
new file mode 100644
index 00000000000..5c1ad7a8fde
--- /dev/null
+++ b/gcc/testsuite/g++.target/nvptx/exceptions-throw-3.C
@@ -0,0 +1,11 @@
+/* 'throw', 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-throw-3.C"
+
+/* { dg-final { scan-tree-dump-times {gimple_call <__cxa_allocate_exception, } 
1 optimized } }
+   { dg-final { scan-tree-dump-times {gimple_call <__cxa_throw, } 1 optimized 
} } */
diff --git a/libgomp/testsuite/libgomp.c++/target-exceptions-throw-3.C 
b/libgomp/testsuite/libgomp.c++/target-exceptions-throw-3.C
new file mode 100644
index 00000000000..c35180de28d
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c++/target-exceptions-throw-3.C
@@ -0,0 +1,19 @@
+/* 'throw' 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-throw-3.C"
+
+/* { dg-final { scan-tree-dump-not {(?n)#pragma omp target .* defaultmap\(to\) 
map\(to:_ZTI11MyException \[len: [0-9]+\] \[runtime_implicit\]\)$} gimple { 
xfail *-*-* } } } */
+
+/* { dg-final { scan-tree-dump-times {gimple_call <__cxa_allocate_exception, } 
1 optimized } }
+   { dg-final { scan-tree-dump-times {gimple_call <__cxa_throw, } 1 optimized 
} }
+   { dg-final { scan-offload-tree-dump-times {gimple_call 
<__cxa_allocate_exception, } 1 optimized } }
+   { dg-final { scan-offload-tree-dump-times {gimple_call <__cxa_throw, } 1 
optimized } } */
diff --git a/libgomp/testsuite/libgomp.oacc-c++/exceptions-throw-3.C 
b/libgomp/testsuite/libgomp.oacc-c++/exceptions-throw-3.C
new file mode 100644
index 00000000000..74a62b3abfa
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-c++/exceptions-throw-3.C
@@ -0,0 +1,43 @@
+/* 'throw' 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-throw-3.C'.  */
+
+/* See also '../../../gcc/testsuite/g++.target/gcn/exceptions-throw-3.C',
+   '../../../gcc/testsuite/g++.target/nvptx/exceptions-throw-3.C'.  */
+
+/* For PR119692 workarounds.  */
+#ifndef DEFAULT
+# define DEFAULT
+#endif
+
+class MyException
+{
+};
+
+int main()
+{
+#pragma omp target DEFAULT
+#pragma acc serial DEFAULT
+  /* { dg-bogus {using 'vector_length \(32\)', ignoring 1} {} { target 
openacc_nvidia_accel_selected xfail *-*-* } .-1 } */
+  {
+    bool a = false;
+    asm volatile ("" : : "r" (&a) : "memory");
+    if (a)
+      {
+       MyException e1;
+       throw e1;
+      }
+  }
+}
+
+/* { dg-final { scan-tree-dump-not {(?n)#pragma omp target oacc_serial 
map\(tofrom:_ZTI11MyException \[len: [0-9]+\]\)$} gimple { xfail *-*-* } } } */
+
+/* { dg-final { scan-tree-dump-times {gimple_call <__cxa_allocate_exception, } 
1 optimized } }
+   { dg-final { scan-tree-dump-times {gimple_call <__cxa_throw, } 1 optimized 
} } */
-- 
2.34.1

Reply via email to