168 lines · cpp
1// expected-no-diagnostics2 3//RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \4//RUN: -x c++ -std=c++14 -fexceptions -fcxx-exceptions \5//RUN: -Wno-source-uses-openmp -Wno-openmp-clauses \6//RUN: -ast-print %s | FileCheck %s --check-prefix=PRINT7 8//RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \9//RUN: -x c++ -std=c++14 -fexceptions -fcxx-exceptions \10//RUN: -Wno-source-uses-openmp -Wno-openmp-clauses \11//RUN: -ast-dump %s | FileCheck %s --check-prefix=DUMP12 13//RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \14//RUN: -x c++ -std=c++14 -fexceptions -fcxx-exceptions \15//RUN: -Wno-source-uses-openmp -Wno-openmp-clauses \16//RUN: -emit-pch -o %t %s17 18//RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \19//RUN: -x c++ -std=c++14 -fexceptions -fcxx-exceptions \20//RUN: -Wno-source-uses-openmp -Wno-openmp-clauses \21//RUN: -include-pch %t -ast-print %s | FileCheck %s --check-prefix=PRINT22 23//RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \24//RUN: -x c++ -std=c++14 -fexceptions -fcxx-exceptions \25//RUN: -Wno-source-uses-openmp -Wno-openmp-clauses \26//RUN: -include-pch %t -ast-dump-all %s | FileCheck %s --check-prefix=DUMP27 28#ifndef HEADER29#define HEADER30 31struct SomeKernel {32 int targetDev;33 float devPtr;34 SomeKernel();35 ~SomeKernel();36 37 template <unsigned int nRHS>38 void apply() {39#pragma omp parallel default(firstprivate)40 {41 [=]() -> int {42 return targetDev++;43 }();44 }45 // PRINT: #pragma omp parallel default(firstprivate)46 // PRINT-NEXT: {47 // PRINT-NEXT: [=]() -> int {48 // PRINT-NEXT: return this->targetDev++;49 // PRINT-NEXT: }();50 // PRINT-NEXT: }51 // DUMP: -OMPParallelDirective52 // DUMP-NEXT: -OMPDefaultClause53 // DUMP-NOT: -OMPFirstprivateClause54 }55 // PRINT: template<> void apply<32U>()56 // PRINT: #pragma omp parallel default(firstprivate)57 // PRINT-NEXT: {58 // PRINT-NEXT: [=]() -> int {59 // PRINT-NEXT: return this->targetDev++;60 // PRINT-NEXT: }();61 // CHECK-NEXT: }62 // DUMP: -OMPParallelDirective63 // DUMP-NEXT: -OMPDefaultClause64 // DUMP-NEXT: -OMPFirstprivateClause65 // DUMP-NEXT: -DeclRefExpr {{.*}} 'targetDev'66};67 68void use_template() {69 SomeKernel aKern;70 aKern.apply<32>();71}72 73void foo() {74 int a;75#pragma omp parallel default(firstprivate)76 a++;77 // PRINT: #pragma omp parallel default(firstprivate)78 // PRINT-NEXT: a++;79 // DUMP: -OMPParallelDirective80 // DUMP-NEXT: -OMPDefaultClause81 // DUMP-NEXT: -OMPFirstprivateClause {{.*}} <implicit>82 // DUMP-NEXT: -DeclRefExpr {{.*}} 'a'83}84 85struct St {86 int a, b;87 static int y;88 St() : a(0), b(0) {}89 ~St() {}90};91int St::y = 0;92void bar() {93 St a = St();94 static int yy = 0;95#pragma omp parallel default(firstprivate)96 {97 a.a += 1;98 a.b += 1;99 a.y++;100 yy++;101 St::y++;102 }103 // PRINT: #pragma omp parallel default(firstprivate)104 // DUMP: -OMPParallelDirective105 // DUMP-NEXT: -OMPDefaultClause106 // DUMP-NEXT: -OMPFirstprivateClause {{.*}} <implicit>107 // DUMP-NEXT: -DeclRefExpr {{.*}} 'a'108 // DUMP-NEXT: -DeclRefExpr {{.*}} 'yy'109 // DUMP-NEXT: -DeclRefExpr {{.*}} 'y'110}111void zoo(int);112struct A {113 int z;114 int f;115 A();116 ~A();117 void foo() {118#pragma omp parallel firstprivate(z) default(firstprivate)119 {120 z++;121 f++;122 zoo(z + f);123 f++;124 }125 }126 // PRINT: #pragma omp parallel firstprivate(this->z) default(firstprivate)127 // DUMP: -OMPParallelDirective128 // DUMP-NEXT: -OMPFirstprivateClause129 // DUMP-NEXT: -DeclRefExpr {{.*}} 'z'130 // DUMP-NEXT: -OMPDefaultClause131 // DUMP-NEXT: -OMPFirstprivateClause {{.*}} <implicit>132 // DUMP-NEXT: -DeclRefExpr {{.*}} 'f'133 // DUMP: -CXXThisExpr {{.*}} 'A *' implicit this134 // DUMP-NEXT: -DeclRefExpr {{.*}} 'z'135 // DUMP-NEXT: -DeclRefExpr {{.*}} 'f'136 void bar() {137#pragma omp parallel firstprivate(z) default(firstprivate)138 {139#pragma omp parallel private(z) default(firstprivate)140 {141 z++;142 f++;143 zoo(z + f);144 f++;145 }146 }147 }148 // PRINT: #pragma omp parallel firstprivate(this->z) default(firstprivate)149 // PRINT: #pragma omp parallel private(this->z) default(firstprivate)150 // DUMP: -OMPParallelDirective151 // DUMP-NEXT: -OMPFirstprivateClause152 // DUMP-NEXT: -DeclRefExpr {{.*}} 'z'153 // DUMP-NEXT: -OMPDefaultClause154 // DUMP: -OMPParallelDirective155 // DUMP-NEXT: -OMPPrivateClaus156 // DUMP-NEXT: -DeclRefExpr {{.*}} 'z'157 // DUMP-NEXT: -OMPDefaultClause158 // DUMP-NEXT: -OMPFirstprivateClause {{.*}} <implicit>159 // DUMP-NEXT: -DeclRefExpr {{.*}} 'f'160 // DUMP: -CXXThisExpr {{.*}} 'A *' implicit this161 // DUMP-NEXT: -DeclRefExpr {{.*}} 'f'162 // DUMP: -MemberExpr {{.*}}163 // DUMP-NEXT: -CXXThisExpr164 // DUMP: -CXXThisExpr {{.*}} 'A *' implicit this165 // DUMP-NEXT: -DeclRefExpr {{.*}} 'z'166};167#endif // HEADER168