diff options
author | Jennifer Yu <jennifer.yu@intel.com> | 2023-03-01 08:22:21 -0800 |
---|---|---|
committer | Jennifer Yu <jennifer.yu@intel.com> | 2023-03-08 17:43:43 -0800 |
commit | 0f2f378425821de77e50a0dcb67c4504389a56e8 (patch) | |
tree | c0ec002d375de5f5fab5f2ff7c064b32f3505ea0 /clang/lib/Sema/SemaOpenMP.cpp | |
parent | 42a5dda553e84da98cb03630130e4820e93af8f2 (diff) | |
download | llvm-0f2f378425821de77e50a0dcb67c4504389a56e8.zip llvm-0f2f378425821de77e50a0dcb67c4504389a56e8.tar.gz llvm-0f2f378425821de77e50a0dcb67c4504389a56e8.tar.bz2 |
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
Diffstat (limited to 'clang/lib/Sema/SemaOpenMP.cpp')
-rw-r--r-- | clang/lib/Sema/SemaOpenMP.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index b87732a..e193fa3 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -2203,11 +2203,14 @@ bool Sema::isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level, ++EI; if (EI == EE) return false; - - if (isa<ArraySubscriptExpr>(EI->getAssociatedExpression()) || - isa<OMPArraySectionExpr>(EI->getAssociatedExpression()) || + auto Last = std::prev(EE); + const auto *UO = + dyn_cast<UnaryOperator>(Last->getAssociatedExpression()); + if ((UO && UO->getOpcode() == UO_Deref) || + isa<ArraySubscriptExpr>(Last->getAssociatedExpression()) || + isa<OMPArraySectionExpr>(Last->getAssociatedExpression()) || isa<MemberExpr>(EI->getAssociatedExpression()) || - isa<OMPArrayShapingExpr>(EI->getAssociatedExpression())) { + isa<OMPArrayShapingExpr>(Last->getAssociatedExpression())) { IsVariableAssociatedWithSection = true; // There is nothing more we need to know about this variable. return true; |