[PATCH] D18474: [OPENMP] Enable correct generation of runtime call when target directive is separated from teams directive by multiple curly brackets

Carlo Bertolli via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 25 09:57:23 PDT 2016

carlo.bertolli added inline comments.

Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:4257
@@ +4256,3 @@
+hasEnclosingTeams(const Stmt *TargetBody) {
+  if(auto *TeamsDir = dyn_cast<OMPTeamsDirective>(TargetBody)) return TeamsDir;
sfantao wrote:
> I think that this can be simplified to:
> ```
> while (auto *S = dyn_cast<CompoundStmt>(TargetBody))
>   TargetBody = S->body_front();
> return dyn_cast<CompoundStmt>(OMPTeamsDirective);
> ```
> I know that this is currently used only for teams, but I think it would be nice to make this a templated function to look for other possible nests. I suspect this will very useful for other cases like 'target teams parallel distribute'.
Thanks! I agree that having this as a template will help with combined directives. I will produce a new version of the patch with that support.

About your new loop: this would crash if S->body_front() is nullptr. This may happen if you have something like this:

A solution may be

while (auto *S = dyn_cast_or_null<CompoundStmt>(TargetBody))
  TargetBody = S->body_front();

return dyn_cast_or_null<CompoundStmt>(OMPTeamsDirective);




More information about the cfe-commits mailing list