[PATCH] D89844: [Clang][OpenMP][WIP] Fixed an issue of segment fault when using target nowait
Shilei Tian via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 20 20:00:23 PDT 2020
tianshilei1992 created this revision.
tianshilei1992 added reviewers: jdoerfert, grokos, ye-luo.
Herald added subscribers: cfe-commits, guansong, yaxunl.
Herald added a project: clang.
tianshilei1992 requested review of this revision.
Herald added a subscriber: sstefan1.
The implementation of target nowait just wraps the target region into a
task. The essential four parameters (base ptr, ptr, size, mapper) are taken as
firstprivate such that they will be copied to the private location. When there
is no user-defined mapper, the mapper variable will be nullptr. However, it will
be still copied to the corresponding place. Therefore, a memcpy will be generated
and the source pointer will be nullptr, causing a segmentation fault.
In this patch, it will first checks whether the mapper is a constant nullptr. If
so, the firstprivate field and corresponding copy will not be generated.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D89844
Files:
clang/lib/CodeGen/CGStmtOpenMP.cpp
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===================================================================
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -4210,16 +4210,24 @@
/*IndexTypeQuals=*/0);
SVD = createImplicitFirstprivateForType(getContext(), Data, SizesType, CD,
S.getBeginLoc());
- MVD = createImplicitFirstprivateForType(
- getContext(), Data, BaseAndPointerAndMapperType, CD, S.getBeginLoc());
TargetScope.addPrivate(
BPVD, [&InputInfo]() { return InputInfo.BasePointersArray; });
TargetScope.addPrivate(PVD,
[&InputInfo]() { return InputInfo.PointersArray; });
TargetScope.addPrivate(SVD,
[&InputInfo]() { return InputInfo.SizesArray; });
- TargetScope.addPrivate(MVD,
- [&InputInfo]() { return InputInfo.MappersArray; });
+ // Mapper can be nullptr if user doesn't provide any. We will not take it
+ // into account in this case.
+ if (auto *Ptr = dyn_cast_or_null<llvm::Constant>(
+ InputInfo.MappersArray.getPointer())) {
+ if (!Ptr->isNullValue()) {
+ MVD = createImplicitFirstprivateForType(getContext(), Data,
+ BaseAndPointerAndMapperType, CD,
+ S.getBeginLoc());
+ TargetScope.addPrivate(
+ MVD, [&InputInfo]() { return InputInfo.MappersArray; });
+ }
+ }
}
(void)TargetScope.Privatize();
// Build list of dependences.
@@ -4269,8 +4277,10 @@
CGF.GetAddrOfLocalVar(PVD), /*Index=*/0);
InputInfo.SizesArray = CGF.Builder.CreateConstArrayGEP(
CGF.GetAddrOfLocalVar(SVD), /*Index=*/0);
- InputInfo.MappersArray = CGF.Builder.CreateConstArrayGEP(
- CGF.GetAddrOfLocalVar(MVD), /*Index=*/0);
+ // MVD can be nullptr if there is no user-defined mapper
+ if (MVD)
+ InputInfo.MappersArray = CGF.Builder.CreateConstArrayGEP(
+ CGF.GetAddrOfLocalVar(MVD), /*Index=*/0);
}
Action.Enter(CGF);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89844.299544.patch
Type: text/x-patch
Size: 2162 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201021/38f0527e/attachment-0001.bin>
More information about the cfe-commits
mailing list