https://gcc.gnu.org/g:ad51cb1221fdddb246b421e6529e5af7524a15de

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

    Add 'throw', dead code test cases for GCN, nvptx target and OpenACC, OpenMP 
'target' offloading
    
            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.
    
    (cherry picked from commit 6c0ea840265454b01d9ef4eb8850a4f015788788)

Diff:
---
 gcc/testsuite/ChangeLog.omp                        |  6 +++
 gcc/testsuite/g++.target/gcn/exceptions-throw-3.C  | 11 ++++++
 .../g++.target/nvptx/exceptions-throw-3.C          | 11 ++++++
 libgomp/ChangeLog.omp                              |  6 +++
 .../libgomp.c++/target-exceptions-throw-3.C        | 19 ++++++++++
 .../libgomp.oacc-c++/exceptions-throw-3.C          | 43 ++++++++++++++++++++++
 6 files changed, 96 insertions(+)

diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 677f7d190b08..a0abef706bd0 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -3,6 +3,12 @@
        Backported from trunk:
        2025-04-14  Thomas Schwinge  <tschwi...@baylibre.com>
 
+       * g++.target/gcn/exceptions-throw-3.C: New.
+       * g++.target/nvptx/exceptions-throw-3.C: Likewise.
+
+       Backported from trunk:
+       2025-04-14  Thomas Schwinge  <tschwi...@baylibre.com>
+
        * g++.target/gcn/exceptions-throw-2.C: New.
        * g++.target/nvptx/exceptions-throw-2.C: Likewise.
 
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 000000000000..5c1ad7a8fde4
--- /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 000000000000..5c1ad7a8fde4
--- /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/ChangeLog.omp b/libgomp/ChangeLog.omp
index acd9dac9cb89..8965de690745 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -3,6 +3,12 @@
        Backported from trunk:
        2025-04-14  Thomas Schwinge  <tschwi...@baylibre.com>
 
+       * testsuite/libgomp.c++/target-exceptions-throw-3.C: New.
+       * testsuite/libgomp.oacc-c++/exceptions-throw-3.C: Likewise.
+
+       Backported from trunk:
+       2025-04-14  Thomas Schwinge  <tschwi...@baylibre.com>
+
        * testsuite/libgomp.c++/target-exceptions-throw-2.C: New.
        * testsuite/libgomp.c++/target-exceptions-throw-2-offload-sorry-GCN.C: 
Likewise.
        * 
testsuite/libgomp.c++/target-exceptions-throw-2-offload-sorry-nvptx.C: Likewise.
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 000000000000..c35180de28d3
--- /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 000000000000..74a62b3abfac
--- /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 
} } */

Reply via email to