1 // 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 
5 // RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s | FileCheck %s
6 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
8 // expected-no-diagnostics
9 
10 // It is unclear if we want to annotate the template instantiations, e.g., S<int>::foo, or not in the two
11 // situations shown below. Since it is always fair to drop assumptions, we do that for now.
12 
13 #ifndef HEADER
14 #define HEADER
15 
16 template <typename T>
17 struct S {
18   int a;
19 // CHECK: template <typename T> struct S {
20 // CHECK:     void foo() __attribute__((assume("global_assumption")))     {
fooS21   void foo() {
22     #pragma omp parallel
23     {}
24   }
25 };
26 
27 // CHECK: template<> struct S<int> {
28 // CHECK:     void foo() __attribute__((assume("global_assumption")))     {
29 
30 #pragma omp begin assumes no_openmp
31 // CHECK: void S_with_assumes_no_call() __attribute__((assume("no_openmp"))) __attribute__((assume("global_assumption"))) {
S_with_assumes_no_call()32 void S_with_assumes_no_call() {
33   S<int> s;
34   s.a = 0;
35 }
36 // CHECK: void S_with_assumes_call() __attribute__((assume("no_openmp"))) __attribute__((assume("global_assumption"))) {
S_with_assumes_call()37 void S_with_assumes_call() {
38   S<int> s;
39   s.a = 0;
40   // If this is executed we have UB!
41   s.foo();
42 }
43 #pragma omp end assumes
44 
45 // CHECK: void S_without_assumes() __attribute__((assume("global_assumption"))) {
S_without_assumes()46 void S_without_assumes() {
47   S<int> s;
48   s.foo();
49 }
50 
51 #pragma omp assumes ext_global_assumption
52 
53 // Same as the struct S above but the order in which we instantiate P is different, first outside of an assumes.
54 template <typename T>
55 struct P {
56 // CHECK: template <typename T> struct P {
57 // CHECK:     void foo() __attribute__((assume("global_assumption")))     {
58   int a;
fooP59   void foo() {
60     #pragma omp parallel
61     {}
62   }
63 };
64 
65 // TODO: Avoid the duplication here:
66 
67 // CHECK: template<> struct P<int> {
68 // CHECK:     void foo() __attribute__((assume("global_assumption"))) __attribute__((assume("global_assumption")))     {
69 
70 // CHECK: void P_without_assumes() __attribute__((assume("global_assumption"))) {
P_without_assumes()71 void P_without_assumes() {
72   P<int> p;
73   p.foo();
74 }
75 
76 #pragma omp begin assumes no_openmp
77 // CHECK: void P_with_assumes_no_call() __attribute__((assume("no_openmp"))) __attribute__((assume("global_assumption"))) {
P_with_assumes_no_call()78 void P_with_assumes_no_call() {
79   P<int> p;
80   p.a = 0;
81 }
82 // CHECK: void P_with_assumes_call() __attribute__((assume("no_openmp"))) __attribute__((assume("global_assumption"))) {
P_with_assumes_call()83 void P_with_assumes_call() {
84   P<int> p;
85   p.a = 0;
86   // If this is executed we have UB!
87   p.foo();
88 }
89 #pragma omp end assumes
90 
91 #endif
92