Index: lib/CodeGen/CGOpenMPRuntime.cpp =================================================================== --- lib/CodeGen/CGOpenMPRuntime.cpp +++ lib/CodeGen/CGOpenMPRuntime.cpp @@ -4257,6 +4257,14 @@ DeviceID, FileID, ParentName, Line, OutlinedFn, OutlinedFnID); } +/// \brief discard all CompoundStmts intervening between two constructs +static const Stmt *ignoreCompoundStmts(const Stmt *Body) { + while (auto *CS = dyn_cast_or_null(Body)) + Body = CS->body_front(); + + return Body; +} + /// \brief Emit the num_teams clause of an enclosed teams directive at the /// target region scope. If there is no teams directive associated with the /// target directive, or if there is no num_teams clause associated with the @@ -4287,7 +4295,8 @@ // FIXME: Accommodate other combined directives with teams when they become // available. - if (auto *TeamsDir = dyn_cast(CS.getCapturedStmt())) { + if (auto *TeamsDir = dyn_cast_or_null( + ignoreCompoundStmts(CS.getCapturedStmt()))) { if (auto *NTE = TeamsDir->getSingleClause()) { CGOpenMPInnerExprInfo CGInfo(CGF, CS); CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, &CGInfo); @@ -4335,7 +4344,8 @@ // FIXME: Accommodate other combined directives with teams when they become // available. - if (auto *TeamsDir = dyn_cast(CS.getCapturedStmt())) { + if (auto *TeamsDir = dyn_cast_or_null( + ignoreCompoundStmts(CS.getCapturedStmt()))) { if (auto *TLE = TeamsDir->getSingleClause()) { CGOpenMPInnerExprInfo CGInfo(CGF, CS); CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, &CGInfo); Index: test/OpenMP/teams_codegen.cpp =================================================================== --- test/OpenMP/teams_codegen.cpp +++ test/OpenMP/teams_codegen.cpp @@ -29,6 +29,16 @@ ++comp; } + // CK1: call i32 @__tgt_target_teams(i32 -1, i8* @{{[^,]+}}, i32 1, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 0) + // CK1: call void @{{.+}}(i{{64|32}} %{{.+}}) + #pragma omp target + {{{ + #pragma omp teams + { + ++comp; + } + }}} + // CK1-DAG: call i32 @__tgt_target_teams(i32 -1, i8* @{{[^,]+}}, i32 2, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 [[NT:%[^,]+]], i32 0) // CK1-DAG: [[NT]] = load i32, i32* [[NTA:%[^,]+]],