xref: /llvm-project/clang/test/OpenMP/target_messages.cpp (revision d66d25f83824e2d72e06bf0813cc9e9e564dd74c)
1 // RUN: %clang_cc1 -verify -fopenmp -std=c++11 -o - %s
2 // RUN: not %clang_cc1 -fopenmp -std=c++11 -fopenmp-targets=aaa-bbb-ccc-ddd -o - %s 2>&1 | FileCheck %s
3 
4 // RUN: %clang_cc1 -verify -fopenmp-simd -std=c++11 -o - %s
5 // CHECK: error: OpenMP target is invalid: 'aaa-bbb-ccc-ddd'
6 // RUN: not %clang_cc1 -fopenmp -std=c++11 -triple nvptx64-nvidia-cuda -o - %s 2>&1 | FileCheck --check-prefix CHECK-UNSUPPORTED-HOST-TARGET %s
7 // RUN: not %clang_cc1 -fopenmp -std=c++11 -triple nvptx-nvidia-cuda -o - %s 2>&1 | FileCheck --check-prefix CHECK-UNSUPPORTED-HOST-TARGET %s
8 // CHECK-UNSUPPORTED-HOST-TARGET: error: The target '{{nvptx64-nvidia-cuda|nvptx-nvidia-cuda}}' is not a supported OpenMP host target.
9 // RUN: not %clang_cc1 -fopenmp -std=c++11 -fopenmp-targets=hexagon-linux-gnu -o - %s 2>&1 | FileCheck --check-prefix CHECK-UNSUPPORTED-DEVICE-TARGET %s
10 // CHECK-UNSUPPORTED-DEVICE-TARGET: OpenMP target is invalid: 'hexagon-linux-gnu'
11 
12 // RUN: not %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path 1111.bc -o - 2>&1 | FileCheck --check-prefix NO-HOST-BC %s
13 // NO-HOST-BC: The provided host compiler IR file '1111.bc' is required to generate code for OpenMP target regions but cannot be found.
14 
15 // RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm-bc %s -o %t-ppc-host.bc -DREGION_HOST
16 // RUN: not %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - -DREGION_DEVICE 2>&1
17 
18 #if defined(REGION_HOST) || defined(REGION_DEVICE)
19 void foo() {
20 #ifdef REGION_HOST
21 #pragma omp target // expected-error {{Offloading entry for target region in _Z3foov is incorrect: either the address or the ID is invalid.}}
22   ;
23 #endif
24 #ifdef REGION_DEVICE
25 #pragma omp target
26   ;
27 #endif
28 }
29 #pragma omp declare target to(foo)
30 void bar() {
31 #ifdef REGION_HOST
32 #pragma omp target
33   ;
34 #endif
35 #ifdef REGION_DEVICE
36 #pragma omp target
37   ;
38 #endif
39 }
40 #else
41 void foo() {
42 }
43 
44 class S {
45   public:
46   void zee() {
47     #pragma omp target map(this[:2]) // expected-note {{expected length on mapping of 'this' array section expression to be '1'}} // expected-error {{invalid 'this' expression on 'map' clause}}
48       int a;
49     #pragma omp target map(this[1:1]) // expected-note {{expected lower bound on mapping of 'this' array section expression to be '0' or not specified}} // expected-error {{invalid 'this' expression on 'map' clause}}
50       int b;
51     #pragma omp target map(this[1]) // expected-note {{expected 'this' subscript expression on map clause to be 'this[0]'}} // expected-error {{invalid 'this' expression on 'map' clause}}
52       int c;
53     #pragma omp target map(foo) // expected-error {{expected expression containing only member accesses and/or array sections based on named variables}}
54       int d;
55     #pragma omp target map(zee) // expected-error {{expected expression containing only member accesses and/or array sections based on named variables}}
56       int e;
57     #pragma omp target map(this->zee) // expected-error {{expected expression containing only member accesses and/or array sections based on named variables}}
58       int f;
59   }
60 };
61 
62 #pragma omp target // expected-error {{unexpected OpenMP directive '#pragma omp target'}}
63 
64 int main(int argc, char **argv) {
65   #pragma omp target { // expected-warning {{extra tokens at the end of '#pragma omp target' are ignored}}
66   foo();
67   #pragma omp target ( // expected-warning {{extra tokens at the end of '#pragma omp target' are ignored}}
68   foo();
69   #pragma omp target [ // expected-warning {{extra tokens at the end of '#pragma omp target' are ignored}}
70   foo();
71   #pragma omp target ] // expected-warning {{extra tokens at the end of '#pragma omp target' are ignored}}
72   foo();
73   #pragma omp target ) // expected-warning {{extra tokens at the end of '#pragma omp target' are ignored}}
74   foo();
75   #pragma omp target } // expected-warning {{extra tokens at the end of '#pragma omp target' are ignored}}
76   foo();
77   #pragma omp target
78   foo();
79   // expected-warning@+1 {{extra tokens at the end of '#pragma omp target' are ignored}}
80   #pragma omp target unknown()
81   foo();
82   L1:
83     foo();
84   #pragma omp target
85   ;
86   #pragma omp target
87   {
88     goto L1; // expected-error {{use of undeclared label 'L1'}}
89     argc++;
90   }
91 
92   for (int i = 0; i < 10; ++i) {
93     switch(argc) {
94      case (0):
95       #pragma omp target
96       {
97         foo();
98         break; // expected-error {{'break' statement not in loop or switch statement}}
99         continue; // expected-error {{'continue' statement not in loop statement}}
100       }
101       default:
102        break;
103     }
104   }
105 
106   goto L2; // expected-error {{use of undeclared label 'L2'}}
107   #pragma omp target
108   L2:
109   foo();
110   #pragma omp target
111   {
112     return 1; // expected-error {{cannot return from OpenMP region}}
113   }
114 
115   [[]] // expected-error {{an attribute list cannot appear here}}
116   #pragma omp target
117   for (int n = 0; n < 100; ++n) {}
118 
119   #pragma omp target map(foo) // expected-error {{expected expression containing only member accesses and/or array sections based on named variables}}
120   {}
121 
122   S s;
123 
124   #pragma omp target map(s.zee) // expected-error {{expected expression containing only member accesses and/or array sections based on named variables}}
125   {}
126 
127   return 0;
128 }
129 
130 template <class> struct a { static bool b; };
131 template <class c, bool = a<c>::b> void e(c) { // expected-note {{candidate template ignored: substitution failure [with c = int]: non-type template argument is not a constant expression}}
132 #pragma omp target
133   {
134     int d ; e(d); // expected-error {{no matching function for call to 'e'}}
135   }
136 }
137 #endif
138