@@ -6782,8 +6782,7 @@ static bool compareExprLocs(const Expr *LHS, const Expr *RHS) {
67826782 assert(LocRHS.isValid() && "RHS expression must have valid source location");
67836783
67846784 // Compare source locations for deterministic ordering
6785- bool result = LocLHS < LocRHS;
6786- return result;
6785+ return LocLHS < LocRHS;
67876786}
67886787
67896788// Utility to handle information from clauses associated with a given
@@ -7090,11 +7089,19 @@ class MappableExprsHandler {
70907089 Address LB = Address::invalid();
70917090 bool IsArraySection = false;
70927091 bool HasCompleteRecord = false;
7093- // ATTACH information for delayed processing
7092+ };
7093+
7094+ /// A struct to store the attach pointer and pointee information, to be used
7095+ /// when emitting an attach entry.
7096+ struct AttachInfoTy {
70947097 Address AttachPtrAddr = Address::invalid();
70957098 Address AttachPteeAddr = Address::invalid();
70967099 const ValueDecl *AttachPtrDecl = nullptr;
70977100 const Expr *AttachMapExpr = nullptr;
7101+
7102+ bool isValid() const {
7103+ return AttachPtrAddr.isValid() && AttachPteeAddr.isValid();
7104+ }
70987105 };
70997106
71007107 /// Check if there's any component list where the attach pointer expression
@@ -8436,9 +8443,8 @@ class MappableExprsHandler {
84368443 /// Returns the address corresponding to \p PointerExpr.
84378444 static Address getAttachPtrAddr(const Expr *PointerExpr,
84388445 CodeGenFunction &CGF) {
8446+ assert(PointerExpr && "Cannot get addr from null attach-ptr expr");
84398447 Address AttachPtrAddr = Address::invalid();
8440- if (!PointerExpr)
8441- return AttachPtrAddr;
84428448
84438449 if (auto *DRE = dyn_cast<DeclRefExpr>(PointerExpr)) {
84448450 // If the pointer is a variable, we can use its address directly.
@@ -8459,6 +8465,31 @@ class MappableExprsHandler {
84598465 return AttachPtrAddr;
84608466 }
84618467
8468+ /// Get the address of the attach pointer, and a load from it, to get the
8469+ /// pointee base address.
8470+ /// \return A pair containing AttachPtrAddr and AttachPteeBaseAddr. The pair
8471+ /// contains invalid addresses if \p AttachPtrExpr is null.
8472+ static std::pair<Address, Address>
8473+ getAttachPtrAddrAndPteeBaseAddr(const Expr *AttachPtrExpr,
8474+ CodeGenFunction &CGF) {
8475+
8476+ if (!AttachPtrExpr)
8477+ return {Address::invalid(), Address::invalid()};
8478+
8479+ Address AttachPtrAddr = getAttachPtrAddr(AttachPtrExpr, CGF);
8480+ assert(AttachPtrAddr.isValid() && "Invalid attach pointer addr");
8481+
8482+ QualType AttachPtrType =
8483+ OMPClauseMappableExprCommon::getComponentExprElementType(AttachPtrExpr)
8484+ .getCanonicalType();
8485+
8486+ Address AttachPteeBaseAddr = CGF.EmitLoadOfPointer(
8487+ AttachPtrAddr, AttachPtrType->castAs<PointerType>());
8488+ assert(AttachPteeBaseAddr.isValid() && "Invalid attach pointee base addr");
8489+
8490+ return {AttachPtrAddr, AttachPteeBaseAddr};
8491+ }
8492+
84628493 /// Returns whether an attach entry should be emitted for a map on
84638494 /// \p MapBaseDecl on the directive \p CurDir.
84648495 static bool
0 commit comments