Skip to content

Commit 0f2f378

Browse files
committed
Add map info for dereference pointer.
This is to fix run time problem when use: int **a; map((*a)[:3]), (*a)[1] or map(**a). current we skip generate map info for dereference pointer: &(*a), &(*a)[0], 3*sizeof(int), TARGET_PARAM | TO | FROM One way to fix runtime problem is to generate map info for dereference pointer. map((*a)[:3]): &(*a), &(*a), sizeof(pointer), TARGET_PARAM | TO | FROM &(*a), &(*a)[0], 3*sizeof(int), PTR_AND_OBJ | TO | FROM map(**a): &(*a), &(*a), sizeof(pointer), TARGET_PARAM | TO | FROM &(*a), &(**a), sizeof(int), PTR_AND_OBJ | TO | FROM The change in CGOpenMPRuntime.cpp add that. The change in SemaOpenMP is to fix variable of dereference pointer to array captured by reference. That is wrong. That cause run time to fail. The rule is: If variable is identified in a map clause it is always captured by reference except if it is a pointer that is dereferenced somehow. Differential Revision: https://reviews.llvm.org/D145093
1 parent 42a5dda commit 0f2f378

File tree

5 files changed

+449
-17
lines changed

5 files changed

+449
-17
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7163,6 +7163,7 @@ class MappableExprsHandler {
71637163
// double d;
71647164
// int i[100];
71657165
// float *p;
7166+
// int **a = &i;
71667167
//
71677168
// struct S1 {
71687169
// int i;
@@ -7196,6 +7197,14 @@ class MappableExprsHandler {
71967197
// in unified shared memory mode or for local pointers
71977198
// p, &p[1], 24*sizeof(float), TARGET_PARAM | TO | FROM
71987199
//
7200+
// map((*a)[0:3])
7201+
// &(*a), &(*a), sizeof(pointer), TARGET_PARAM | TO | FROM
7202+
// &(*a), &(*a)[0], 3*sizeof(int), PTR_AND_OBJ | TO | FROM
7203+
//
7204+
// map(**a)
7205+
// &(*a), &(*a), sizeof(pointer), TARGET_PARAM | TO | FROM
7206+
// &(*a), &(**a), sizeof(int), PTR_AND_OBJ | TO | FROM
7207+
//
71997208
// map(s)
72007209
// &s, &s, sizeof(S2), TARGET_PARAM | TO | FROM
72017210
//
@@ -7488,7 +7497,9 @@ class MappableExprsHandler {
74887497
bool IsMemberReference = isa<MemberExpr>(I->getAssociatedExpression()) &&
74897498
MapDecl &&
74907499
MapDecl->getType()->isLValueReferenceType();
7491-
bool IsNonDerefPointer = IsPointer && !UO && !BO && !IsNonContiguous;
7500+
bool IsNonDerefPointer = IsPointer &&
7501+
!(UO && UO->getOpcode() != UO_Deref) && !BO &&
7502+
!IsNonContiguous;
74927503

74937504
if (OASE)
74947505
++DimSize;

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,11 +2203,14 @@ bool Sema::isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level,
22032203
++EI;
22042204
if (EI == EE)
22052205
return false;
2206-
2207-
if (isa<ArraySubscriptExpr>(EI->getAssociatedExpression()) ||
2208-
isa<OMPArraySectionExpr>(EI->getAssociatedExpression()) ||
2206+
auto Last = std::prev(EE);
2207+
const auto *UO =
2208+
dyn_cast<UnaryOperator>(Last->getAssociatedExpression());
2209+
if ((UO && UO->getOpcode() == UO_Deref) ||
2210+
isa<ArraySubscriptExpr>(Last->getAssociatedExpression()) ||
2211+
isa<OMPArraySectionExpr>(Last->getAssociatedExpression()) ||
22092212
isa<MemberExpr>(EI->getAssociatedExpression()) ||
2210-
isa<OMPArrayShapingExpr>(EI->getAssociatedExpression())) {
2213+
isa<OMPArrayShapingExpr>(Last->getAssociatedExpression())) {
22112214
IsVariableAssociatedWithSection = true;
22122215
// There is nothing more we need to know about this variable.
22132216
return true;

0 commit comments

Comments
 (0)