blob: 591844b7949819941c55d2747ebb92b2cf27c5bf [file] [log] [blame]
Dmitry Polukhin0b0da292016-04-06 11:38:59 +00001// RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s
2// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
3// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
4// expected-no-diagnostics
5
6#ifndef HEADER
7#define HEADER
8
9#pragma omp declare target
10// CHECK: #pragma omp declare target
11void foo() {}
12// CHECK-NEXT: void foo()
13#pragma omp end declare target
14// CHECK: #pragma omp end declare target
15
16extern "C" {
17#pragma omp declare target
18// CHECK: #pragma omp declare target
19void foo_c() {}
20// CHECK-NEXT: void foo_c()
21#pragma omp end declare target
22// CHECK: #pragma omp end declare target
23}
24
25extern "C++" {
26#pragma omp declare target
27// CHECK: #pragma omp declare target
28void foo_cpp() {}
29// CHECK-NEXT: void foo_cpp()
30#pragma omp end declare target
31// CHECK: #pragma omp end declare target
32}
33
34#pragma omp declare target
35template <class T>
36struct C {
Serge Pavlova67a4d22016-11-10 08:49:37 +000037// CHECK: template <class T> struct C {
38// CHECK: #pragma omp declare target
39// CHECK-NEXT: static T ts;
40// CHECK-NEXT: #pragma omp end declare target
41
42// CHECK: template<> struct C<int>
Dmitry Polukhin0b0da292016-04-06 11:38:59 +000043 T t;
44// CHECK-NEXT: int t;
45 static T ts;
46// CHECK-NEXT: #pragma omp declare target
47// CHECK-NEXT: static int ts;
48// CHECK: #pragma omp end declare target
49
50 C(T t) : t(t) {
51 }
52// CHECK: #pragma omp declare target
53// CHECK-NEXT: C(int t) : t(t) {
54// CHECK-NEXT: }
55// CHECK: #pragma omp end declare target
56
57 T foo() {
58 return t;
59 }
60// CHECK: #pragma omp declare target
61// CHECK-NEXT: int foo() {
62// CHECK-NEXT: return this->t;
63// CHECK-NEXT: }
64// CHECK: #pragma omp end declare target
65};
66
Dmitry Polukhin0b0da292016-04-06 11:38:59 +000067template<class T>
68T C<T>::ts = 1;
69// CHECK: #pragma omp declare target
70// CHECK: T ts = 1;
71// CHECK: #pragma omp end declare target
72
73// CHECK: #pragma omp declare target
74// CHECK: int test1()
75int test1() {
76 C<int> c(1);
77 return c.foo() + c.ts;
78}
79#pragma omp end declare target
80// CHECK: #pragma omp end declare target
81
Dmitry Polukhind69b5052016-05-09 14:59:13 +000082int a1;
83void f1() {
84}
85#pragma omp declare target (a1, f1)
86// CHECK: #pragma omp declare target
87// CHECK: int a1;
88// CHECK: #pragma omp end declare target
89// CHECK: #pragma omp declare target
90// CHECK: void f1()
91// CHECK: #pragma omp end declare target
92
93int b1, b2, b3;
94void f2() {
95}
96#pragma omp declare target to(b1) to(b2), to(b3, f2)
97// CHECK: #pragma omp declare target
98// CHECK: int b1;
99// CHECK: #pragma omp end declare target
100// CHECK: #pragma omp declare target
101// CHECK: int b2;
102// CHECK: #pragma omp end declare target
103// CHECK: #pragma omp declare target
104// CHECK: int b3;
105// CHECK: #pragma omp end declare target
106// CHECK: #pragma omp declare target
107// CHECK: void f2()
108// CHECK: #pragma omp end declare target
109
110int c1, c2, c3;
111void f3() {
112}
113#pragma omp declare target link(c1) link(c2), link(c3, f3)
114// CHECK: #pragma omp declare target link
115// CHECK: int c1;
116// CHECK: #pragma omp end declare target
117// CHECK: #pragma omp declare target link
118// CHECK: int c2;
119// CHECK: #pragma omp end declare target
120// CHECK: #pragma omp declare target link
121// CHECK: int c3;
122// CHECK: #pragma omp end declare target
123// CHECK: #pragma omp declare target link
124// CHECK: void f3()
125// CHECK: #pragma omp end declare target
126
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000127int main (int argc, char **argv) {
128 foo();
129 foo_c();
130 foo_cpp();
131 test1();
132 return (0);
133}
134
135// CHECK: #pragma omp declare target
136// CHECK-NEXT: int ts = 1;
137// CHECK-NEXT: #pragma omp end declare target
138#endif