Index: lib/CodeGen/CGStmtOpenMP.cpp =================================================================== --- lib/CodeGen/CGStmtOpenMP.cpp +++ lib/CodeGen/CGStmtOpenMP.cpp @@ -227,10 +227,15 @@ auto *VD = cast(cast(*IRef)->getDecl()); QualType Type = VD->getType(); if (CopiedVars.insert(VD->getCanonicalDecl()).second) { - // Get the address of the master variable. - auto *MasterAddr = VD->isStaticLocal() - ? CGM.getStaticLocalDeclAddress(VD) - : CGM.GetAddrOfGlobal(VD); + + // Get the address of the master variable. It is passed from the master + // as field in the captured declaration. + auto *FD = CapturedStmtInfo->lookup(VD); + assert( FD && "Copyin master value should be available in some field!"); + QualType TagType = getContext().getTagDeclType(FD->getParent()); + LValue LV = MakeNaturalAlignAddrLValue(CapturedStmtInfo->getContextValue(), TagType); + auto *MasterAddr = EmitLValueForField(LV, FD).getAddress(); + // Get the address of the threadprivate variable. auto *PrivateAddr = EmitLValue(*IRef).getAddress(); if (CopiedVars.size() == 1) { Index: lib/Sema/SemaOpenMP.cpp =================================================================== --- lib/Sema/SemaOpenMP.cpp +++ lib/Sema/SemaOpenMP.cpp @@ -157,6 +157,10 @@ /// current region. bool isLoopControlVariable(VarDecl *D); + /// \brief Check if the specified variable is a 'copyin' variable for current + /// region. + bool isCopyinVariable(VarDecl *D); + /// \brief Adds explicit data sharing attribute to the specified declaration. void addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A); @@ -412,6 +416,12 @@ return Stack.back().LCVSet.count(D) > 0; } +bool DSAStackTy::isCopyinVariable(VarDecl *D){ + assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); + D = D->getCanonicalDecl(); + DSAInfo I = Stack.back().SharingMap.lookup(D); + return I.Attributes == OMPC_copyin; +} void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) { D = D->getCanonicalDecl(); if (A == OMPC_threadprivate) { @@ -653,6 +663,8 @@ assert(LangOpts.OpenMP && "OpenMP is not allowed"); VD = VD->getCanonicalDecl(); if (DSAStack->getCurrentDirective() != OMPD_unknown) { + if (DSAStack->isCopyinVariable(VD) && !DSAStack->isClauseParsingMode()) + return true; if (DSAStack->isLoopControlVariable(VD) || (VD->hasLocalStorage() && isParallelOrTaskRegion(DSAStack->getCurrentDirective())))