From: Kelvin Li Date: Mon, 27 Jun 2016 19:15:43 +0000 (+0000) Subject: [OpenMP] Diagnose missing cases of statements between target and teams directives X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b4330af6b03cabdb8800fc989f6d01380d7db98;p=clang [OpenMP] Diagnose missing cases of statements between target and teams directives Clang fails to diagnose cases such as #pragma omp target while(0) { #pragma omp teams {} } A patch by David Sheinkman. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@273908 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 772b3765e5..21ccfd0478 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -6537,6 +6537,9 @@ StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef Clauses, } assert(I != CS->body_end() && "Not found statement"); S = *I; + } else { + auto *OED = dyn_cast(S); + OMPTeamsFound = OED && isOpenMPTeamsDirective(OED->getDirectiveKind()); } if (!OMPTeamsFound) { Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); diff --git a/test/OpenMP/nesting_of_regions.cpp b/test/OpenMP/nesting_of_regions.cpp index 8d884a2e61..38012e8596 100644 --- a/test/OpenMP/nesting_of_regions.cpp +++ b/test/OpenMP/nesting_of_regions.cpp @@ -2960,6 +2960,12 @@ void foo() { #pragma omp teams // expected-note {{nested teams construct here}} ++a; } +#pragma omp target // expected-error {{target construct with nested teams region contains statements outside of the teams construct}} + { + while (0) // expected-note {{statement outside teams construct here}} +#pragma omp teams // expected-note {{nested teams construct here}} + ++a; + } #pragma omp target { #pragma omp taskloop