Index: lib/Sema/SemaOpenMP.cpp =================================================================== --- lib/Sema/SemaOpenMP.cpp +++ lib/Sema/SemaOpenMP.cpp @@ -6380,6 +6380,10 @@ } assert(I != CS->body_end() && "Not found statement"); S = *I; + } else { + auto *OED = dyn_cast(S); + if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) + OMPTeamsFound = false; } if (!OMPTeamsFound) { Diag(StartLoc, diag::err_omp_target_contains_not_only_teams);