From 4be30e92dc1a3f2df67d2a03c9b3b1cda55cc5cf Mon Sep 17 00:00:00 2001 From: Samuel Antao Date: Fri, 2 Oct 2015 17:14:03 +0000 Subject: [OpenMP] Capture global variables in target regions. All global variables that are not enclosed in a declare target region must be captured in the target region as local variables do. Currently, there is no support for declare target, so this patch adds support for capturing all the global variables used in a the target region. llvm-svn: 249154 --- clang/lib/Sema/SemaExpr.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'clang/lib/Sema/SemaExpr.cpp') diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index be0da09f265..0aa9a6c53cd 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -13183,10 +13183,18 @@ bool Sema::tryCaptureVariable( if (getLangOpts().OpenMP) { if (auto *RSI = dyn_cast(CSI)) { // OpenMP private variables should not be captured in outer scope, so - // just break here. + // just break here. Similarly, global variables that are captured in a + // target region should not be captured outside the scope of the region. if (RSI->CapRegionKind == CR_OpenMP) { - if (isOpenMPPrivateVar(Var, OpenMPLevel)) { - Nested = true; + auto isTargetCap = isOpenMPTargetCapturedVar(Var, OpenMPLevel); + // When we detect target captures we are looking from inside the + // target region, therefore we need to propagate the capture from the + // enclosing region. Therefore, the capture is not initially nested. + if (isTargetCap) + FunctionScopesIndex--; + + if (isTargetCap || isOpenMPPrivateVar(Var, OpenMPLevel)) { + Nested = !isTargetCap; DeclRefType = DeclRefType.getUnqualifiedType(); CaptureType = Context.getLValueReferenceType(DeclRefType); break; -- cgit v1.2.3