167 lines · cpp
1// RUN: %clang_cc1 -verify=expected,omp4 -fopenmp -fopenmp-version=45 %s -Wno-openmp-mapping -Wuninitialized2// RUN: %clang_cc1 -verify=expected,omp5 -fopenmp %s -Wno-openmp-mapping -Wuninitialized3 4// RUN: %clang_cc1 -verify=expected,omp4 -fopenmp-simd -fopenmp-version=45 %s -Wno-openmp-mapping -Wuninitialized5// RUN: %clang_cc1 -verify=expected,omp5 -fopenmp-simd %s -Wno-openmp-mapping -Wuninitialized6 7extern int omp_default_mem_alloc;8void foo() {9}10 11bool foobool(int argc) {12 return argc;13}14 15void xxx(int argc) {16 int fp; // expected-note {{initialize the variable 'fp' to silence this warning}}17#pragma omp target18#pragma omp teams distribute simd firstprivate(fp) // expected-warning {{variable 'fp' is uninitialized when used here}}19 for (int i = 0; i < 10; ++i)20 ;21}22 23struct S1; // expected-note {{declared here}} expected-note 2 {{forward declaration of 'S1'}}24extern S1 a;25class S2 {26 mutable int a;27 28public:29 S2() : a(0) {}30 S2(const S2 &s2) : a(s2.a) {}31 static float S2s;32 static const float S2sc;33};34const float S2::S2sc = 0;35const S2 b;36const S2 ba[5];37class S3 {38 int a;39 S3 &operator=(const S3 &s3);40 41public:42 S3() : a(0) {} // expected-note 2 {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}43 S3(S3 &s3) : a(s3.a) {} // expected-note 2 {{candidate constructor not viable: 1st argument ('const S3') would lose const qualifier}}44};45const S3 c;46const S3 ca[5];47extern const int f;48class S4 {49 int a;50 S4();51 S4(const S4 &s4);52public:53 S4(int v):a(v) { }54};55class S5 {56 int a;57 S5():a(0) {}58 S5(const S5 &s5):a(s5.a) { }59public:60 S5(int v):a(v) { }61};62class S6 {63 int a;64public:65 S6() : a(0) { }66};67 68S3 h;69#pragma omp threadprivate(h) // expected-note {{defined as threadprivate or thread local}}70 71int main(int argc, char **argv) {72 const int d = 5;73 const int da[5] = { 0 };74 S4 e(4);75 S5 g(5);76 S6 p;77 int i, k;78 int &j = i;79 80#pragma omp target81#pragma omp teams distribute simd firstprivate // expected-error {{expected '(' after 'firstprivate'}}82 for (i = 0; i < argc; ++i) foo();83 84#pragma omp target85#pragma omp teams distribute simd firstprivate ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}86 for (i = 0; i < argc; ++i) foo();87 88#pragma omp target89#pragma omp teams distribute simd firstprivate () // expected-error {{expected expression}}90 for (i = 0; i < argc; ++i) foo();91 92#pragma omp target93#pragma omp teams distribute simd firstprivate (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}94 for (i = 0; i < argc; ++i) foo();95 96#pragma omp target97#pragma omp teams distribute simd firstprivate (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}98 for (i = 0; i < argc; ++i) foo();99 100#pragma omp target101#pragma omp teams distribute simd firstprivate (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}102 for (i = 0; i < argc; ++i) foo();103 104#pragma omp target105#pragma omp teams distribute simd firstprivate (argc) allocate , allocate(, allocate(omp_default , allocate(omp_default_mem_alloc, allocate(omp_default_mem_alloc:, allocate(omp_default_mem_alloc: argc, allocate(omp_default_mem_alloc: argv), allocate(argv) // expected-error {{expected '(' after 'allocate'}} expected-error 2 {{expected expression}} expected-error 2 {{expected ')'}} expected-error {{use of undeclared identifier 'omp_default'}} expected-note 2 {{to match this '('}}106 for (i = 0; i < argc; ++i) foo();107 108#pragma omp target109#pragma omp teams distribute simd firstprivate (S1) // expected-error {{'S1' does not refer to a value}}110 for (i = 0; i < argc; ++i) foo();111 112#pragma omp target113#pragma omp teams distribute simd firstprivate (k, a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} expected-error {{incomplete type 'S1' where a complete type is required}} expected-error {{no matching constructor for initialization of 'S3'}}114 for (i = 0; i < argc; ++i) foo();115 116#pragma omp target117#pragma omp teams distribute simd firstprivate (argv[1]) // expected-error {{expected variable name}}118 for (i = 0; i < argc; ++i) foo();119 120#pragma omp target121#pragma omp teams distribute simd firstprivate(ba)122 for (i = 0; i < argc; ++i) foo();123 124#pragma omp target125#pragma omp teams distribute simd firstprivate(ca) // expected-error {{no matching constructor for initialization of 'S3'}}126 for (i = 0; i < argc; ++i) foo();127 128#pragma omp target129#pragma omp teams distribute simd firstprivate(da)130 for (i = 0; i < argc; ++i) foo();131 132#pragma omp target133#pragma omp teams distribute simd firstprivate(S2::S2s)134 for (i = 0; i < argc; ++i) foo();135 136#pragma omp target137#pragma omp teams distribute simd firstprivate(S2::S2sc)138 for (i = 0; i < argc; ++i) foo();139 140#pragma omp target141#pragma omp teams distribute simd firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}142 for (i = 0; i < argc; ++i) foo();143 144#pragma omp target145#pragma omp teams distribute simd private(i), firstprivate(i) // expected-error {{private variable cannot be firstprivate}} omp4-note 2 {{defined as private}} omp5-note {{defined as private}} 146 for (i = 0; i < argc; ++i) foo(); // omp4-error {{loop iteration variable in the associated loop of 'omp teams distribute simd' directive may not be private, predetermined as linear}}147 148#pragma omp target149#pragma omp teams distribute simd firstprivate(i)150 for (j = 0; j < argc; ++j) foo();151 152#pragma omp target153#pragma omp teams distribute simd firstprivate(i) // expected-note {{defined as firstprivate}}154 for (i = 0; i < argc; ++i) foo(); // expected-error {{loop iteration variable in the associated loop of 'omp teams distribute simd' directive may not be firstprivate, predetermined as linear}}155 156#pragma omp target157#pragma omp teams distribute simd firstprivate(j)158 for (i = 0; i < argc; ++i) foo();159 160// expected-error@+2 {{lastprivate variable cannot be firstprivate}} expected-note@+2 {{defined as lastprivate}}161#pragma omp target162#pragma omp teams distribute simd lastprivate(argc), firstprivate(argc) // OK163 for (i = 0; i < argc; ++i) foo();164 165 return 0;166}167