blob: 87ea00a90822eeddb49fe41110e202c9dfb894ef [file] [log] [blame]
Yaxun (Sam) Liu57670852020-03-27 12:38:20 -04001// RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown \
2// RUN: -verify=host -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc \
3// RUN: %s -o %t-ppc-host.bc -fexceptions -fcxx-exceptions
4// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown \
5// RUN: -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s \
6// RUN: -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - \
7// RUN: -fexceptions -fcxx-exceptions -ferror-limit 100
Alexey Bataev1ab34572018-05-02 16:52:07 +00008
9#ifndef HEADER
10#define HEADER
11
12template <typename T>
13class TemplateClass {
14 T a;
15public:
16 TemplateClass() { throw 1;}
17 T f_method() const { return a; }
18};
19
20int foo();
21
22int baz1();
23
24int baz2();
25
26int baz4() { return 5; }
27
28template <typename T>
29T FA() {
30 TemplateClass<T> s;
31 return s.f_method();
32}
33
34#pragma omp declare target
35struct S {
36 int a;
37 S(int a) : a(a) { throw 1; } // expected-error {{cannot use 'throw' with exceptions disabled}}
38};
39
40int foo() { return 0; }
41int b = 15;
42int d;
43#pragma omp end declare target
44int c;
45
Yaxun (Sam) Liub670ab72020-02-26 10:57:39 -050046int bar() { return 1 + foo() + bar() + baz1() + baz2(); } // expected-note {{called by 'bar'}}
Alexey Bataev1ab34572018-05-02 16:52:07 +000047
48int maini1() {
49 int a;
50 static long aa = 32;
51 try {
52#pragma omp target map(tofrom \
53 : a, b)
54 {
Johannes Doerfert1dd66e62021-02-02 11:17:44 -060055 // expected-note@+1 {{called by 'maini1'}}
Alexey Bataev1ab34572018-05-02 16:52:07 +000056 S s(a);
57 static long aaa = 23;
Yaxun (Sam) Liub670ab72020-02-26 10:57:39 -050058 a = foo() + bar() + b + c + d + aa + aaa + FA<int>(); // expected-note{{called by 'maini1'}}
Alexey Bataev1ab34572018-05-02 16:52:07 +000059 if (!a)
60 throw "Error"; // expected-error {{cannot use 'throw' with exceptions disabled}}
61 }
62 } catch(...) {
63 }
64 return baz4();
65}
66
67int baz3() { return 2 + baz2(); }
68int baz2() {
69#pragma omp target
70 try { // expected-error {{cannot use 'try' with exceptions disabled}}
71 ++c;
72 } catch (...) {
73 }
74 return 2 + baz3();
75}
76
Alexey Bataevc416e642019-02-08 18:02:25 +000077int baz1() { throw 1; } // expected-error {{cannot use 'throw' with exceptions disabled}}
78
79int foobar1();
80int foobar2();
81
82int (*A)() = &foobar1;
83#pragma omp declare target
84int (*B)() = &foobar2;
85#pragma omp end declare target
86
87int foobar1() { throw 1; }
88int foobar2() { throw 1; } // expected-error {{cannot use 'throw' with exceptions disabled}}
89
Yaxun (Sam) Liu57670852020-03-27 12:38:20 -040090
91int foobar3();
92int (*C)() = &foobar3; // expected-warning {{declaration is not declared in any declare target region}}
93 // host-warning@-1 {{declaration is not declared in any declare target region}}
94#pragma omp declare target
95int (*D)() = C; // expected-note {{used here}}
96 // host-note@-1 {{used here}}
97#pragma omp end declare target
98int foobar3() { throw 1; }
99
100// Check no infinite recursion in deferred diagnostic emitter.
101long E = (long)&E;
102
Alexey Bataev1ab34572018-05-02 16:52:07 +0000103#endif // HEADER