https://gcc.gnu.org/g:95219213053cc0d6111230f196f961f21026b799

commit 95219213053cc0d6111230f196f961f21026b799
Author: Thomas Schwinge <tschwi...@baylibre.com>
Date:   Thu Mar 27 23:06:37 2025 +0100

    Add test cases for exception handling constructs in dead code for GCN, 
nvptx target and OpenMP 'target' offloading [PR118794]
    
            PR target/118794
            gcc/testsuite/
            * g++.target/gcn/exceptions-pr118794-1.C: New.
            * g++.target/nvptx/exceptions-pr118794-1.C: Likewise.
            libgomp/
            * testsuite/libgomp.c++/target-exceptions-pr118794-1.C: New.
            * 
testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-GCN.C:
            Likewise.
            * 
testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-nvptx.C:
            Likewise.
    
    (cherry picked from commit aa3e72f943032e5f074b2bd2fd06d130dda8760b)

Diff:
---
 gcc/testsuite/ChangeLog.omp                        |  7 +++
 .../g++.target/gcn/exceptions-pr118794-1.C         | 16 ++++++
 .../g++.target/nvptx/exceptions-pr118794-1.C       | 16 ++++++
 libgomp/ChangeLog.omp                              | 10 ++++
 ...arget-exceptions-pr118794-1-offload-sorry-GCN.C | 23 +++++++++
 ...get-exceptions-pr118794-1-offload-sorry-nvptx.C | 23 +++++++++
 .../libgomp.c++/target-exceptions-pr118794-1.C     | 58 ++++++++++++++++++++++
 7 files changed, 153 insertions(+)

diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 3cdde0e8ac39..7a295230e79a 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -3,6 +3,13 @@
        Backported from trunk:
        2025-04-14  Thomas Schwinge  <tschwi...@baylibre.com>
 
+       PR target/118794
+       * g++.target/gcn/exceptions-pr118794-1.C: New.
+       * g++.target/nvptx/exceptions-pr118794-1.C: Likewise.
+
+       Backported from trunk:
+       2025-04-14  Thomas Schwinge  <tschwi...@baylibre.com>
+
        PR c++/119692
        * g++.target/gcn/pr119692-1-1.C: New.
        * g++.target/nvptx/pr119692-1-1.C: Likewise.
diff --git a/gcc/testsuite/g++.target/gcn/exceptions-pr118794-1.C 
b/gcc/testsuite/g++.target/gcn/exceptions-pr118794-1.C
new file mode 100644
index 000000000000..a7013791511d
--- /dev/null
+++ b/gcc/testsuite/g++.target/gcn/exceptions-pr118794-1.C
@@ -0,0 +1,16 @@
+/* Exception handling constructs in dead code.  */
+
+/* Via the magic string "-std=*++" indicate that testing one (the default) C++ 
standard is sufficient.  */
+/* { dg-additional-options -fexceptions } */
+/* { dg-additional-options -O0 } */
+/* { dg-additional-options -fdump-tree-optimized-raw } */
+
+#include 
"../../../../libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1.C"
+
+/* In this specific C++ arrangement, distilled from PR118794, GCC synthesizes
+   '__builtin_eh_pointer', '__builtin_unwind_resume' calls as dead code in 'f':
+   { dg-final { scan-tree-dump-times {gimple_call <__builtin_eh_pointer, } 1 
optimized } }
+   { dg-final { scan-tree-dump-times {gimple_call <__builtin_unwind_resume, } 
1 optimized } }
+   Given '-O0', compilation fails:
+   { dg-regexp {[^\r\n]+: In function 'void f\(\)':[\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-pr118794-1.C 
b/gcc/testsuite/g++.target/nvptx/exceptions-pr118794-1.C
new file mode 100644
index 000000000000..a7013791511d
--- /dev/null
+++ b/gcc/testsuite/g++.target/nvptx/exceptions-pr118794-1.C
@@ -0,0 +1,16 @@
+/* Exception handling constructs in dead code.  */
+
+/* Via the magic string "-std=*++" indicate that testing one (the default) C++ 
standard is sufficient.  */
+/* { dg-additional-options -fexceptions } */
+/* { dg-additional-options -O0 } */
+/* { dg-additional-options -fdump-tree-optimized-raw } */
+
+#include 
"../../../../libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1.C"
+
+/* In this specific C++ arrangement, distilled from PR118794, GCC synthesizes
+   '__builtin_eh_pointer', '__builtin_unwind_resume' calls as dead code in 'f':
+   { dg-final { scan-tree-dump-times {gimple_call <__builtin_eh_pointer, } 1 
optimized } }
+   { dg-final { scan-tree-dump-times {gimple_call <__builtin_unwind_resume, } 
1 optimized } }
+   Given '-O0', compilation fails:
+   { dg-regexp {[^\r\n]+: In function 'void f\(\)':[\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/ChangeLog.omp b/libgomp/ChangeLog.omp
index 80578d93d800..a0fdd14aaf3c 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -3,6 +3,16 @@
        Backported from trunk:
        2025-04-14  Thomas Schwinge  <tschwi...@baylibre.com>
 
+       PR target/118794
+       * testsuite/libgomp.c++/target-exceptions-pr118794-1.C: New.
+       * 
testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-GCN.C:
+       Likewise.
+       * 
testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-nvptx.C:
+       Likewise.
+
+       Backported from trunk:
+       2025-04-14  Thomas Schwinge  <tschwi...@baylibre.com>
+
        PR c++/119692
        * testsuite/libgomp.c++/pr119692-1-1.C: New.
        * testsuite/libgomp.c++/pr119692-1-2.C: Likewise.
diff --git 
a/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-GCN.C
 
b/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-GCN.C
new file mode 100644
index 000000000000..a588016210c4
--- /dev/null
+++ 
b/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-GCN.C
@@ -0,0 +1,23 @@
+/* Exception handling constructs in dead code.  */
+
+/* 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 -O0 } */
+/* { dg-additional-options -fdump-tree-optimized-raw }
+   { dg-additional-options -foffload-options=-fdump-tree-optimized-raw } */
+
+#include "target-exceptions-pr118794-1.C"
+
+/* In this specific C++ arrangement, distilled from PR118794, GCC synthesizes
+   '__builtin_eh_pointer', '__builtin_unwind_resume' calls as dead code in 'f':
+   { dg-final { scan-tree-dump-times {gimple_call <__builtin_eh_pointer, } 1 
optimized } }
+   { dg-final { scan-tree-dump-times {gimple_call <__builtin_unwind_resume, } 
1 optimized } }
+   { dg-final { only_for_offload_target amdgcn-amdhsa 
scan-offload-tree-dump-times {gimple_call <__builtin_eh_pointer, } 1 optimized 
} }
+   { dg-final { only_for_offload_target amdgcn-amdhsa 
scan-offload-tree-dump-times {gimple_call <__builtin_unwind_resume, } 1 
optimized } }
+   Given '-O0', offload compilation fails:
+   { dg-regexp {[^\r\n]+: In function 'f':[\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-pr118794-1-offload-sorry-nvptx.C
 
b/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-nvptx.C
new file mode 100644
index 000000000000..0358c687d205
--- /dev/null
+++ 
b/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-nvptx.C
@@ -0,0 +1,23 @@
+/* Exception handling constructs in dead code.  */
+
+/* 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 -O0 } */
+/* { dg-additional-options -fdump-tree-optimized-raw }
+   { dg-additional-options -foffload-options=-fdump-tree-optimized-raw } */
+
+#include "target-exceptions-pr118794-1.C"
+
+/* In this specific C++ arrangement, distilled from PR118794, GCC synthesizes
+   '__builtin_eh_pointer', '__builtin_unwind_resume' calls as dead code in 'f':
+   { dg-final { scan-tree-dump-times {gimple_call <__builtin_eh_pointer, } 1 
optimized } }
+   { dg-final { scan-tree-dump-times {gimple_call <__builtin_unwind_resume, } 
1 optimized } }
+   { dg-final { only_for_offload_target nvptx-none 
scan-offload-tree-dump-times {gimple_call <__builtin_eh_pointer, } 1 optimized 
} }
+   { dg-final { only_for_offload_target nvptx-none 
scan-offload-tree-dump-times {gimple_call <__builtin_unwind_resume, } 1 
optimized } }
+   Given '-O0', offload compilation fails:
+   { dg-regexp {[^\r\n]+: In function 'f':[\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-pr118794-1.C 
b/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1.C
new file mode 100644
index 000000000000..8e5ca5cc0b24
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1.C
@@ -0,0 +1,58 @@
+/* Exception handling constructs in dead code.  */
+
+/* { dg-require-effective-target exceptions }
+   { dg-additional-options -fexceptions } */
+/* { dg-additional-options -foffload=disable }
+   Offloading compilation not yet supported; see
+   'target-exceptions-pr118794-1-offload-sorry-GCN.C',
+   'target-exceptions-pr118794-1-offload-sorry-nvptx.C'.  */
+/* { dg-additional-options -O0 } */
+/* { dg-additional-options -fdump-tree-optimized-raw } */
+
+/* See also '../../../gcc/testsuite/g++.target/gcn/exceptions-pr118794-1.C',
+   '../../../gcc/testsuite/g++.target/nvptx/exceptions-pr118794-1.C'.  */
+
+#pragma omp begin declare target
+
+bool ok = false;
+
+template <typename T>
+struct C
+{
+  C()
+  {
+    ok = true;
+  }
+  C(int) {};
+  ~C() {};
+
+  __attribute__((noipa))
+  void m()
+  {
+    C c;
+  }
+};
+
+inline void f()
+{
+  C<double> c(1);
+  c.m();
+}
+
+#pragma omp end declare target
+
+int main()
+{
+#pragma omp target
+  {
+    f();
+  }
+#pragma omp target update from(ok)
+  if (!ok)
+    __builtin_abort();
+}
+
+/* In this specific C++ arrangement, distilled from PR118794, GCC synthesizes
+   '__builtin_eh_pointer', '__builtin_unwind_resume' calls as dead code in 'f':
+   { dg-final { scan-tree-dump-times {gimple_call <__builtin_eh_pointer, } 1 
optimized } }
+   { dg-final { scan-tree-dump-times {gimple_call <__builtin_unwind_resume, } 
1 optimized } } */

Reply via email to