1 // 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
8 
9 #ifndef HEADER
10 #define HEADER
11 
12 template <typename T>
13 class TemplateClass {
14   T a;
15 public:
TemplateClass()16   TemplateClass() { throw 1;}
f_method() const17   T f_method() const { return a; }
18 };
19 
20 int foo();
21 
22 int baz1();
23 
24 int baz2();
25 
baz4()26 int baz4() { return 5; }
27 
28 template <typename T>
FA()29 T FA() {
30   TemplateClass<T> s;
31   return s.f_method();
32 }
33 
34 #pragma omp declare target
35 struct S {
36   int a;
SS37   S(int a) : a(a) { throw 1; } // expected-error {{cannot use 'throw' with exceptions disabled}}
38 };
39 
foo()40 int foo() { return 0; }
41 int b = 15;
42 int d;
43 #pragma omp end declare target
44 int c;
45 
bar()46 int bar() { return 1 + foo() + bar() + baz1() + baz2(); } // expected-note {{called by 'bar'}}
47 
maini1()48 int maini1() {
49   int a;
50   static long aa = 32;
51   try {
52 #pragma omp target map(tofrom \
53                        : a, b)
54   {
55     S s(a);
56     static long aaa = 23;
57     a = foo() + bar() + b + c + d + aa + aaa + FA<int>(); // expected-note{{called by 'maini1'}}
58     if (!a)
59       throw "Error"; // expected-error {{cannot use 'throw' with exceptions disabled}}
60   }
61   } catch(...) {
62   }
63   return baz4();
64 }
65 
baz3()66 int baz3() { return 2 + baz2(); }
baz2()67 int baz2() {
68 #pragma omp target
69   try { // expected-error {{cannot use 'try' with exceptions disabled}}
70   ++c;
71   } catch (...) {
72   }
73   return 2 + baz3();
74 }
75 
baz1()76 int baz1() { throw 1; } // expected-error {{cannot use 'throw' with exceptions disabled}}
77 
78 int foobar1();
79 int foobar2();
80 
81 int (*A)() = &foobar1;
82 #pragma omp declare target
83 int (*B)() = &foobar2;
84 #pragma omp end declare target
85 
foobar1()86 int foobar1() { throw 1; }
foobar2()87 int foobar2() { throw 1; } // expected-error {{cannot use 'throw' with exceptions disabled}}
88 
89 
90 int foobar3();
91 int (*C)() = &foobar3; // expected-warning {{declaration is not declared in any declare target region}}
92                        // host-warning@-1 {{declaration is not declared in any declare target region}}
93 #pragma omp declare target
94 int (*D)() = C; // expected-note {{used here}}
95                 // host-note@-1 {{used here}}
96 #pragma omp end declare target
foobar3()97 int foobar3() { throw 1; }
98 
99 // Check no infinite recursion in deferred diagnostic emitter.
100 long E = (long)&E;
101 
102 #endif // HEADER
103