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.
This commit is contained in:
Thomas Schwinge 2025-03-27 14:46:20 +01:00
parent 0e68f49db9
commit 00cde164ee
8 changed files with 158 additions and 0 deletions

View file

@ -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.) */

View file

@ -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.) */

View file

@ -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.} } */

View file

@ -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.} } */

View file

@ -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]+} } */

View file

@ -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.} } */

View file

@ -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.} } */

View file

@ -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]+} } */