Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp =================================================================== --- clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -3816,9 +3816,9 @@ bool IsTargetTask = isOpenMPTargetDataManagementDirective(D.getDirectiveKind()) || isOpenMPTargetExecutionDirective(D.getDirectiveKind()); - // For target-based directives skip 3 firstprivate arrays BasePointersArray, - // PointersArray and SizesArray. The original variables for these arrays are - // not captured and we get their addresses explicitly. + // For target-based directives skip 4 firstprivate arrays BasePointersArray, + // PointersArray, SizesArray, and MappersArray. The original variables for + // these arrays are not captured and we get their addresses explicitly. if ((!IsTargetTask && !Data.FirstprivateVars.empty() && ForDup) || (IsTargetTask && KmpTaskSharedsPtr.isValid())) { SrcBase = CGF.MakeAddrLValue( @@ -3836,7 +3836,7 @@ if (const VarDecl *Elem = Pair.second.PrivateElemInit) { const VarDecl *OriginalVD = Pair.second.Original; // Check if the variable is the target-based BasePointersArray, - // PointersArray or SizesArray. + // PointersArray, SizesArray, or MappersArray. LValue SharedRefLValue; QualType Type = PrivateLValue.getType(); const FieldDecl *SharedField = CapturesInfo.lookup(OriginalVD); @@ -8814,7 +8814,7 @@ CodeGenFunction &CGF, llvm::Value *&BasePointersArrayArg, llvm::Value *&PointersArrayArg, llvm::Value *&SizesArrayArg, llvm::Value *&MapTypesArrayArg, llvm::Value *&MappersArrayArg, - CGOpenMPRuntime::TargetDataInfo &Info) { + CGOpenMPRuntime::TargetDataInfo &Info, bool IsTask = false) { CodeGenModule &CGM = CGF.CGM; if (Info.NumberOfPtrs) { BasePointersArrayArg = CGF.Builder.CreateConstInBoundsGEP2_32( @@ -8834,10 +8834,13 @@ Info.MapTypesArray, /*Idx0=*/0, /*Idx1=*/0); - MappersArrayArg = - Info.HasMapper - ? CGF.Builder.CreatePointerCast(Info.MappersArray, CGM.VoidPtrPtrTy) - : llvm::ConstantPointerNull::get(CGM.VoidPtrPtrTy); + // Always emit the mapper array address in case of a target task for + // privatization. + if (!IsTask && !Info.HasMapper) + MappersArrayArg = llvm::ConstantPointerNull::get(CGM.VoidPtrPtrTy); + else + MappersArrayArg = + CGF.Builder.CreatePointerCast(Info.MappersArray, CGM.VoidPtrPtrTy); } else { BasePointersArrayArg = llvm::ConstantPointerNull::get(CGM.VoidPtrPtrTy); PointersArrayArg = llvm::ConstantPointerNull::get(CGM.VoidPtrPtrTy); @@ -9584,9 +9587,9 @@ TargetDataInfo Info; // Fill up the arrays and create the arguments. emitOffloadingArrays(CGF, CombinedInfo, Info); - emitOffloadingArraysArgument(CGF, Info.BasePointersArray, - Info.PointersArray, Info.SizesArray, - Info.MapTypesArray, Info.MappersArray, Info); + emitOffloadingArraysArgument( + CGF, Info.BasePointersArray, Info.PointersArray, Info.SizesArray, + Info.MapTypesArray, Info.MappersArray, Info, RequiresOuterTask); InputInfo.NumberOfTargetItems = Info.NumberOfPtrs; InputInfo.BasePointersArray = Address(Info.BasePointersArray, CGM.getPointerAlign()); @@ -10438,7 +10441,8 @@ emitOffloadingArrays(CGF, CombinedInfo, Info); emitOffloadingArraysArgument(CGF, Info.BasePointersArray, Info.PointersArray, Info.SizesArray, - Info.MapTypesArray, Info.MappersArray, Info); + Info.MapTypesArray, Info.MappersArray, Info, + D.hasClausesOfKind()); InputInfo.NumberOfTargetItems = Info.NumberOfPtrs; InputInfo.BasePointersArray = Address(Info.BasePointersArray, CGM.getPointerAlign());