Skip to content

Commit 2e9dde2

Browse files
committed
Fix pointer-type used to load from attach-ptr-addr.
1 parent 707dfce commit 2e9dde2

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7768,13 +7768,8 @@ class MappableExprsHandler {
77687768

77697769
// Get the pointer-attachment base-pointer for the given list, if any.
77707770
const Expr *AttachPtrExpr = getAttachPtrExpr(Components);
7771-
Address AttachPtrAddr = getAttachPtrAddr(AttachPtrExpr, CGF);
7772-
Address AttachPteeBaseAddr =
7773-
!AttachPtrAddr.isValid()
7774-
? Address::invalid()
7775-
: CGF.EmitLoadOfPointer(
7776-
AttachPtrAddr,
7777-
CGF.getContext().VoidPtrTy.castAs<PointerType>());
7771+
auto [AttachPtrAddr, AttachPteeBaseAddr] =
7772+
getAttachPtrAddrAndPteeBaseAddr(AttachPtrExpr, CGF);
77787773

77797774
bool HasAttachPtr = AttachPtrExpr != nullptr;
77807775
bool FirstComponentIsForAttachPtr = AssocExpr == AttachPtrExpr;
@@ -8557,9 +8552,8 @@ class MappableExprsHandler {
85578552
/// Returns the address corresponding to \p PointerExpr.
85588553
static Address getAttachPtrAddr(const Expr *PointerExpr,
85598554
CodeGenFunction &CGF) {
8555+
assert(PointerExpr && "Cannot get addr from null attach-ptr expr");
85608556
Address AttachPtrAddr = Address::invalid();
8561-
if (!PointerExpr)
8562-
return AttachPtrAddr;
85638557

85648558
if (auto *DRE = dyn_cast<DeclRefExpr>(PointerExpr)) {
85658559
// If the pointer is a variable, we can use its address directly.
@@ -8580,6 +8574,31 @@ class MappableExprsHandler {
85808574
return AttachPtrAddr;
85818575
}
85828576

8577+
/// Get the address of the attach pointer, and a load from it, to get the
8578+
/// pointee base address.
8579+
/// \return A pair containing AttachPtrAddr and AttachPteeBaseAddr. The pair
8580+
/// contains invalid addresses if \p AttachPtrExpr is null.
8581+
static std::pair<Address, Address>
8582+
getAttachPtrAddrAndPteeBaseAddr(const Expr *AttachPtrExpr,
8583+
CodeGenFunction &CGF) {
8584+
8585+
if (!AttachPtrExpr)
8586+
return {Address::invalid(), Address::invalid()};
8587+
8588+
Address AttachPtrAddr = getAttachPtrAddr(AttachPtrExpr, CGF);
8589+
assert(AttachPtrAddr.isValid() && "Invalid attach pointer addr");
8590+
8591+
QualType AttachPtrType =
8592+
OMPClauseMappableExprCommon::getComponentExprElementType(AttachPtrExpr)
8593+
.getCanonicalType();
8594+
8595+
Address AttachPteeBaseAddr = CGF.EmitLoadOfPointer(
8596+
AttachPtrAddr, AttachPtrType->castAs<PointerType>());
8597+
assert(AttachPteeBaseAddr.isValid() && "Invalid attach pointee base addr");
8598+
8599+
return {AttachPtrAddr, AttachPteeBaseAddr};
8600+
}
8601+
85838602
/// Returns whether an attach entry should be emitted for a map on
85848603
/// \p MapBaseDecl on the directive \p CurDir.
85858604
static bool

0 commit comments

Comments
 (0)