diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/OpenMP/generic_loop_ast_print.cpp | 141 | ||||
-rw-r--r-- | clang/test/OpenMP/generic_loop_messages.cpp | 133 |
2 files changed, 274 insertions, 0 deletions
diff --git a/clang/test/OpenMP/generic_loop_ast_print.cpp b/clang/test/OpenMP/generic_loop_ast_print.cpp new file mode 100644 index 000000000000..7f5f53003e40 --- /dev/null +++ b/clang/test/OpenMP/generic_loop_ast_print.cpp @@ -0,0 +1,141 @@ +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \ +// RUN: -fsyntax-only -verify %s + +// expected-no-diagnostics + +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \ +// RUN: -ast-print %s | FileCheck %s --check-prefix=PRINT + +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \ +// RUN: -ast-dump %s | FileCheck %s --check-prefix=DUMP + +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \ +// RUN: -emit-pch -o %t %s + +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \ +// RUN: -include-pch %t -ast-dump-all %s | FileCheck %s --check-prefix=DUMP + +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \ +// RUN: -include-pch %t -ast-print %s | FileCheck %s --check-prefix=PRINT + +#ifndef HEADER +#define HEADER + +//PRINT: template <typename T, int C> void templ_foo(T t) { +//PRINT: T j, z; +//PRINT: #pragma omp loop collapse(C) reduction(+: z) lastprivate(j) +//PRINT: for (T i = 0; i < t; ++i) +//PRINT: for (j = 0; j < t; ++j) +//PRINT: z += i + j; +//PRINT: } +//DUMP: FunctionTemplateDecl{{.*}}templ_foo +//DUMP: TemplateTypeParmDecl{{.*}}T +//DUMP: NonTypeTemplateParmDecl{{.*}}C +//DUMP: OMPGenericLoopDirective +//DUMP: OMPCollapseClause +//DUMP: DeclRefExpr{{.*}}'C' 'int' +//DUMP: OMPReductionClause +//DUMP: DeclRefExpr{{.*}}'z' 'T' +//DUMP: OMPLastprivateClause +//DUMP: DeclRefExpr{{.*}}'j' 'T' +//DUMP: ForStmt +//DUMP: ForStmt + +//PRINT: template<> void templ_foo<int, 2>(int t) { +//PRINT: int j, z; +//PRINT: #pragma omp loop collapse(2) reduction(+: z) lastprivate(j) +//PRINT: for (int i = 0; i < t; ++i) +//PRINT: for (j = 0; j < t; ++j) +//PRINT: z += i + j; +//PRINT: } +//DUMP: FunctionDecl{{.*}}templ_foo 'void (int)' +//DUMP: TemplateArgument type 'int' +//DUMP: TemplateArgument integral 2 +//DUMP: ParmVarDecl{{.*}}'int':'int' +//DUMP: OMPGenericLoopDirective +//DUMP: OMPCollapseClause +//DUMP: ConstantExpr{{.*}}'int' +//DUMP: value: Int 2 +//DUMP: OMPReductionClause +//DUMP: DeclRefExpr{{.*}}'z' 'int':'int' +//DUMP: OMPLastprivateClause +//DUMP: DeclRefExpr{{.*}}'j' 'int':'int' +//DUMP: ForStmt +template <typename T, int C> +void templ_foo(T t) { + + T j,z; + #pragma omp loop collapse(C) reduction(+:z) lastprivate(j) + for (T i = 0; i<t; ++i) + for (j = 0; j<t; ++j) + z += i+j; +} + + +//PRINT: void test() { +//DUMP: FunctionDecl {{.*}}test 'void ()' +void test() { + constexpr int N = 100; + float MTX[N][N]; + int aaa[1000]; + + //PRINT: #pragma omp target teams distribute parallel for map(tofrom: MTX) + //PRINT: #pragma omp loop + //DUMP: OMPTargetTeamsDistributeParallelForDirective + //DUMP: CapturedStmt + //DUMP: ForStmt + //DUMP: CompoundStmt + //DUMP: OMPGenericLoopDirective + #pragma omp target teams distribute parallel for map(MTX) + for (auto i = 0; i < N; ++i) { + #pragma omp loop + for (auto j = 0; j < N; ++j) { + MTX[i][j] = 0; + } + } + + //PRINT: #pragma omp target teams + //PRINT: #pragma omp loop + //DUMP: OMPTargetTeamsDirective + //DUMP: CapturedStmt + //DUMP: ForStmt + //DUMP: OMPGenericLoopDirective + #pragma omp target teams + for (int i=0; i<1000; ++i) { + #pragma omp loop + for (int j=0; j<100; j++) { + aaa[i] += i + j; + } + } + + int j, z, z1; + //PRINT: #pragma omp loop collapse(2) private(z) lastprivate(j) order(concurrent) reduction(+: z1) + //DUMP: OMPGenericLoopDirective + //DUMP: OMPCollapseClause + //DUMP: IntegerLiteral{{.*}}2 + //DUMP: OMPPrivateClause + //DUMP-NEXT: DeclRefExpr{{.*}}'z' + //DUMP: OMPLastprivateClause + //DUMP-NEXT: DeclRefExpr{{.*}}'j' + //DUMP: OMPOrderClause + //DUMP: OMPReductionClause + //DUMP-NEXT: DeclRefExpr{{.*}}'z1' + //DUMP: ForStmt + //DUMP: ForStmt + #pragma omp loop collapse(2) private(z) lastprivate(j) order(concurrent) \ + reduction(+:z1) + for (auto i = 0; i < N; ++i) { + for (j = 0; j < N; ++j) { + z = i+j; + MTX[i][j] = z; + z1 += z; + } + } +} + +void bar() +{ + templ_foo<int,2>(8); +} + +#endif // HEADER diff --git a/clang/test/OpenMP/generic_loop_messages.cpp b/clang/test/OpenMP/generic_loop_messages.cpp new file mode 100644 index 000000000000..01838a921330 --- /dev/null +++ b/clang/test/OpenMP/generic_loop_messages.cpp @@ -0,0 +1,133 @@ +// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -Wuninitialized %s + +void foo() +{ + int i,j,k; + int z; + + // expected-error@+2 {{statement after '#pragma omp loop' must be a for loop}} + #pragma omp loop + i = 0; + + // OpenMP 5.1 [2.22 Nesting of regions] + // + // A barrier region may not be closely nested inside a worksharing, loop, + // task, taskloop, critical, ordered, atomic, or masked region. + + // expected-error@+3 {{region cannot be closely nested inside 'loop' region}} + #pragma omp loop + for (i=0; i<1000; ++i) { + #pragma omp barrier + } + + // A masked region may not be closely nested inside a worksharing, loop, + // atomic, task, or taskloop region. + + // expected-error@+3 {{region cannot be closely nested inside 'loop' region}} + #pragma omp loop + for (i=0; i<1000; ++i) { + #pragma omp masked filter(2) + { } + } + + // An ordered region that corresponds to an ordered construct without any + // clause or with the threads or depend clause may not be closely nested + // inside a critical, ordered, loop, atomic, task, or taskloop region. + + // expected-error@+3 {{region cannot be closely nested inside 'loop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}} + #pragma omp loop + for (i=0; i<1000; ++i) { + #pragma omp ordered + { } + } + + // expected-error@+3 {{region cannot be closely nested inside 'loop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}} + #pragma omp loop + for (i=0; i<1000; ++i) { + #pragma omp ordered threads + { } + } + + // expected-error@+3 {{region cannot be closely nested inside 'loop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}} + #pragma omp loop + for (i=0; i<1000; ++i) { + #pragma omp ordered depend(source) + } + + // bind clause (not yet implemented) + + // collapse clause + + // expected-error@+4 {{expected 2 for loops after '#pragma omp loop', but found only 1}} + // expected-note@+1 {{as specified in 'collapse' clause}} + #pragma omp loop collapse(2) + for (i=0; i<1000; ++i) + z = i+11; + + // expected-error@+1 {{directive '#pragma omp loop' cannot contain more than one 'collapse' clause}} + #pragma omp loop collapse(2) collapse(2) + for (i=0; i<1000; ++i) + for (j=0; j<1000; ++j) + z = i+j+11; + + // order clause + + // expected-error@+1 {{expected 'concurrent' in OpenMP clause 'order'}} + #pragma omp loop order(foo) + for (i=0; i<1000; ++i) + z = i+11; + + // private clause + + // expected-error@+1 {{use of undeclared identifier 'undef_var'}} + #pragma omp loop private(undef_var) + for (i=0; i<1000; ++i) + z = i+11; + + // lastprivate + + // A list item may not appear in a lastprivate clause unless it is the loop + // iteration variable of a loop that is associated with the construct. + + // expected-error@+1 {{only loop iteration variables are allowed in 'lastprivate' clause in 'omp loop' directives}} + #pragma omp loop lastprivate(z) + for (i=0; i<1000; ++i) { + z = i+11; + } + + // expected-error@+1 {{only loop iteration variables are allowed in 'lastprivate' clause in 'omp loop' directives}} + #pragma omp loop lastprivate(k) collapse(2) + for (i=0; i<1000; ++i) + for (j=0; j<1000; ++j) + for (k=0; k<1000; ++k) + z = i+j+k+11; + + // reduction + + // expected-error@+1 {{use of undeclared identifier 'undef_var'}} + #pragma omp loop reduction(+:undef_var) + for (i=0; i<1000; ++i) + z = i+11; +} + +template <typename T, int C> +void templ_test(T t) { + T i,z; + + // expected-error@+4 {{expected 2 for loops after '#pragma omp loop', but found only 1}} + // expected-note@+1 {{as specified in 'collapse' clause}} + #pragma omp loop collapse(C) + for (i=0; i<1000; ++i) + z = i+11; + + // expected-error@+1 {{only loop iteration variables are allowed in 'lastprivate' clause in 'omp loop' directives}} + #pragma omp loop lastprivate(z) + for (i=0; i<1000; ++i) { + z = i+11; + } +} + +void bar() +{ + templ_test<int, 2>(16); // expected-note {{in instantiation of function template specialization 'templ_test<int, 2>' requested here}} +} |