xref: /llvm-project/clang/test/OpenMP/amdgpu_exceptions.cpp (revision 0cfc2dba93b172802b580713a492ea14148a0218)
1 /**
2  * The first four lines test that a warning is produced when enabling
3  * -Wopenmp-target-exception no matter what combination of -fexceptions and
4  * -fcxx-exceptions are set, as we want OpenMP to always allow exceptions in the
5  * target region but emit a warning instead.
6 */
7 
8 // RUN: %clang_cc1 -fopenmp -triple amdgcn-amd-amdhsa -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify=with -Wopenmp-target-exception -analyze
9 // RUN: %clang_cc1 -fopenmp -triple amdgcn-amd-amdhsa -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify=with -Wopenmp-target-exception -analyze
10 // RUN: %clang_cc1 -fopenmp -triple amdgcn-amd-amdhsa -fopenmp-is-target-device -fexceptions %s -emit-llvm -S -verify=with -Wopenmp-target-exception -analyze
11 // RUN: %clang_cc1 -fopenmp -triple amdgcn-amd-amdhsa -fopenmp-is-target-device %s -emit-llvm -S -verify=with -Wopenmp-target-exception -analyze
12 
13 /**
14  * The following four lines test that no warning is emitted when providing
15  * -Wno-openmp-target-exception no matter the combination of -fexceptions and
16  * -fcxx-exceptions.
17 */
18 
19 // RUN: %clang_cc1 -fopenmp -triple amdgcn-amd-amdhsa -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -analyze
20 // RUN: %clang_cc1 -fopenmp -triple amdgcn-amd-amdhsa -fopenmp-is-target-device -fcxx-exceptions %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -analyze
21 // RUN: %clang_cc1 -fopenmp -triple amdgcn-amd-amdhsa -fopenmp-is-target-device -fexceptions %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -analyze
22 // RUN: %clang_cc1 -fopenmp -triple amdgcn-amd-amdhsa -fopenmp-is-target-device %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -analyze
23 
24 /**
25  * Finally we should test that we only ignore exceptions in the OpenMP
26  * offloading tool-chain
27 */
28 
29 // RUN: %clang_cc1 -triple amdgcn-amd-amdhsa %s -emit-llvm -S -verify=noexceptions -o -
30 
31 // noexceptions-error@37 {{cannot use 'try' with exceptions disabled}}
32 // noexceptions-error@38 {{cannot use 'throw' with exceptions disabled}}
33 
34 #pragma omp declare target
35 int foo(void) {
36 	int error = -1;
37 	try { // with-warning {{target 'amdgcn-amd-amdhsa' does not support exception handling; 'catch' block is ignored}}
38 		throw 404; // with-warning {{target 'amdgcn-amd-amdhsa' does not support exception handling; 'throw' is assumed to be never reached}}
39 	}
40 	catch (int e){
41 		error = e;
42 	}
43 	return error;
44 }
45 #pragma omp end declare target
46 // without-no-diagnostics
47